The officially official Devuan Forum!

You are not logged in.

#1 2021-04-19 15:14:29

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

youtube-dl tutorial

Lets start with mp3. Requires ffmpeg

#create youtube-dl directory for Music first.

mkdir -p ~/Music/ytdl 

#create mp3 config directory

mkdir -p ~/.config/yt-mp3/

# create yt-mp3 config

# Save all music under Music directory in your home directory
-o ~/Music/ytdl/%(title)s.%(ext)s
--metadata-from-title "(?P<artist>.+?) - (?P<title>.+)"
--add-metadata
--embed-thumbnail
--no-warnings
--ignore-errors
--restrict-filenames
--extract-audio
--audio-format mp3
--audio-quality 0

in bashrc or aliases file, do ...

alias yt-mp3='youtube-dl --config-location ~/.config/yt-mp3/config'

# command

yt-mp3 https://www.youtube.com/watch?v=WA2gBEDFaJo

Last edited by dice (2021-04-19 15:25:31)

Offline

#2 2021-04-19 23:05:29

andyprough
Member
Registered: 2019-10-19
Posts: 327  

Re: youtube-dl tutorial

This is fantastic! Awesome way to organize a song collection, thank you very much.

I'm using 'ytfzf -L <song name>' to find the url's for the songs, and then yt-mp3 to download them. ytfzf is a very cool ytdl search tool: https://github.com/pystardust/ytfzf

Offline

#3 2021-04-20 08:11:35

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: youtube-dl tutorial

Thanks for the link to ytfzf, i will give it try. Good tool to negate visiting youtube.com in the browser.

Edit: just installed ytfzf, that is awesome smile

Last edited by dice (2021-04-20 08:18:49)

Offline

#4 2021-04-20 15:37:28

andyprough
Member
Registered: 2019-10-19
Posts: 327  

Re: youtube-dl tutorial

How about making a "yt-webm" or "yt-opus" (or similar) for downloading and playing lower-quality audios. For downloading lectures and podcasts where quality doesn't matter but getting a small file size is more important. I use this option a lot with the NewPipe app on my phone, which gives me a 50kbps opus option as the lowest quality download. Would there be many changes to make in your method besides the --audio-format option?

Offline

#5 2021-04-20 19:41:56

bgstack15
Member
Registered: 2018-02-04
Posts: 205  

Re: youtube-dl tutorial

Haha, that's nice! I have never dug deep enough with youtube-dl to discover you could save the flags to a file. In my ~/.useful file I just have my example:

youtube-dl -x --audio-format mp3 https://www.youtube.com/watch?v=1234567890

This space intentionally left blank.

Offline

#6 2021-04-21 08:15:52

dice
Member
Registered: 2020-11-22
Posts: 559  
Website

Re: youtube-dl tutorial

andyprough wrote:

How about making a "yt-webm" or "yt-opus" (or similar) for downloading and playing lower-quality audios. For downloading lectures and podcasts where quality doesn't matter but getting a small file size is more important. I use this option a lot with the NewPipe app on my phone, which gives me a 50kbps opus option as the lowest quality download. Would there be many changes to make in your method besides the --audio-format option?

That seems a bit trickier to accomplish into a directory of its own say /home/dice/podcasts using a config as i cant see an option to properly just download the available audio formats instead of downloading and converting the video, cause we dont want the best audio download of say 160M, which is what --audio-quality 0 to 9 will do in the config, even at 9 the file i downloaded was 160MB whereas the audio only in opus was 58M.

man youtub-dl says,

  Video Format Options:
    -f, --format FORMAT                  Video format code, see the "FORMAT SELECTION" for all the info
    --all-formats                        Download all available video formats
    --prefer-free-formats                Prefer free video formats unless a specific one is requested
    -F, --list-formats                   List all available formats of requested videos
    --youtube-skip-dash-manifest         Do not download the DASH manifests and related data on YouTube videos
    --merge-output-format FORMAT         If a merge is required (e.g. bestvideo+bestaudio), output to given container format. One of mkv, mp4, ogg, webm, flv. Ignored if no merge is
                                         required

example using youtube-dl -F to inspect formats.

~$ youtube-dl -F https://www.youtube.com/watch?v=cq1g8czIBJY
[youtube] cq1g8czIBJY: Downloading webpage
[info] Available formats for cq1g8czIBJY:
format code  extension  resolution note
249          webm       audio only tiny   54k , webm_dash container, opus @ 54k (48000Hz), 58.23MiB
250          webm       audio only tiny   74k , webm_dash container, opus @ 74k (48000Hz), 79.40MiB
140          m4a        audio only tiny  129k , m4a_dash container, mp4a.40.2@129k (44100Hz), 138.29MiB
251          webm       audio only tiny  152k , webm_dash container, opus @152k (48000Hz), 163.14MiB
160          mp4        256x144    144p   14k , mp4_dash container, avc1.4d400c@  14k, 24fps, video only, 15.05MiB
278          webm       256x144    144p   39k , webm_dash container, vp9@  39k, 24fps, video only, 42.63MiB
133          mp4        426x240    240p   26k , mp4_dash container, avc1.4d4015@  26k, 24fps, video only, 28.18MiB
242          webm       426x240    240p   62k , webm_dash container, vp9@  62k, 24fps, video only, 66.48MiB
134          mp4        640x360    360p   39k , mp4_dash container, avc1.4d401e@  39k, 24fps, video only, 42.01MiB
243          webm       640x360    360p  119k , webm_dash container, vp9@ 119k, 24fps, video only, 128.01MiB
135          mp4        854x480    480p   57k , mp4_dash container, avc1.4d401e@  57k, 24fps, video only, 61.75MiB
244          webm       854x480    480p  186k , webm_dash container, vp9@ 186k, 24fps, video only, 198.95MiB
136          mp4        1280x720   720p   78k , mp4_dash container, avc1.4d401f@  78k, 24fps, video only, 83.70MiB
247          webm       1280x720   720p  314k , webm_dash container, vp9@ 314k, 24fps, video only, 335.58MiB
137          mp4        1920x1080  1080p  262k , mp4_dash container, avc1.640028@ 262k, 24fps, video only, 280.76MiB
248          webm       1920x1080  1080p  642k , webm_dash container, vp9@ 642k, 24fps, video only, 685.82MiB
18           mp4        640x360    360p  253k , avc1.42001E, 24fps, mp4a.40.2 (44100Hz), 271.26MiB
22           mp4        1280x720   720p  207k , avc1.64001F, 24fps, mp4a.40.2 (44100Hz) (best)

The best i could come up with below hoping that most audio only formats are in the same format code that being 249 for the lowest possible download and lowest possible bitrate? So this way im only download and converting webm to opus and the total download is 58M not 160M. Note that thumbnail embedding cant be done with opus, not sure about webm.

mkdir -p ~/Music/podcasts
mkdir -p ~/.config/yt-podcasts/

config..

# Save all podcasts inside music directory in your home directory
-o ~/Music/podcasts/%(title)s.%(ext)s
--metadata-from-title "(?P<artist>.+?) - (?P<title>.+)"
--add-metadata
--no-warnings
--ignore-errors
--restrict-filenames
--extract-audio
--audio-format opus
--format 249

alias..

alias yt-podcasts='youtube-dl --config-location ~/.config/yt-podcasts/config'

Hope that made sense, maybe someone smarter than me knows a better way.

Last edited by dice (2021-04-21 08:41:53)

Offline

#7 2021-04-21 15:46:49

andyprough
Member
Registered: 2019-10-19
Posts: 327  

Re: youtube-dl tutorial

dice wrote:

Hope that made sense, maybe someone smarter than me knows a better way.

Yes, that works. I checked one download on both my phone through NewPipe as a small opus file, and with your opus download method, and I got the same file size with each download. I'll try a few more, but I think that you've got it figured out. It's about 1/5 the size of the same file using an mp3 download, which is a big difference especially for long audio files that could otherwise fill up available space quickly.

Having a thumbnail is not something I need for podcasts and lectures. Thumbnails help to quickly tell which song is playing at a glance, but for a longer podcast or lecture I wouldn't need it.

Offline

Board footer