Module: Overscribe
- Defined in:
- lib/overscribe.rb,
lib/overscribe/cli.rb,
lib/overscribe/version.rb,
lib/overscribe/youtube_dl.rb
Defined Under Namespace
Modules: YoutubeDL
Classes: CLI, Error
Constant Summary
collapse
- DEFAULT_PROFILES =
{
'audio' => {
'youtubedl_args' => %w[--format bestaudio --extract-audio],
},
'video' => {
'youtubedl_args' => %w[--format bestvideo+bestaudio],
},
}.freeze
- VERSION =
'0.4.0'.freeze
Class Method Summary
collapse
Class Method Details
.collections(pattern:) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/overscribe.rb', line 66
def self.collections(pattern:)
collections = config['collections']
collections.select! do |collection, options|
if pattern.nil?
!options['manual']
else
collection.start_with? pattern
end
end
end
|
.config ⇒ Object
61
62
63
64
|
# File 'lib/overscribe.rb', line 61
def self.config
filename = File.expand_path '~/.config/overscribe.yaml'
YAML.safe_load(File.read(filename))
end
|
.fetch_collections(cli_options) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/overscribe.rb', line 15
def self.fetch_collections(cli_options)
collections = collections(pattern: cli_options['pattern'])
collections.each do |collection, options|
puts ">>> #{collection}"
options = profile(name: options['profile']).deep_merge(options).deep_merge(cli_options)
directory = File.expand_path collection, options['directory']
FileUtils.mkdir_p directory
FileUtils.chdir(directory) do
YoutubeDL.download url: options['url'], args: options['youtubedl_args'], options: options
end
end
end
|
.fetch_oneshot(url, cli_options) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/overscribe.rb', line 34
def self.fetch_oneshot(url, cli_options)
profile = profile(name: cli_options['profile'])
options = profile.deep_merge cli_options
directory = File.expand_path cli_options['collection'].to_s, options['directory']
FileUtils.mkdir_p directory
FileUtils.chdir(directory) do
YoutubeDL.download url: url, args: profile['youtubedl_args'], options: options
generate_collection_config_file(url: url, options: options) unless options['collection'].nil?
end
end
|
.generate_collection_config_file(url:, options:) ⇒ Object
rubocop:disable Metrics/MethodLength
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/overscribe.rb', line 46
def self.generate_collection_config_file(url:, options:) config = {
'profiles' => {
options['profile'] => profile(name: options['profile']),
},
'collections' => {
options['collection'] => {
'url' => url,
'profile' => options['profile'],
},
},
}
File.write 'overscribe.yaml', config.to_yaml
end
|
.list_collections(cli_options) ⇒ Object
30
31
32
|
# File 'lib/overscribe.rb', line 30
def self.list_collections(cli_options)
collections(pattern: cli_options['pattern'])
end
|
.profile(name:) ⇒ Object
92
93
94
|
# File 'lib/overscribe.rb', line 92
def self.profile(name:)
profiles[name]
end
|
.profiles ⇒ Object
88
89
90
|
# File 'lib/overscribe.rb', line 88
def self.profiles
DEFAULT_PROFILES.deep_merge config['profiles']
end
|