sanitized vars created

This commit is contained in:
jbannon 2022-07-17 06:29:14 +00:00
parent 142d87d14e
commit d9b33b2052
4 changed files with 42 additions and 2 deletions

View file

@ -2,6 +2,8 @@ from typing import Dict
from typing import List
from typing import Optional
from yt_dlp.utils import sanitize_filename
from ytdl_sub.entries.entry import Entry
from ytdl_sub.plugins.plugin import Plugin
from ytdl_sub.plugins.plugin import PluginOptions
@ -119,6 +121,7 @@ class RegexOptions(PluginOptions):
# Perform this regex match on it to act as a filter.
# This will only download videos with "Official Video" in it.
match: '\[Official Video\]'
# For each entry's `description` value...
description:
# Match with capture groups and defaults.
@ -126,7 +129,7 @@ class RegexOptions(PluginOptions):
match: "([0-9]{4})-([0-9]{2})-([0-9]{2})"
# Each capture group creates these new source variables, respectively, as well
# a sanitized version, i.e. `sanitized_captured_upload_year`
# a sanitized version, i.e. `captured_upload_year_sanitized`
capture_group_names:
- "captured_upload_year"
- "captured_upload_month"
@ -209,6 +212,10 @@ class RegexOptions(PluginOptions):
added_source_vars: List[str] = []
for regex_options in self.source_variable_capture_dict.values():
added_source_vars.extend(regex_options.capture_group_names)
added_source_vars.extend(
f"{capture_group_name}_sanitized"
for capture_group_name in regex_options.capture_group_names
)
return added_source_vars
@ -260,6 +267,8 @@ class RegexPlugin(Plugin[RegexOptions]):
source_variables_and_overrides_dict = dict(
entry_variable_dict, **self.overrides.dict_with_format_strings
)
# add both the default...
entry.add_variables(
variables_to_add={
regex_options.capture_group_names[i]: default.apply_formatter(
@ -268,14 +277,35 @@ class RegexPlugin(Plugin[RegexOptions]):
for i, default in enumerate(regex_options.capture_group_defaults)
},
)
# and sanitized default
entry.add_variables(
variables_to_add={
f"{regex_options.capture_group_names[i]}_sanitized": sanitize_filename(
default.apply_formatter(
variable_dict=source_variables_and_overrides_dict
)
)
for i, default in enumerate(regex_options.capture_group_defaults)
},
)
# There is a capture, add the source variables to the entry as
# {source_var}_capture_1, {source_var}_capture_2, ...
else:
# Add the value...
entry.add_variables(
variables_to_add={
regex_options.capture_group_names[i]: capture
for i, capture in enumerate(maybe_capture)
},
)
# And the sanitized value
entry.add_variables(
variables_to_add={
f"{regex_options.capture_group_names[i]}_sanitized": sanitize_filename(
capture
)
for i, capture in enumerate(maybe_capture)
},
)
return entry

View file

@ -56,16 +56,20 @@ def regex_subscription_dict(output_directory):
"nfo_tags": {
"tags": {
"title_cap_1": "{title_type}",
"title_cap_1_sanitized": "{title_type_sanitized}",
"title_cap_2": "{title_date}",
"desc_cap": "{description_website}",
"upload_date_both_caps": "{upload_captured_year} and {upload_captured_month}",
"artist_cap_always_default": "{always_default}",
"artist_cap_always_default_sanitized": "{always_default_sanitized}",
"override_with_capture_variable": "{contains_regex_default}",
"override_with_capture_variable_sanitized": "{contains_regex_sanitized_default}",
}
},
"overrides": {
"in_regex_default": "in regex default",
"contains_regex_default": "contains {title_type}",
"contains_regex_sanitized_default": "contains {title_type_sanitized}",
},
}

View file

@ -9,10 +9,13 @@ Project Zombie - Jesse's Minecraft Server [Trailer - Feb.1].nfo
album: Music Videos
artist: Project Zombie
artist_cap_always_default: Always default
artist_cap_always_default_sanitized: Always default
desc_cap: www.jesseminecraft.webs
override_with_capture_variable: contains Trailer
override_with_capture_variable_sanitized: contains Trailer
title: Jesse's Minecraft Server [Trailer - Feb.1]
title_cap_1: Trailer
title_cap_1_sanitized: Trailer
title_cap_2: Feb.1
upload_date_both_caps: First and Second containing in regex default
year: 2011
@ -24,10 +27,13 @@ Project Zombie - Jesse's Minecraft Server [Trailer - Feb.27].nfo
album: Music Videos
artist: Project Zombie
artist_cap_always_default: Always default
artist_cap_always_default_sanitized: Always default
desc_cap: jesseminecraft.webs
override_with_capture_variable: contains Trailer
override_with_capture_variable_sanitized: contains Trailer
title: Jesse's Minecraft Server [Trailer - Feb.27]
title_cap_1: Trailer
title_cap_1_sanitized: Trailer
title_cap_2: Feb.27
upload_date_both_caps: 2011 and 02
year: 2011

View file

@ -1,6 +1,6 @@
Files created in '{output_directory}'
----------------------------------------
.ytdl-sub-jmc-download-archive.json
.ytdl-sub-music_video_playlist_test-download-archive.json
JMC - Jesse's Minecraft Server [Trailer - Feb.1]-thumb.jpg
JMC - Jesse's Minecraft Server [Trailer - Feb.1].mp4
JMC - Jesse's Minecraft Server [Trailer - Feb.1].nfo