Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maxhollmann/ruby-ytdl
A Ruby wrapper for youtube-dl with progress callbacks
https://github.com/maxhollmann/ruby-ytdl
downloader ruby ruby-gem wrapper youtube youtube-dl
Last synced: about 2 months ago
JSON representation
A Ruby wrapper for youtube-dl with progress callbacks
- Host: GitHub
- URL: https://github.com/maxhollmann/ruby-ytdl
- Owner: maxhollmann
- License: mit
- Created: 2020-05-05T17:38:47.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-01-22T19:46:39.000Z (12 months ago)
- Last Synced: 2024-10-31T13:30:03.136Z (2 months ago)
- Topics: downloader, ruby, ruby-gem, wrapper, youtube, youtube-dl
- Language: Ruby
- Size: 20.5 KB
- Stars: 8
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ytdl
A Ruby wrapper for yt-dlp/youtube-dl with progress callbacks.
## Installation
```shell
gem install ytdl
``````ruby
gem 'ytdl'
```Make sure you have [yt-dlp](https://github.com/yt-dlp/yt-dlp) or [youtube-dl](https://github.com/ytdl-org/youtube-dl) installed and available in your `PATH`. If you have `pip` installed:
```shell
pip install yt-dlp
# or
pip install youtube-dl
```## Usage
Minimal example:
```ruby
YoutubeDL.download('https://www.youtube.com/watch?v=MmIWve5bUpU').call
```With callbacks and options:
```ruby
state = YoutubeDL.download('https://www.youtube.com/watch?v=MmIWve5bUpU', format: 'mp4')
.on_progress do |state:, line:|
puts "Progress: #{state.progress}%"
end
.on_error do |state:, line:|
puts "Error: #{state.error}"
end
.on_complete do |state:, line:|
puts "Complete: #{state.destination}"
end
.call
````YoutubeDL.download` returns the state after `yt-dlp` has exited. If the download was successful, `state.info_json` is loaded into `state.info` and the `info_json` file deleted.
### Configuration
```ruby
YoutubeDL::Command.config.executable = 'youtube-dl' # if you're using youtube-dl instead of yt-dlp
YoutubeDL::Command.config.default_options = { some_option: true }
```### Events
One event is emitted for each line printed by `yt-dlp`.
The full list of events types is:
* `unparsable`: The `OutputParser` couldn't parse the line
* `destination`: Download destination announcement (stored in `state.destination`)
* `info_json`: Info JSON destination announcement (stored in `state.info_json`)
* `progress`: Download progress in percentage (stored in `state.progress`)
* `error`: An error message (stored in `state.error` without the `ERROR: ` prefix)
* `complete`: The download is complete (Info JSON is parsed into `state.info` and deleted, `state.destination` now exists)
* `unclear_exit_state`: `yt-dlp` exited without error, but either `destination` or `info_json` does not exist### Options
Options passed to `YoutubeDL.download` get transformed as follows:
* `some_option: true` becomes `--some-option`
* `some_option: false` becomes `--no-some-option`
* `some_option: 'anything'` becomes `--some-option anything`
* `some_option: nil` can be used to remove a default option