overscribe 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8e54eb7a38556634f996f36dd60437f16feb17b5018d6dfd2f8ea6c1d9dde36d
4
+ data.tar.gz: 722d73797fd50d6c2228ae7ff2ab001bc116863c0f7ab5af146c1163cc66c3e1
5
+ SHA512:
6
+ metadata.gz: 98670c1878fad2a80c43da47301d009f921f15c2e9fa086e4e5ff8ae4f4635fc305177fd4b6649c95e56223590af155a66081f469813a33a9b3845e2f833109e
7
+ data.tar.gz: d2c27343dbc1c722b73d819841cd7c39b53d22febea8253be469e610879816e41d9a6d46ebb0506d899656c9b60fe2d47830d5a767f7e4b32ab3c24fdf227a98
@@ -0,0 +1,15 @@
1
+ name: Continuous integration
2
+
3
+ on:
4
+ - push
5
+
6
+ jobs:
7
+ ci:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: '2.7'
14
+ bundler-cache: true
15
+ - run: bundle exec rubocop
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ .rspec_status
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ /vendor/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ ---
2
+ AllCops:
3
+ TargetRubyVersion: 2.5
4
+ NewCops: enable
5
+ SuggestExtensions: false
6
+
7
+ Style/Documentation:
8
+ Enabled: false
9
+
10
+ Style/FrozenStringLiteralComment:
11
+ Enabled: false
12
+
13
+ Style/TrailingCommaInHashLiteral:
14
+ EnforcedStyleForMultiline: comma
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in overscribe.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Romuald Conty
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # Overscribe
2
+
3
+ ## Usage
4
+
5
+ ### Fetch all collections
6
+
7
+ ```shell
8
+ overscribe collections fetch
9
+ ```
10
+
11
+ ### Fetch specific collection(s)
12
+
13
+ ```shell
14
+ overscribe collections fetch "The collections name starts with this"
15
+ ```
16
+
17
+ ### List configured collections
18
+
19
+ ```shell
20
+ overscribe collections list
21
+ ```
22
+
23
+ ### Fetch medias behind one URL
24
+
25
+ #### Basic
26
+
27
+ ```shell
28
+ overscribe oneshot \
29
+ --profile "video hd" \
30
+ https://example.com/video
31
+ ```
32
+
33
+ `overscribe` will fetch medias pointed by _URL_ using options specified in the `profile`, including the target directory, defined in config file.
34
+
35
+ #### With collection
36
+
37
+ If you want to fetch one URL as a collection:
38
+
39
+ ```shell
40
+ overscribe oneshot \
41
+ --profile audio:album \
42
+ --collection "Worakls/Sur le front des animaux menacés" \
43
+ https://www.youtube.com/playlist?list=OLAK5uy_mrpr_HvIdIey7xvzt82EPKRHsuorKOMM4
44
+ ```
45
+
46
+ This `--collection` option will:
47
+ * append the collection name to the target directory
48
+ * generate a `overscribe.yaml` config file into target directory
49
+
50
+ ### More
51
+
52
+ ```shell
53
+ overscribe help
54
+ ```
55
+
56
+ ## Setup
57
+
58
+ Create a configuration file in `~/.overscribe.yaml` like:
59
+
60
+ ```
61
+ profiles:
62
+ audio:
63
+ directory: '~/Music'
64
+ youtubedl_args: ['--format', 'bestaudio', '--extract-audio']
65
+ audio:album:
66
+ directory: '~/Music'
67
+ youtubedl_args: ['--format', 'bestaudio', '--extract-audio']
68
+ filename_pattern: '%(playlist_index)s. %(title)s.%(ext)s'
69
+ video hd:
70
+ directory: '~/Videos'
71
+ youtubedl_args: ['--format' 'bestvideo+bestaudio']
72
+ video:interview:
73
+ directory: '~/Videos'
74
+ youtubedl_args: ['--format', 'bestvideo[height<800]+bestaudio']
75
+ filename_pattern: '%(upload_date)s - %(title)s.%(ext)s'
76
+
77
+ collections:
78
+ "Thinkerview/Sciences":
79
+ url: https://www.youtube.com/playlist?list=PLnRz6CkWwLlKnn_ggkzcvaBzmZjOoefJP
80
+ profile: video:interview
81
+ ```
82
+
83
+ ### YoutubeDL
84
+
85
+ _Overscribe_ relies on [youtube-dl](https://youtube-dl.org/).
86
+
87
+ In configuration file, `youtubedl_args` and `filename_pattern` options should be set according to [youtube-dl documentation](https://github.com/ytdl-org/youtube-dl/blob/master/README.md)
88
+
89
+ ## Contributing
90
+
91
+ Pull requests are welcome on GitHub at https://github.com/neomilium/overscribe.
92
+
93
+ ## License
94
+
95
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rubocop/rake_task'
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'overscribe'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/overscribe ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ require 'overscribe/cli'
6
+
7
+ begin
8
+ Overscribe::CLI.start ARGV
9
+ rescue Overscribe::Error => e
10
+ warn e.message
11
+ exit 1
12
+ end
@@ -0,0 +1,54 @@
1
+ require 'overscribe'
2
+
3
+ require 'thor'
4
+
5
+ module Overscribe
6
+ class CLI < Thor
7
+ class Collections < Thor
8
+ class_option :simulate,
9
+ desc: 'Do not download',
10
+ aliases: '-s',
11
+ type: :boolean,
12
+ default: false
13
+ desc 'fetch [PATTERN]', 'Fetch collections that start with PATTERN'
14
+ option :limit,
15
+ desc: 'Limit downloads per collection',
16
+ type: :numeric,
17
+ default: 1
18
+ def fetch(pattern = nil)
19
+ Overscribe.fetch_collections(options.merge(pattern: pattern))
20
+ end
21
+
22
+ desc 'list [PATTERN]', 'Fetch collections that start with PATTERN'
23
+ def list(pattern = nil)
24
+ puts Overscribe.list_collections(options.merge(pattern: pattern)).keys.join "\n"
25
+ end
26
+ end
27
+
28
+ desc 'oneshot URL', 'Fetch medias from URL'
29
+ option :profile,
30
+ desc: <<~DESC,
31
+ Use the specified profile to download medias
32
+ #{' ' * 37}# Profiles: #{Overscribe.profiles.map { |key, _| key }}
33
+ DESC
34
+ aliases: '-p',
35
+ required: true
36
+ option :collection,
37
+ desc: 'Generate a named collection',
38
+ type: :string
39
+ option :extra_args,
40
+ desc: 'Add extra arguments to youtube-dl',
41
+ aliases: '-x',
42
+ type: :string
43
+ def oneshot(url)
44
+ Overscribe.fetch_oneshot(url, options)
45
+ end
46
+
47
+ desc 'collections', 'Play with collections'
48
+ subcommand 'collections', CLI::Collections
49
+
50
+ def self.exit_on_failure?
51
+ true
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module Overscribe
2
+ VERSION = '0.3.1'.freeze
3
+ end
@@ -0,0 +1,25 @@
1
+ module Overscribe
2
+ module YoutubeDL
3
+ def self.download(url:, args:, options:)
4
+ command = %w[youtube-dl --add-metadata]
5
+ command += %w[--yes-playlist]
6
+ command += %w[--ignore-errors --no-call-home]
7
+ command += %w[--download-archive .youtube-dl.archive]
8
+
9
+ command += %w[--get-filename] if options['simulate'] == true
10
+ command += %W[--max-downloads #{options['limit']}] unless options['limit'].nil? || options['limit'].zero?
11
+ command += %W[--output #{options['filename_pattern']}] unless options['filename_pattern'].nil?
12
+ command += args
13
+
14
+ command += [url]
15
+ run command
16
+ end
17
+
18
+ def self.run(command)
19
+ puts "Running '#{command}'"
20
+ system(*command)
21
+ status = $CHILD_STATUS
22
+ puts status
23
+ end
24
+ end
25
+ end
data/lib/overscribe.rb ADDED
@@ -0,0 +1,95 @@
1
+ require 'overscribe/version'
2
+ require 'overscribe/youtube_dl'
3
+
4
+ require 'active_support'
5
+ require 'active_support/core_ext/hash/deep_merge' # Hash#deep_merge
6
+
7
+ require 'yaml'
8
+ require 'English'
9
+
10
+ require 'byebug'
11
+
12
+ module Overscribe
13
+ class Error < StandardError; end
14
+
15
+ def self.fetch_collections(cli_options)
16
+ collections = collections(pattern: cli_options['pattern'])
17
+
18
+ collections.each do |collection, options|
19
+ puts ">>> #{collection}"
20
+ options = profile(name: options['profile']).deep_merge(options).deep_merge(cli_options)
21
+
22
+ directory = File.expand_path collection, options['directory']
23
+ FileUtils.mkdir_p directory
24
+ FileUtils.chdir(directory) do
25
+ YoutubeDL.download url: options['url'], args: options['youtubedl_args'], options: options
26
+ end
27
+ end
28
+ end
29
+
30
+ def self.list_collections(cli_options)
31
+ collections(pattern: cli_options['pattern'])
32
+ end
33
+
34
+ def self.fetch_oneshot(url, cli_options)
35
+ profile = profile(name: cli_options['profile'])
36
+ options = profile.deep_merge cli_options
37
+
38
+ directory = File.expand_path cli_options['collection'].to_s, options['directory']
39
+ FileUtils.mkdir_p directory
40
+ FileUtils.chdir(directory) do
41
+ YoutubeDL.download url: url, args: profile['youtubedl_args'], options: options
42
+ generate_collection_config_file(url: url, options: options) unless options['collection'].nil?
43
+ end
44
+ end
45
+
46
+ def self.generate_collection_config_file(url:, options:) # rubocop:disable Metrics/MethodLength
47
+ config = {
48
+ 'profiles' => {
49
+ options['profile'] => profile(name: options['profile']),
50
+ },
51
+ 'collections' => {
52
+ options['collection'] => {
53
+ 'url' => url,
54
+ 'profile' => options['profile'],
55
+ },
56
+ },
57
+ }
58
+ File.write 'overscribe.yaml', config.to_yaml
59
+ end
60
+
61
+ def self.config
62
+ filename = File.expand_path '~/.overscribe.yaml'
63
+ YAML.safe_load(File.read(filename))
64
+ end
65
+
66
+ def self.collections(pattern:)
67
+ collections = config['collections']
68
+
69
+ collections.select! do |collection, options|
70
+ if pattern.nil?
71
+ # Remove manually synced
72
+ !options['manual']
73
+ else
74
+ # Select by pattern
75
+ collection.start_with? pattern
76
+ end
77
+ end
78
+ end
79
+
80
+ DEFAULT_PROFILES = {
81
+ 'audio' => {
82
+ 'youtubedl_args' => %w[--format bestaudio --extract-audio],
83
+ },
84
+ 'video' => {
85
+ 'youtubedl_args' => %w[--format bestvideo+bestaudio],
86
+ },
87
+ }.freeze
88
+ def self.profiles
89
+ DEFAULT_PROFILES.deep_merge config['profiles']
90
+ end
91
+
92
+ def self.profile(name:)
93
+ profiles[name]
94
+ end
95
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'lib/overscribe/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'overscribe'
5
+ spec.version = Overscribe::VERSION
6
+ spec.authors = ['Romuald Conty']
7
+ spec.email = ['romuald@opus-codium.fr']
8
+
9
+ spec.summary = 'Keep your favorites media synced'
10
+ spec.description = 'A tool to download online media like youtube playlists'
11
+ spec.license = 'MIT'
12
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
13
+
14
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
15
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ end
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'activesupport'
22
+ spec.add_dependency 'thor'
23
+
24
+ spec.add_development_dependency 'byebug'
25
+ spec.add_development_dependency 'rubocop'
26
+
27
+ spec.add_development_dependency 'rake', '~> 12.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.metadata['rubygems_mfa_required'] = 'true'
30
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: overscribe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Romuald Conty
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '12.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '12.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: A tool to download online media like youtube playlists
98
+ email:
99
+ - romuald@opus-codium.fr
100
+ executables:
101
+ - overscribe
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".github/workflows/ci.yaml"
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".rubocop.yml"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - exe/overscribe
116
+ - lib/overscribe.rb
117
+ - lib/overscribe/cli.rb
118
+ - lib/overscribe/version.rb
119
+ - lib/overscribe/youtube_dl.rb
120
+ - overscribe.gemspec
121
+ homepage:
122
+ licenses:
123
+ - MIT
124
+ metadata:
125
+ rubygems_mfa_required: 'true'
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 2.5.0
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubygems_version: 3.1.2
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Keep your favorites media synced
145
+ test_files: []