soundlcoud working, refactor album track
This commit is contained in:
parent
0580745176
commit
af2d091d50
3 changed files with 53 additions and 14 deletions
|
|
@ -9,6 +9,11 @@ def uid():
|
|||
return "abc123"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def extractor():
|
||||
return "xtract"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def title():
|
||||
return "entry title"
|
||||
|
|
@ -45,7 +50,9 @@ def download_file_name(uid, ext):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_entry_to_dict(uid, title, ext, upload_date, upload_year, thumbnail, thumbnail_ext):
|
||||
def mock_entry_to_dict(
|
||||
uid, title, ext, upload_date, upload_year, thumbnail, thumbnail_ext, extractor
|
||||
):
|
||||
return {
|
||||
"uid": uid,
|
||||
"title": title,
|
||||
|
|
@ -55,6 +62,7 @@ def mock_entry_to_dict(uid, title, ext, upload_date, upload_year, thumbnail, thu
|
|||
"upload_year": upload_year,
|
||||
"thumbnail": thumbnail,
|
||||
"thumbnail_ext": thumbnail_ext,
|
||||
"extractor": extractor,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -62,6 +70,7 @@ def mock_entry_to_dict(uid, title, ext, upload_date, upload_year, thumbnail, thu
|
|||
def mock_entry_kwargs(uid, title, ext, upload_date, thumbnail):
|
||||
return {
|
||||
"id": uid,
|
||||
"extractor": extractor,
|
||||
"title": title,
|
||||
"ext": ext,
|
||||
"upload_date": upload_date,
|
||||
|
|
|
|||
|
|
@ -35,9 +35,21 @@ class BaseEntry(ABC):
|
|||
|
||||
@property
|
||||
def extractor(self) -> str:
|
||||
"""Get the ytdl extrator name"""
|
||||
"""
|
||||
:return: The ytdl extrator name
|
||||
"""
|
||||
return self.kwargs("extractor")
|
||||
|
||||
@property
|
||||
def order_index(self) -> int:
|
||||
"""
|
||||
Reserved for any child entry class that might have some kind of ordering to it.
|
||||
Returns 1 unless overwritten.
|
||||
|
||||
:return: The order index (1-based)
|
||||
"""
|
||||
return 1
|
||||
|
||||
def to_dict(self) -> Dict[str, str]:
|
||||
"""Returns the entry's values as a dictionary"""
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -65,20 +65,24 @@ class SoundcloudAlbumTrack(SoundcloudTrack):
|
|||
Entry object to represent a Soundcloud track yt-dlp that belongs to an album.
|
||||
"""
|
||||
|
||||
def __init__(self, album: str, track_number: int, album_year: int, **kwargs):
|
||||
def __init__(self, album: str, album_year: int, track_number: int, **kwargs):
|
||||
"""
|
||||
Initialize the album track using album metadata and ytdl metadata for the specific track.
|
||||
"""
|
||||
super().__init__(**kwargs)
|
||||
self._album = album
|
||||
self._track_number = track_number
|
||||
self._album_year = album_year
|
||||
self._track_number = track_number
|
||||
|
||||
@property
|
||||
def track_number(self) -> int:
|
||||
"""Returns the entry's track number"""
|
||||
return self._track_number
|
||||
|
||||
@property
|
||||
def order_index(self) -> int:
|
||||
return self._track_number
|
||||
|
||||
@property
|
||||
def album(self) -> str:
|
||||
"""Returns the entry's album name, fetched from its internal album"""
|
||||
|
|
@ -89,6 +93,17 @@ class SoundcloudAlbumTrack(SoundcloudTrack):
|
|||
"""Returns the entry's album year, fetched from its internal album"""
|
||||
return self._album_year
|
||||
|
||||
@classmethod
|
||||
def from_soundcloud_entry(
|
||||
cls, soundcloud_track: SoundcloudTrack, album: str, album_year: int, track_number: int
|
||||
) -> "SoundcloudAlbumTrack":
|
||||
return SoundcloudAlbumTrack(
|
||||
album=album,
|
||||
album_year=album_year,
|
||||
track_number=track_number,
|
||||
**soundcloud_track._kwargs,
|
||||
)
|
||||
|
||||
|
||||
class SoundcloudAlbum(Entry):
|
||||
"""
|
||||
|
|
@ -108,17 +123,20 @@ class SoundcloudAlbum(Entry):
|
|||
Returns all tracks in the album represented as album-tracks. They will share the
|
||||
same album name, have ordered track numbers, and a shared album year.
|
||||
"""
|
||||
album_tracks = [
|
||||
SoundcloudAlbumTrack(
|
||||
album=self.title,
|
||||
track_number=i + 1,
|
||||
album_year=self.album_year,
|
||||
**entry,
|
||||
)
|
||||
for i, entry in enumerate(self.kwargs("entries"))
|
||||
]
|
||||
tracks = [SoundcloudTrack(**entry) for entry in self.kwargs("entries")]
|
||||
|
||||
if skip_premiere_tracks:
|
||||
album_tracks = [t for t in album_tracks if not t.is_premiere]
|
||||
tracks = [track for track in tracks if not track.is_premiere]
|
||||
|
||||
album_tracks = [
|
||||
SoundcloudAlbumTrack.from_soundcloud_entry(
|
||||
soundcloud_track=track,
|
||||
album=self.title,
|
||||
album_year=self.album_year,
|
||||
track_number=i + 1,
|
||||
)
|
||||
for i, track in enumerate(tracks)
|
||||
]
|
||||
|
||||
return album_tracks
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue