-
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:
youtube:
download_strategy: "video"
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:
youtube:
download_strategy: "video"
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"
youtube:
download_strategy: "playlist"
yt_channel:
preset: "yt_playlist"
youtube:
download_strategy: "channel"
Our config now has the following inheritance hierarchy:
yt_channel <--inherits-- yt_playlist <--inherits-- yt_video
Each new preset overrides its parent's youtube.download_strategy
field with its own.
Here is our original subscription.yaml
file:
rick_a:
preset: "yt_video"
youtube:
video_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}
.
However, I want to 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"
youtube:
video_url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
overrides:
video_type: "Music Videos"
If we dry run again, we will see:
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
Great! 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"
youtube:
playlist_url: "https://www.youtube.com/playlist?list=PLlaN88a7y2_plecYoJxvRFTLHVbIVAOoc"
overrides:
video_type: "Music Videos"