yt_dlp 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3704fb56f4b154eb956126f7d197c5985315607a971fc90c085f719fc594a470
4
+ data.tar.gz: 706e6c1241e35ca9573ec4d966d3dace8d3a78d197d24cacf7eaa5d307442da4
5
+ SHA512:
6
+ metadata.gz: 92841c5d4dd11e7bea1febe1cc31cd8fd72af2704108265ed536d6768116e790bc42693423d996162c491110340c39105e0c6defb7c4642a1693dc15ac2816e0
7
+ data.tar.gz: 6984417a9309e0cf91bf2ee99760658fd02eeabbeae3471a113c09a3199fe25b176722917c84f7f506a52d3e28c5e8a043558324528065832765596c2cce6e45
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'bundler'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'daily'
@@ -0,0 +1,31 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ '**' ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ ci:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: 2.6
18
+ - name: Install dependencies
19
+ run: bundle install
20
+ - name: Run tests
21
+ run: bundle exec rake ci
22
+ env:
23
+ REGION: uscentral
24
+ SUBSCRIPTION_KEY: k3ah8ztrc4ojeh98r05zh7v6x9w62lqp
25
+ - name: Coveralls
26
+ uses: coverallsapp/github-action@master
27
+ with:
28
+ github-token: ${{ secrets.GITHUB_TOKEN }}
29
+ path-to-lcov: "./coverage/lcov.info"
30
+ - name: Rubocop
31
+ run: rubocop
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-performance
4
+
5
+ AllCops:
6
+ DisplayCopNames: true
7
+ NewCops: enable
8
+ TargetRubyVersion: 2.6
9
+
10
+ Layout/LineLength:
11
+ Max: 100
12
+
13
+ Metrics/MethodLength:
14
+ Max: 20
15
+
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+ - 'Rakefile'
19
+ - 'spec/**/*.rb'
20
+
21
+ Style/Documentation:
22
+ Enabled: false
23
+
24
+ RSpec/FilePath:
25
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog],
6
+ and this project adheres to [Semantic Versioning].
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.1] - 2021-09-17
11
+
12
+ ### Fixed
13
+
14
+ - Typo in gemspec
15
+
16
+ ## [0.1.0] - 2021-09-17
17
+
18
+ Initial release
19
+
20
+ <!-- Links -->
21
+ [keep a changelog]: https://keepachangelog.com/en/1.0.0/
22
+ [semantic versioning]: https://semver.org/spec/v2.0.0.html
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at axel.delsol@perfect-memory.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in yt_dlp.gemspec
8
+ gemspec
9
+
10
+ group :test do
11
+ gem 'debase', require: false
12
+ gem 'rubocop', require: false
13
+ gem 'rubocop-performance', require: false
14
+ gem 'rubocop-rake', require: false
15
+ gem 'rubocop-rspec', require: false
16
+ gem 'ruby-debug-ide', require: false
17
+ gem 'simplecov', require: false
18
+ gem 'simplecov-lcov', require: false
19
+ gem 'solargraph', require: false
20
+ gem 'yard'
21
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,124 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ yt_dlp (0.1.1)
5
+ terrapin (~> 0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ backport (1.2.0)
12
+ benchmark (0.1.1)
13
+ climate_control (0.2.0)
14
+ debase (0.2.4.1)
15
+ debase-ruby_core_source (>= 0.10.2)
16
+ debase-ruby_core_source (0.10.12)
17
+ diff-lcs (1.4.4)
18
+ docile (1.4.0)
19
+ e2mmap (0.1.0)
20
+ jaro_winkler (1.5.4)
21
+ kramdown (2.3.1)
22
+ rexml
23
+ kramdown-parser-gfm (1.1.0)
24
+ kramdown (~> 2.0)
25
+ nokogiri (1.12.4-x86_64-linux)
26
+ racc (~> 1.4)
27
+ parallel (1.21.0)
28
+ parser (3.0.2.0)
29
+ ast (~> 2.4.1)
30
+ racc (1.5.2)
31
+ rainbow (3.0.0)
32
+ rake (13.0.6)
33
+ regexp_parser (2.1.1)
34
+ reverse_markdown (2.0.0)
35
+ nokogiri
36
+ rexml (3.2.5)
37
+ rspec (3.10.0)
38
+ rspec-core (~> 3.10.0)
39
+ rspec-expectations (~> 3.10.0)
40
+ rspec-mocks (~> 3.10.0)
41
+ rspec-core (3.10.1)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-expectations (3.10.1)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-its (1.3.0)
47
+ rspec-core (>= 3.0.0)
48
+ rspec-expectations (>= 3.0.0)
49
+ rspec-mocks (3.10.2)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.10.0)
52
+ rspec-support (3.10.2)
53
+ rubocop (1.21.0)
54
+ parallel (~> 1.10)
55
+ parser (>= 3.0.0.0)
56
+ rainbow (>= 2.2.2, < 4.0)
57
+ regexp_parser (>= 1.8, < 3.0)
58
+ rexml
59
+ rubocop-ast (>= 1.9.1, < 2.0)
60
+ ruby-progressbar (~> 1.7)
61
+ unicode-display_width (>= 1.4.0, < 3.0)
62
+ rubocop-ast (1.11.0)
63
+ parser (>= 3.0.1.1)
64
+ rubocop-performance (1.11.5)
65
+ rubocop (>= 1.7.0, < 2.0)
66
+ rubocop-ast (>= 0.4.0)
67
+ rubocop-rake (0.6.0)
68
+ rubocop (~> 1.0)
69
+ rubocop-rspec (2.4.0)
70
+ rubocop (~> 1.0)
71
+ rubocop-ast (>= 1.1.0)
72
+ ruby-debug-ide (0.7.2)
73
+ rake (>= 0.8.1)
74
+ ruby-progressbar (1.11.0)
75
+ simplecov (0.21.2)
76
+ docile (~> 1.1)
77
+ simplecov-html (~> 0.11)
78
+ simplecov_json_formatter (~> 0.1)
79
+ simplecov-html (0.12.3)
80
+ simplecov-lcov (0.8.0)
81
+ simplecov_json_formatter (0.1.3)
82
+ solargraph (0.43.0)
83
+ backport (~> 1.2)
84
+ benchmark
85
+ bundler (>= 1.17.2)
86
+ diff-lcs (~> 1.4)
87
+ e2mmap
88
+ jaro_winkler (~> 1.5)
89
+ kramdown (~> 2.3)
90
+ kramdown-parser-gfm (~> 1.1)
91
+ parser (~> 3.0)
92
+ reverse_markdown (>= 1.0.5, < 3)
93
+ rubocop (>= 0.52)
94
+ thor (~> 1.0)
95
+ tilt (~> 2.0)
96
+ yard (~> 0.9, >= 0.9.24)
97
+ terrapin (0.6.0)
98
+ climate_control (>= 0.0.3, < 1.0)
99
+ thor (1.1.0)
100
+ tilt (2.0.10)
101
+ unicode-display_width (2.0.0)
102
+ yard (0.9.26)
103
+
104
+ PLATFORMS
105
+ ruby
106
+
107
+ DEPENDENCIES
108
+ debase
109
+ rake (~> 13.0)
110
+ rspec (~> 3.0)
111
+ rspec-its (~> 1.3)
112
+ rubocop
113
+ rubocop-performance
114
+ rubocop-rake
115
+ rubocop-rspec
116
+ ruby-debug-ide
117
+ simplecov
118
+ simplecov-lcov
119
+ solargraph
120
+ yard
121
+ yt_dlp!
122
+
123
+ BUNDLED WITH
124
+ 1.17.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Perfect Memory
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # yt_dlp
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/yt_dlp.svg)](https://badge.fury.io/rb/yt_dlp)
4
+ [![CI](https://github.com/PerfectMemory/yt_dlp/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/PerfectMemory/yt_dlp/actions/workflows/ci.yml)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/e0a6aab8925641f3e0a3/maintainability)](https://codeclimate.com/github/PerfectMemory/yt_dlp/maintainability)
6
+ [![Coverage Status](https://coveralls.io/repos/github/PerfectMemory/yt_dlp/badge.svg?branch=main)](https://coveralls.io/github/PerfectMemory/yt_dlp?branch=main)
7
+
8
+ Wrapper for the [yt_dlp](https://github.com/yt-dlp/yt-dlp) tool.
9
+ This gem is heavily inspired by the [youtube_dl.rb](https://github.com/layer8x/youtube-dl.rb) gem.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'yt_dlp'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```bash
22
+ bundle
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ```bash
28
+ gem install yt_dlp
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### Configuration
34
+
35
+ One can configure:
36
+
37
+ - 'executable_path': the path where yt-dlp is located. Default : vendor/bin/yt-dlp
38
+
39
+ - 'logger': the logger used to print various parts of the execution.
40
+
41
+ Those variable can be configured using the following code:
42
+
43
+ ```ruby
44
+ YtDlp.configure do |config|
45
+ config.executable_path = <YOUR_PATH>
46
+ config.logger = <YOUR_LOGGER>
47
+ end
48
+ ```
49
+
50
+ ### Download a video
51
+
52
+ ```ruby
53
+ require 'yt_dlp'
54
+
55
+ YtDlp.configure do |config|
56
+ # config.executable_path = 'path/to/yt-dlp'
57
+ config.logger = Logger.new($stderr)
58
+ end
59
+
60
+ url = 'https://www.youtube.com/watch?v=fzlT80jQ3lo'
61
+
62
+ # See https://github.com/yt-dlp/yt-dlp for the list of options
63
+ video = YtDlp::Video.new url, output: 'test.mp4'
64
+
65
+ output_file = video.download
66
+ # Do something with output file
67
+ ```
68
+
69
+ ### Get information about a video
70
+
71
+ ```ruby
72
+ require 'yt_dlp'
73
+
74
+ YtDlp.configure do |config|
75
+ # config.executable_path = 'path/to/yt-dlp'
76
+ config.logger = Logger.new($stderr)
77
+ end
78
+
79
+ url = 'https://www.youtube.com/watch?v=fzlT80jQ3lo'
80
+
81
+ # See https://github.com/yt-dlp/yt-dlp for the list of options
82
+ video = YtDlp::Video.new url
83
+
84
+ information = video.information
85
+ # Do something with information
86
+ ```
87
+
88
+ ## Development
89
+
90
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
91
+
92
+ ## Contributing
93
+
94
+ Bug reports and pull requests are welcome on GitHub at https://github.com/PerfectMemory/yt_dlp. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
95
+
96
+ ## Code of Conduct
97
+
98
+ Everyone interacting in the AzureStt project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/PerfectMemory/yt_dlp/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Run RSpec code examples (unit & integration tests, needs live instance)'
6
+ RSpec::Core::RakeTask.new('spec:all') do |task|
7
+ task.pattern = './spec/**/*_spec.rb'
8
+ task.rspec_opts = '-O .rspec-no-tags'
9
+ end
10
+
11
+ desc 'Run RSpec code examples (unit tests only)'
12
+ RSpec::Core::RakeTask.new(:spec) do |task|
13
+ task.pattern = './spec/**/*_spec.rb'
14
+ task.exclude_pattern = './spec/integration/**/*_spec.rb'
15
+ task.rspec_opts = '-O .rspec'
16
+ end
17
+
18
+ desc 'Run RSpec code examples (integration tests only, needs live instance)'
19
+ RSpec::Core::RakeTask.new('spec:integration') do |task|
20
+ task.pattern = './spec/**/*_spec.rb'
21
+ task.rspec_opts = '-O .rspec --tag integration'
22
+ end
23
+
24
+ desc 'Run CI tests'
25
+ task ci: %i[spec]
26
+
27
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ # !/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'yt_dlp'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ 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/examples/run.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
4
+
5
+ #########
6
+ require 'yt_dlp'
7
+
8
+ YtDlp.configure do |config|
9
+ # config.executable_path = 'path/to/yt-dlp'
10
+ config.logger = Logger.new($stderr)
11
+ end
12
+
13
+ url = 'https://www.youtube.com/watch?v=fzlT80jQ3lo'
14
+
15
+ # See https://github.com/yt-dlp/yt-dlp for the list of options
16
+ video = YtDlp::Video.new url, output: 'test.mp4'
17
+
18
+ video.download
19
+ #########
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YtDlp
4
+ class Configuration
5
+ attr_writer :logger, :executable_path
6
+
7
+ def logger
8
+ @logger ||= Logger.new($stdout)
9
+ end
10
+
11
+ def executable_path
12
+ @executable_path ||= File.join(__dir__, '../../vendor/bin/yt-dlp')
13
+ end
14
+ end
15
+
16
+ class << self
17
+ def configure
18
+ yield config
19
+ end
20
+
21
+ def config
22
+ @config ||= Configuration.new
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YtDlp
4
+ #
5
+ # Class responsible for converting a ruby Hash into valid yt-dlp options.
6
+ # Convert the option Hash into valid yt-dlp options.
7
+ # (key,value) pairs are transformed according to the following rules
8
+ # * { key: value } --> '--key value'
9
+ # * { my_key: value } --> '--my-key value'. Allow dev to keep using ruby naming conventions
10
+ # * { key: true } --> '--key'
11
+ # * { key: false } --> '--no-key'
12
+ #
13
+ class OptionsConverter
14
+ attr_reader :options
15
+
16
+ #
17
+ # Initialize the runner options.
18
+ #
19
+ # @param [Hash] options contains the option to pass to yt-dlp
20
+ #
21
+ def initialize(options = {})
22
+ @options = options
23
+ end
24
+
25
+ #
26
+ # Convert the option Hash into valid yt-dlp options.
27
+ # (key,value) pairs are transformed according to the following rules
28
+ # * { key: value } --> '--key value'
29
+ # * { my_key: value } --> '--my-key value'. Allow dev to keep using ruby naming conventions
30
+ # * { key: true } --> '--key'
31
+ # * { key: false } --> '--no-key'
32
+ #
33
+ # @return [String] yt-dlp options
34
+ #
35
+ def to_command_options
36
+ @to_command_options ||= build_to_command_options
37
+ end
38
+
39
+ private
40
+
41
+ def build_to_command_options
42
+ options
43
+ .map { |key, value| to_yt_dlp_option(sanitize_key(key), value.to_s) }
44
+ .join(' ')
45
+ end
46
+
47
+ def to_yt_dlp_option(key, value)
48
+ case value
49
+ when 'true'
50
+ "--#{key}"
51
+ when 'false'
52
+ "--no-#{key}"
53
+ else
54
+ "--#{key} #{value}"
55
+ end
56
+ end
57
+
58
+ def sanitize_key(key)
59
+ key.to_s.tr('_', '-')
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YtDlp
4
+ #
5
+ # Wraps the execution of the yt-dlp command.
6
+ #
7
+ class Runner
8
+ attr_reader :executable_path, :url, :options
9
+
10
+ #
11
+ # Initialize the runner.
12
+ #
13
+ # @param [String] executable_path Executable to run
14
+ # @param [<Type>] url Download URL
15
+ # @param [options] options Command options
16
+ #
17
+ def initialize(executable_path:, url:, options: {})
18
+ @executable_path = executable_path
19
+ @url = url
20
+ @options = options
21
+ end
22
+
23
+ #
24
+ # Run the executable with the specified options.
25
+ #
26
+ # @return [String] execution output
27
+ #
28
+ def run
29
+ command_line.run
30
+ rescue Terrapin::CommandLineError
31
+ raise Errors::YtDlpError
32
+ end
33
+
34
+ private
35
+
36
+ def command_line
37
+ @command_line ||= build_command_line
38
+ end
39
+
40
+ def build_command_line
41
+ Terrapin::CommandLine.new(
42
+ executable_path.to_s,
43
+ "#{quoted_url} #{command_options}",
44
+ logger: YtDlp.config.logger
45
+ )
46
+ end
47
+
48
+ def quoted_url
49
+ "\"#{url}\""
50
+ end
51
+
52
+ def command_options
53
+ runner_options.to_command_options
54
+ end
55
+
56
+ def runner_options
57
+ @runner_options ||= OptionsConverter.new(options)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YtDlp
4
+ VERSION = '0.1.1'
5
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YtDlp
4
+ #
5
+ # Data model for a video accessed from an URL.
6
+ #
7
+ class Video
8
+ attr_reader :url, :executable_path, :options
9
+
10
+ # Required to get informations about the video.
11
+ MANDATORY_OPTIONS = {
12
+ dump_json: true,
13
+ simulate: false
14
+ }.freeze
15
+
16
+ # Optimisation purpose. Do not download the video if you only need information.
17
+ INFORMATION_OPTIONS = MANDATORY_OPTIONS.merge(skip_download: true).freeze
18
+
19
+ #
20
+ # Initialize a Video.
21
+ #
22
+ #
23
+ # @param [String] url Download URL
24
+ # @param [Hash] **options See OptionConverter and https://github.com/yt-dlp/yt-dlp
25
+ #
26
+ def initialize(url, executable_path = YtDlp.config.executable_path, **options)
27
+ @url = url
28
+ @executable_path = executable_path
29
+ @options = options
30
+ end
31
+
32
+ def download
33
+ @information = run_with_options(options.merge(MANDATORY_OPTIONS))
34
+ @information[:filename]
35
+ end
36
+
37
+ def information
38
+ @information ||= run_with_options(options.merge(INFORMATION_OPTIONS))
39
+ end
40
+
41
+ private
42
+
43
+ def run_with_options(options)
44
+ JSON.parse(run(options), symbolize_names: true)
45
+ end
46
+
47
+ def run(options)
48
+ Runner.new(executable_path: executable_path, url: url, options: options).run
49
+ end
50
+ end
51
+ end
data/lib/yt_dlp.rb ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'logger'
5
+ require 'terrapin'
6
+ require 'yt_dlp/version'
7
+
8
+ #
9
+ # Top level module for YtDlp.
10
+ #
11
+ module YtDlp
12
+ module Errors
13
+ class YtDlpError < StandardError
14
+ end
15
+ end
16
+ end
17
+
18
+ require_relative 'yt_dlp/configuration'
19
+ require_relative 'yt_dlp/options_converter'
20
+ require_relative 'yt_dlp/runner'
21
+ require_relative 'yt_dlp/video'
data/vendor/bin/yt-dlp ADDED
Binary file
data/yt_dlp.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'yt_dlp/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'yt_dlp'
9
+ spec.version = YtDlp::VERSION
10
+ spec.authors = ['Axel Delsol']
11
+ spec.email = ['axel.delsol@perfect-memory.com']
12
+
13
+ spec.summary = 'yt-dlp wrapper for Ruby'
14
+ spec.description = 'Command line wrapper for the python script yt-dlp'
15
+ spec.homepage = 'https://github.com/PerfectMemory/yt-dlp'
16
+ spec.license = 'MIT'
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.required_ruby_version = '>= 2.6'
27
+
28
+ spec.add_runtime_dependency 'terrapin', '~> 0'
29
+
30
+ spec.add_development_dependency 'rake', '~> 13.0'
31
+ spec.add_development_dependency 'rspec', '~> 3.0'
32
+ spec.add_development_dependency 'rspec-its', '~> 1.3'
33
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yt_dlp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Axel Delsol
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: terrapin
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ description: Command line wrapper for the python script yt-dlp
70
+ email:
71
+ - axel.delsol@perfect-memory.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".github/dependabot.yml"
77
+ - ".github/workflows/ci.yml"
78
+ - ".gitignore"
79
+ - ".rubocop.yml"
80
+ - CHANGELOG.md
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - examples/run.rb
90
+ - lib/yt_dlp.rb
91
+ - lib/yt_dlp/configuration.rb
92
+ - lib/yt_dlp/options_converter.rb
93
+ - lib/yt_dlp/runner.rb
94
+ - lib/yt_dlp/version.rb
95
+ - lib/yt_dlp/video.rb
96
+ - vendor/bin/yt-dlp
97
+ - yt_dlp.gemspec
98
+ homepage: https://github.com/PerfectMemory/yt-dlp
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '2.6'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubygems_version: 3.0.3
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: yt-dlp wrapper for Ruby
121
+ test_files: []