-
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