-
Notifications
You must be signed in to change notification settings - Fork 69
4. Enhancing Your First Config
So far, we have our first config:
configuration:
working_directory: '/tmp/ytdl-sub-downloads'
presets:
yt_video:
download:
download_strategy: "url"
output_options:
output_directory: "/config/first_config/output_videos"
file_name: "{upload_date_standardized}.{title_sanitized}.{ext}"
thumbnail_name: "{upload_date_standardized}.{title_sanitized}.{thumbnail_ext}"
Now that you know the basics of a ytdl-sub
config, let's learn other useful features to enhance it.
In this example, we will modify our config to be able to download from YouTube videos, playlists, or channels, and place the files in organized folders depending on the video type. The types could be concerts
, music_videos
, tutorials
, or the channel name itself.
We know that source variables contain values that are derived from entries. Override variables are user-defined variables that can contain both hard-coded strings, source variables, and other override variables.
Let's create two override variables - one that simplifies our file and thumbnail name, and another to define our video type. For now, set the video_type
variable be to the channel's name. We will see why later.
overrides:
video_name: "{upload_date_standardized}.{title_sanitized}"
video_type: "{channel}"
Since override variables are often used as file or directory names, additional sanitized override variables are automatically created which are safe to use for file paths. Let's now modify our output options to have the entry files save in the video_type_sanitized
directory and use our shortened video_name
variable.
output_options:
output_directory: "/config/first_config/output_videos"
file_name: "{video_type_sanitized}/{video_name}.{ext}"
thumbnail_name: "{video_type_sanitized}/{video_name}.{thumbnail_ext}"
Specifying {video_type_sanitized}/{video_name}
twice is redundant. Let's make another override containing our original overrides to simplify this even further.
overrides:
video_name: "{upload_date_standardized}.{title_sanitized}"
video_type: "{channel}"
video_path: "{video_type_sanitized}/{video_name}"
Now we can specify our output options as:
output_options:
output_directory: "/config/first_config/output_videos"
file_name: "{video_path}.{ext}"
thumbnail_name: "{video_path}.{thumbnail_ext}"
We saw with subscriptions that you can specify a preset
field, which will inherit all fields from the specified preset via merging values. We can specify this in presets themselves, allowing preset inheritance.
We will use preset inheritance to create two new presets to download YouTube playlists and channels using our yt_video
preset.
configuration:
working_directory: '/tmp/ytdl-sub-downloads'
presets:
yt_video:
download:
download_strategy: "url"
output_options:
output_directory: "/config/first_config/output_videos"
file_name: "{video_path}.{ext}"
thumbnail_name: "{video_path}.{thumbnail_ext}"
overrides:
video_name: "{upload_date_standardized}.{title_sanitized}"
video_type: "{channel}"
video_path: "{video_type_sanitized}/{video_name}"
yt_playlist:
preset:
- "yt_video"
yt_channel:
preset:
- "yt_playlist"
Our config now has the following inheritance hierarchy:
yt_channel <--inherits-- yt_playlist <--inherits-- yt_video
The presets do not add anything new yet. We will add tweaks to them later on.
Here is our original subscription.yaml
file:
rick_a:
preset: "yt_video"
download:
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
A lot has changed since we first made this. If we dry run this with our new config, we'll see the following:
ytdl-sub --dry-run sub
Files created in '/config/first_config/output_videos'
----------------------------------------
Rick Astley/2009-10-25.Rick Astley - Never Gonna Give You Up (Official Music Video).jpg
Rick Astley/2009-10-25.Rick Astley - Never Gonna Give You Up (Official Music Video).mp4
Notice that the video would now save to the Rick Astley/
directory. This is because our video_type
variable is set to {channel}
.
Let's store this in a Music Video/
directory instead. We can do this by overriding overrides.video_type
in our subscription:
rick_a:
preset: "yt_video"
download:
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
overrides:
video_type: "Music Videos"
If we dry run again, we will see:
ytdl-sub --dry-run sub
Files created in '/config/first_config/output_videos'
----------------------------------------
Music Videos/2009-10-25.Rick Astley - Never Gonna Give You Up (Official Music Video).jpg
Music Videos/2009-10-25.Rick Astley - Never Gonna Give You Up (Official Music Video).mp4
Looks good! But again, since this is a single video, we should use the dl
equivalent command:
ytdl-sub --dry-run dl --preset yt_video --download.url "https://www.youtube.com/watch?v=dQw4w9WgXcQ" --overrides.video_type "Music Videos"
The above dl
command is extremely long and not easy to remember. We can simplify it by creating
dl aliases
in our config.yaml
:
configuration:
working_directory: '/tmp/ytdl-sub-downloads'
dl_aliases:
video: "--preset yt_video"
video-url: "--download.url"
type: "--overrides.video_type"
As the name suggests, this creates aliases that will be resolved at run time. We can now specify the above command as:
ytdl-sub --dry-run dl --video --video-url "https://www.youtube.com/watch?v=dQw4w9WgXcQ" --type "Music Video"
We could take it a step further and make a more encapsulating dl alias:
configuration:
working_directory: '/tmp/ytdl-sub-downloads'
dl_aliases:
video: "--preset yt_video"
video-url: "--youtube.video_url"
type: "--overrides.video_type"
single-music-video: "--preset yt_video --overrides.video_type 'Music Video' --download.url"
(At this time, nested dl_aliases are not supported. An issue is made here: https://github.com/jmbannon/ytdl-sub/issues/141) Now we can specify the above command as:
ytdl-sub --dry-run dl --single-music-video "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
Now we can leverage this logic we've created in our config to begin downloading any video type whether it is a video, playlist, or channel in our subscriptions.yaml
file. Let's modify our subscription file to download Rick's official music video playlist:
rick_a_music_video_playlist:
preset: "yt_playlist"
download:
url: "https://www.youtube.com/playlist?list=PLlaN88a7y2_plecYoJxvRFTLHVbIVAOoc"
overrides:
video_type: "Music Videos"
If we dry run, we'll see:
Files created in '/config/first_config/output_videos'
----------------------------------------
Music Videos/
2009-10-25.Rick Astley - Cry for Help (Official Music Video).jpg
2009-10-25.Rick Astley - Cry for Help (Official Music Video).webm
2009-10-25.Rick Astley - Hold Me In Your Arms (Official Music Video).jpg
2009-10-25.Rick Astley - Hold Me In Your Arms (Official Music Video).webm
2009-10-25.Rick Astley - Never Gonna Give You Up (Official Music Video).jpg
2009-10-25.Rick Astley - Never Gonna Give You Up (Official Music Video).mp4
2009-10-25.Rick Astley - Together Forever (Official Video) [Remastered in 4K].jpg
2009-10-25.Rick Astley - Together Forever (Official Video) [Remastered in 4K].webm
2009-10-25.Rick Astley - Whenever You Need Somebody (Official Music Video).jpg
2009-10-25.Rick Astley - Whenever You Need Somebody (Official Music Video).webm
2012-03-14.Rick Astley - Giving Up On Love (Official Video).jpg
2012-03-14.Rick Astley - Giving Up On Love (Official Video).webm
2012-03-14.Rick Astley - Hopelessly (Official Music Video).jpg
2012-03-14.Rick Astley - Hopelessly (Official Music Video).webm
2012-03-14.Rick Astley - She Wants To Dance With Me (Official Music Video).jpg
2012-03-14.Rick Astley - She Wants To Dance With Me (Official Music Video).webm
2012-03-14.Rick Astley - Take Me to Your Heart (Official Music Video).jpg
2012-03-14.Rick Astley - Take Me to Your Heart (Official Music Video).webm
2013-08-22.Rick Astley - Never Gonna Give You Up (Live) (Top Of The Pops 1987).jpg
2013-08-22.Rick Astley - Never Gonna Give You Up (Live) (Top Of The Pops 1987).webm
2015-02-01.Rick Astley - Lights Out (Official Music Video).jpg
2015-02-01.Rick Astley - Lights Out (Official Music Video).webm
2016-04-06.Rick Astley - Keep Singing (Official Music Video).jpg
2016-04-06.Rick Astley - Keep Singing (Official Music Video).webm
2016-06-09.Rick Astley - Angels On My Side (Official Music Video).jpg
2016-06-09.Rick Astley - Angels On My Side (Official Music Video).webm
2016-07-06.Rick Astley - Never Gonna Give You Up (Live) (The Roxy 1987).jpg
2016-07-06.Rick Astley - Never Gonna Give You Up (Live) (The Roxy 1987).webm
2016-07-06.Rick Astley - Whenever You Need Somebody (Live) (The Roxy 1987).jpg
2016-07-06.Rick Astley - Whenever You Need Somebody (Live) (The Roxy 1987).webm
2016-09-07.Rick Astley - Dance (Official Video).jpg
2016-09-07.Rick Astley - Dance (Official Video).webm
2016-11-10.Rick Astley - Pray With Me (Official Music Video).jpg
2016-11-10.Rick Astley - Pray With Me (Official Music Video).webm
2017-06-20.Rick Astley - This Old House (Official Music Video).jpg
2017-06-20.Rick Astley - This Old House (Official Music Video).webm
2018-03-09.Rick Astley - Walk Like A Panther (Official Music Video).jpg
2018-03-09.Rick Astley - Walk Like A Panther (Official Music Video).webm
2018-07-05.Rick Astley - Beautiful Life (Official Music Video).jpg
2018-07-05.Rick Astley - Beautiful Life (Official Music Video).webm
2018-09-13.Rick Astley - Try (Official Music Video).jpg
2018-09-13.Rick Astley - Try (Official Music Video).webm
2018-11-09.Rick Astley - She Makes Me (Official Music Video).jpg
2018-11-09.Rick Astley - She Makes Me (Official Music Video).webm
2019-05-31.Rick Astley - Try (Champions League Tribute Version).jpg
2019-05-31.Rick Astley - Try (Champions League Tribute Version).webm
2019-06-06.Rick Astley - Giant (Official Audio).jpg
2019-06-06.Rick Astley - Giant (Official Audio).webm
2019-06-19.Rick Astley - Giant (Tour Video).jpg
2019-06-19.Rick Astley - Giant (Tour Video).webm
2019-10-30.Rick Astley - Every One of Us (Rehearsal Video).jpg
2019-10-30.Rick Astley - Every One of Us (Rehearsal Video).webm
2019-11-19.Rick Astley - It Would Take a Strong Strong Man (Official HD Video).jpg
2019-11-19.Rick Astley - It Would Take a Strong Strong Man (Official HD Video).webm
2019-11-21.Rick Astley - Move Right Out (UK Version) [Official HD Video].jpg
2019-11-21.Rick Astley - Move Right Out (UK Version) [Official HD Video].webm
2019-11-28.Rick Astley - The Ones You Love (Official HD Video).jpg
2019-11-28.Rick Astley - The Ones You Love (Official HD Video).webm
2019-12-12.Rick Astley - Never Gonna Give You Up (Pianoforte) (Performance).jpg
2019-12-12.Rick Astley - Never Gonna Give You Up (Pianoforte) (Performance).webm
2020-10-15.Rick Astley ft.The Unsung Heroes - Every One of Us (Heroes Edit) (Official Music Video).jpg
2020-10-15.Rick Astley ft.The Unsung Heroes - Every One of Us (Heroes Edit) (Official Music Video).webm
2020-10-23.Rick Astley ft.The Unsung Heroes - Every One of Us (Lyric Video).jpg
2020-10-23.Rick Astley ft.The Unsung Heroes - Every One of Us (Lyric Video).webm
2020-11-30.Rick Astley - Love This Christmas (Lyric Video).jpg
2020-11-30.Rick Astley - Love This Christmas (Lyric Video).webm
2020-12-10.Rick Astley - Love This Christmas (Official Music Video).jpg
2020-12-10.Rick Astley - Love This Christmas (Official Music Video).webm
2021-04-08.Rick Astley - Unwanted (Official Song from the Podcast) (Lyric Video).jpg
2021-04-08.Rick Astley - Unwanted (Official Song from the Podcast) (Lyric Video).webm
That is a lot of Rick Astley! And that is just a single playlist, imagine if we downloaded his entire channel.
<<-- Part III: Creating Your First Config -- Previous -- | -- Next -- Part V: Optimizing Your First Config -->>