bandcamp working

This commit is contained in:
Jesse Bannon 2023-12-12 11:30:59 -08:00
parent 2f1bd49922
commit 96cbb45dde
4 changed files with 25 additions and 28 deletions

View file

@ -323,7 +323,7 @@ class _Variables:
str str
The playlist unique ID if it exists, otherwise return Variable("") The playlist unique ID if it exists, otherwise return Variable("")
""" """
return MetadataVariable(variable_name="playlist_uid", metadata_key=self.uid.metadata_key) return MetadataVariable(variable_name="playlist_uid", metadata_key="playlist_id")
@property @property
def playlist_title(self) -> MetadataVariable: def playlist_title(self) -> MetadataVariable:
@ -333,9 +333,7 @@ class _Variables:
str str
Name of its parent playlist/channel if it exists, otherwise returns its title. Name of its parent playlist/channel if it exists, otherwise returns its title.
""" """
return MetadataVariable( return MetadataVariable(variable_name="playlist_title", metadata_key="playlist_title")
variable_name="playlist_title", metadata_key=self.title.metadata_key
)
@property @property
def playlist_title_sanitized(self) -> Variable: def playlist_title_sanitized(self) -> Variable:
@ -488,7 +486,7 @@ class _Variables:
str str
The playlist uploader id if it exists, otherwise returns the entry uploader ID. The playlist uploader id if it exists, otherwise returns the entry uploader ID.
""" """
return MetadataVariable("playlist_uploader_id", metadata_key=self.uploader_id.metadata_key) return MetadataVariable("playlist_uploader_id", metadata_key="playlist_uploader_id")
@property @property
def playlist_uploader(self) -> MetadataVariable: def playlist_uploader(self) -> MetadataVariable:

View file

@ -127,7 +127,6 @@ ENTRY_REQUIRED_VARIABLES: Dict[MetadataVariable, str] = {
} }
ENTRY_DEFAULT_VARIABLES: Dict[MetadataVariable, str] = { ENTRY_DEFAULT_VARIABLES: Dict[MetadataVariable, str] = {
v.playlist_index: playlist_get_int(v.playlist_index, 1),
v.title: entry_get_str(v.title, v.uid), v.title: entry_get_str(v.title, v.uid),
v.extractor: entry_get_str(v.extractor, v.extractor_key), v.extractor: entry_get_str(v.extractor, v.extractor_key),
v.description: entry_get_str(v.description, ""), v.description: entry_get_str(v.description, ""),
@ -139,6 +138,11 @@ ENTRY_DEFAULT_VARIABLES: Dict[MetadataVariable, str] = {
v.channel: entry_get_str(v.channel, v.uploader), v.channel: entry_get_str(v.channel, v.uploader),
v.creator: entry_get_str(v.creator, v.channel), v.creator: entry_get_str(v.creator, v.channel),
v.channel_id: entry_get_str(v.channel_id, v.uploader_id), v.channel_id: entry_get_str(v.channel_id, v.uploader_id),
v.playlist_index: entry_get_int(v.playlist_index, 1),
v.playlist_count: entry_get_int(v.playlist_count, 1),
v.playlist_uid: entry_get_str(v.playlist_uid, v.uid),
v.playlist_title: entry_get_str(v.playlist_title, v.title),
v.playlist_uploader_id: entry_get_str(v.playlist_uploader_id, v.uploader_id),
} }
# MARK AS UNRESOLVABLE UNTIL THEY ARE ADDED # MARK AS UNRESOLVABLE UNTIL THEY ARE ADDED
@ -164,6 +168,12 @@ ENTRY_DERIVED_VARIABLES: Dict[Variable, str] = {
v.upload_date_index_padded: pad_int(v.upload_date_index, 2), v.upload_date_index_padded: pad_int(v.upload_date_index, 2),
v.upload_date_index_reversed: f"{{%sub(100, {v.upload_date_index.variable_name})}}", v.upload_date_index_reversed: f"{{%sub(100, {v.upload_date_index.variable_name})}}",
v.upload_date_index_reversed_padded: pad_int(v.upload_date_index_reversed, 2), v.upload_date_index_reversed_padded: pad_int(v.upload_date_index_reversed, 2),
v.playlist_title_sanitized: sanitized(v.playlist_title),
v.playlist_index_reversed: f"{{%sub({v.playlist_count.variable_name}, {v.playlist_index.variable_name}, -1)}}",
v.playlist_index_padded: pad_int(v.playlist_index, 2),
v.playlist_index_reversed_padded: pad_int(v.playlist_index_reversed, 2),
v.playlist_index_padded6: pad_int(v.playlist_index, 6),
v.playlist_index_reversed_padded6: pad_int(v.playlist_index_reversed, 6),
} }
ENTRY_UPLOAD_DATE_VARIABLES: Dict[Variable, str] = { ENTRY_UPLOAD_DATE_VARIABLES: Dict[Variable, str] = {
@ -209,23 +219,13 @@ ENTRY_RELEASE_DATE_VARIABLES: Dict[Variable, str] = {
} }
PLAYLIST_VARIABLES: Dict[Variable, str] = { PLAYLIST_VARIABLES: Dict[Variable, str] = {
v.playlist_uid: playlist_get_str(v.playlist_uid, v.uid),
v.playlist_title: playlist_get_str(v.playlist_title, v.title),
v.playlist_webpage_url: playlist_get_str(v.playlist_webpage_url, v.webpage_url), v.playlist_webpage_url: playlist_get_str(v.playlist_webpage_url, v.webpage_url),
v.playlist_count: playlist_get_int(v.playlist_count, 1),
v.playlist_description: playlist_get_str(v.playlist_description, v.description), v.playlist_description: playlist_get_str(v.playlist_description, v.description),
v.playlist_uploader_id: playlist_get_str(v.playlist_uploader_id, v.uploader_id),
v.playlist_uploader: playlist_get_str(v.playlist_uploader, v.uploader), v.playlist_uploader: playlist_get_str(v.playlist_uploader, v.uploader),
v.playlist_uploader_url: playlist_get_str(v.playlist_uploader_url, v.playlist_webpage_url), v.playlist_uploader_url: playlist_get_str(v.playlist_uploader_url, v.playlist_webpage_url),
} }
PLAYLIST_DERIVED_VARIABLES: Dict[Variable, str] = { PLAYLIST_DERIVED_VARIABLES: Dict[Variable, str] = {
v.playlist_title_sanitized: sanitized(v.playlist_title),
v.playlist_index_reversed: f"{{%sub({v.playlist_count.variable_name}, {v.playlist_index.variable_name}, -1)}}",
v.playlist_index_padded: pad_int(v.playlist_index, 2),
v.playlist_index_reversed_padded: pad_int(v.playlist_index_reversed, 2),
v.playlist_index_padded6: pad_int(v.playlist_index, 6),
v.playlist_index_reversed_padded6: pad_int(v.playlist_index_reversed, 6),
v.playlist_uploader_sanitized: sanitized(v.playlist_uploader), v.playlist_uploader_sanitized: sanitized(v.playlist_uploader),
} }

View file

@ -4,20 +4,15 @@ from typing import List
from typing import Optional from typing import Optional
from typing import Set from typing import Set
from yt_dlp.utils import sanitize_filename
from ytdl_sub.config.plugin import Plugin from ytdl_sub.config.plugin import Plugin
from ytdl_sub.config.plugin import PluginPriority from ytdl_sub.config.plugin import PluginPriority
from ytdl_sub.config.preset_options import OptionsDictValidator from ytdl_sub.config.preset_options import OptionsDictValidator
from ytdl_sub.config.preset_options import PluginOperation from ytdl_sub.config.preset_options import PluginOperation
from ytdl_sub.entries.entry import Entry from ytdl_sub.entries.entry import Entry
from ytdl_sub.entries.script.variable_scripts import VARIABLE_SCRIPTS
from ytdl_sub.entries.variables.kwargs import YTDL_SUB_REGEX_SOURCE_VARS from ytdl_sub.entries.variables.kwargs import YTDL_SUB_REGEX_SOURCE_VARS
from ytdl_sub.script.parser import parse from ytdl_sub.script.parser import parse
from ytdl_sub.script.script import Script
from ytdl_sub.script.utils.exceptions import ScriptVariableNotResolved from ytdl_sub.script.utils.exceptions import ScriptVariableNotResolved
from ytdl_sub.utils.exceptions import RegexNoMatchException from ytdl_sub.utils.exceptions import RegexNoMatchException
from ytdl_sub.utils.exceptions import StringFormattingVariableNotFoundException
from ytdl_sub.utils.logger import Logger from ytdl_sub.utils.logger import Logger
from ytdl_sub.validators.regex_validator import RegexListValidator from ytdl_sub.validators.regex_validator import RegexListValidator
from ytdl_sub.validators.source_variable_validator import SourceVariableNameListValidator from ytdl_sub.validators.source_variable_validator import SourceVariableNameListValidator
@ -358,10 +353,10 @@ class RegexPlugin(Plugin[RegexOptions]):
return self._try_skip_entry(entry=entry, variable_name=variable_name) return self._try_skip_entry(entry=entry, variable_name=variable_name)
# add both the default... # add both the default...
entry.add({ entry.add(
{
regex_options.capture_group_names[i]: self.overrides.apply_formatter( regex_options.capture_group_names[i]: self.overrides.apply_formatter(
formatter=default, formatter=default, entry=entry
entry=entry
) )
for i, default in enumerate(regex_options.capture_group_defaults) for i, default in enumerate(regex_options.capture_group_defaults)
} }
@ -369,10 +364,12 @@ class RegexPlugin(Plugin[RegexOptions]):
# There is a capture, add the source variables to the entry as # There is a capture, add the source variables to the entry as
# {source_var}_capture_1, {source_var}_capture_2, ... # {source_var}_capture_1, {source_var}_capture_2, ...
else: else:
entry.add({ entry.add(
{
regex_options.capture_group_names[i]: capture regex_options.capture_group_names[i]: capture
for i, capture in enumerate(maybe_capture) for i, capture in enumerate(maybe_capture)
}) }
)
return entry return entry

View file

@ -71,9 +71,11 @@ UNREACHABLE = _UnreachableSyntaxException(
class RuntimeException(ValueError, ABC): class RuntimeException(ValueError, ABC):
"""Exception thrown at runtime during resolution""" """Exception thrown at runtime during resolution"""
class ScriptVariableNotResolved(RuntimeException): class ScriptVariableNotResolved(RuntimeException):
"""Tried to get a variable's resolved value from a script, but has not resolved yet""" """Tried to get a variable's resolved value from a script, but has not resolved yet"""
class FunctionRuntimeException(RuntimeException): class FunctionRuntimeException(RuntimeException):
"""Exception thrown when a ytdl-sub function has an error occur at runtime""" """Exception thrown when a ytdl-sub function has an error occur at runtime"""