broken unit tests, start to separate entry from base entry
This commit is contained in:
parent
18b932925d
commit
0580745176
2 changed files with 55 additions and 42 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
from abc import ABC
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
@ -9,11 +10,8 @@ from ytdl_subscribe.validators.base.string_formatter_validators import StringFor
|
||||||
from ytdl_subscribe.validators.config.overrides.overrides_validator import OverridesValidator
|
from ytdl_subscribe.validators.config.overrides.overrides_validator import OverridesValidator
|
||||||
|
|
||||||
|
|
||||||
class Entry:
|
# TODO: strip things out of entry into BaseEntry
|
||||||
"""
|
class BaseEntry(ABC):
|
||||||
Entry object to represent a single media object returned from yt-dlp.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Initialize the entry using ytdl metadata
|
Initialize the entry using ytdl metadata
|
||||||
|
|
@ -35,6 +33,39 @@ class Entry:
|
||||||
"""Returns the entry's unique id"""
|
"""Returns the entry's unique id"""
|
||||||
return self.kwargs("id")
|
return self.kwargs("id")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def extractor(self) -> str:
|
||||||
|
"""Get the ytdl extrator name"""
|
||||||
|
return self.kwargs("extractor")
|
||||||
|
|
||||||
|
def to_dict(self) -> Dict[str, str]:
|
||||||
|
"""Returns the entry's values as a dictionary"""
|
||||||
|
return {
|
||||||
|
"uid": self.uid,
|
||||||
|
"extractor": self.extractor,
|
||||||
|
}
|
||||||
|
|
||||||
|
def apply_formatter(
|
||||||
|
self,
|
||||||
|
formatter: StringFormatterValidator,
|
||||||
|
overrides: Optional[OverridesValidator] = None,
|
||||||
|
) -> str:
|
||||||
|
"""
|
||||||
|
Perform a string format on the given format string, using the entry's dict for format
|
||||||
|
values. The override dict will overwrite any values within the entry's dict.
|
||||||
|
"""
|
||||||
|
entry_dict = self.to_dict()
|
||||||
|
if overrides:
|
||||||
|
entry_dict = dict(entry_dict, **overrides.dict_with_format_strings)
|
||||||
|
|
||||||
|
return formatter.apply_formatter(variable_dict=entry_dict)
|
||||||
|
|
||||||
|
|
||||||
|
class Entry(BaseEntry):
|
||||||
|
"""
|
||||||
|
Entry object to represent a single media object returned from yt-dlp.
|
||||||
|
"""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title(self) -> str:
|
def title(self) -> str:
|
||||||
"""Returns the entry's title"""
|
"""Returns the entry's title"""
|
||||||
|
|
@ -45,11 +76,6 @@ class Entry:
|
||||||
"""Returns the entry's sanitized title"""
|
"""Returns the entry's sanitized title"""
|
||||||
return sanitize(self.title)
|
return sanitize(self.title)
|
||||||
|
|
||||||
@property
|
|
||||||
def extractor(self) -> str:
|
|
||||||
"""Get the ytdl extrator name"""
|
|
||||||
return self.kwargs("extractor")
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ext(self) -> str:
|
def ext(self) -> str:
|
||||||
"""Returns the entry's file extension"""
|
"""Returns the entry's file extension"""
|
||||||
|
|
@ -126,34 +152,21 @@ class Entry:
|
||||||
|
|
||||||
def to_dict(self) -> Dict:
|
def to_dict(self) -> Dict:
|
||||||
"""Returns the entry's values as a dictionary"""
|
"""Returns the entry's values as a dictionary"""
|
||||||
return {
|
return dict(
|
||||||
"uid": self.uid,
|
super().to_dict(),
|
||||||
"title": self.title,
|
**{
|
||||||
"sanitized_title": self.sanitized_title,
|
"title": self.title,
|
||||||
"description": self.description,
|
"sanitized_title": self.sanitized_title,
|
||||||
"ext": self.ext,
|
"description": self.description,
|
||||||
"upload_date": self.upload_date,
|
"ext": self.ext,
|
||||||
"upload_year": self.upload_year,
|
"upload_date": self.upload_date,
|
||||||
"upload_month": self.upload_month,
|
"upload_year": self.upload_year,
|
||||||
"upload_month_padded": self.upload_month_padded,
|
"upload_month": self.upload_month,
|
||||||
"upload_day": self.upload_day,
|
"upload_month_padded": self.upload_month_padded,
|
||||||
"upload_day_padded": self.upload_day_padded,
|
"upload_day": self.upload_day,
|
||||||
"standardized_upload_date": self.standardized_upload_date,
|
"upload_day_padded": self.upload_day_padded,
|
||||||
"thumbnail": self.thumbnail,
|
"standardized_upload_date": self.standardized_upload_date,
|
||||||
"thumbnail_ext": self.thumbnail_ext,
|
"thumbnail": self.thumbnail,
|
||||||
}
|
"thumbnail_ext": self.thumbnail_ext,
|
||||||
|
},
|
||||||
def apply_formatter(
|
)
|
||||||
self,
|
|
||||||
formatter: StringFormatterValidator,
|
|
||||||
overrides: Optional[OverridesValidator] = None,
|
|
||||||
) -> str:
|
|
||||||
"""
|
|
||||||
Perform a string format on the given format string, using the entry's dict for format
|
|
||||||
values. The override dict will overwrite any values within the entry's dict.
|
|
||||||
"""
|
|
||||||
entry_dict = self.to_dict()
|
|
||||||
if overrides:
|
|
||||||
entry_dict = dict(entry_dict, **overrides.dict_with_format_strings)
|
|
||||||
|
|
||||||
return formatter.apply_formatter(variable_dict=entry_dict)
|
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ class SoundcloudAlbum(Entry):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def track_count(self) -> int:
|
def track_count(self) -> int:
|
||||||
return self.kwargs('playlist_count')
|
return self.kwargs("playlist_count")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def downloaded_track_count(self) -> int:
|
def downloaded_track_count(self) -> int:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue