almost there

This commit is contained in:
Jesse Bannon 2023-12-11 18:57:17 -08:00
parent 95948bce9e
commit 40309ed358
3 changed files with 22 additions and 8 deletions

View file

@ -448,7 +448,17 @@ class _Variables:
)
@property
def playlist_max_upload_year(self) -> MetadataVariable:
def playlist_max_upload_date(self) -> Variable:
"""
Returns
-------
Max upload_date for all entries in this entry's playlist if it exists, otherwise returns
``upload_date``
"""
return Variable("playlist_max_upload_date")
@property
def playlist_max_upload_year(self) -> Variable:
"""
Returns
-------
@ -457,9 +467,7 @@ class _Variables:
``upload_year``
"""
# override in EntryParent
return MetadataVariable(
variable_name="playlist_max_upload_year", metadata_key="playlist_max_upload_year"
)
return Variable("playlist_max_upload_year")
@property
def playlist_max_upload_year_truncated(self) -> Variable:

View file

@ -248,11 +248,11 @@ SOURCE_DERIVED_VARIABLES: Dict[Variable, str] = {
}
SIBLING_VARIABLES: Dict[Variable, str] = {
v.playlist_max_upload_year: f"""{{
v.playlist_max_upload_date: f"""{{
%array_reduce(
%if_passthrough(
%extract_field_from_siblings('{v.upload_year.variable_name}'),
[{v.upload_year.variable_name}]
%extract_field_from_siblings('{v.upload_date.variable_name}'),
[{v.upload_date.variable_name}]
),
%max
)
@ -260,7 +260,10 @@ SIBLING_VARIABLES: Dict[Variable, str] = {
}
SIBLING_DERIVED_VARIABLES: Dict[Variable, str] = {
v.playlist_max_upload_year_truncated: f"{{%int(%slice(%string({v.playlist_max_upload_year.variable_name}), 2))}}",
v.playlist_max_upload_year: date_metadata(v.playlist_max_upload_date, "year"),
v.playlist_max_upload_year_truncated: date_metadata(
v.playlist_max_upload_date, "year_truncated"
),
}
_VARIABLE_SCRIPTS: Dict[Variable, str] = {}

View file

@ -7,11 +7,14 @@ from ytdl_sub.entries.script.variable_definitions import VARIABLES as v
class TestEntry(object):
def test_entry_to_dict(self, mock_entry, mock_entry_to_dict):
out = mock_entry.to_dict()
# Delete non-legacy variables to reuse old to_dict comparision
del out[v.entry_metadata.variable_name]
del out[v.ytdl_sub_input_url.variable_name]
del out[v.playlist_metadata.variable_name]
del out[v.source_metadata.variable_name]
del out[v.sibling_metadata.variable_name]
del out[v.playlist_max_upload_date.variable_name]
assert out == mock_entry_to_dict
def test_entry_missing_kwarg(self, mock_entry):