Changed Tracklist to abstract class

This commit is contained in:
nathannathant 2021-03-16 08:19:25 -07:00
parent a57c84e2fe
commit 376854809e
3 changed files with 17 additions and 23 deletions

View File

@ -34,6 +34,7 @@ TIDAL_Q_IDS = {
4: "LOW", # AAC
5: "HIGH", # AAC
6: "LOSSLESS", # Lossless, but it also could be MQA
7: "HI_RES",
}
TIDAL_MAX_Q = max(TIDAL_Q_IDS.keys())

View File

@ -59,7 +59,7 @@ class Converter:
self.ffmpeg_arg = ffmpeg_arg
self._is_command_valid()
logger.debug("Ffmpeg codec extra argument: %s", self.ffmpeg_arg)
logger.debug("FFmpeg codec extra argument: %s", self.ffmpeg_arg)
def convert(self, custom_fn: Optional[str] = None):
"""Convert the file.

View File

@ -4,6 +4,7 @@ import shutil
from pprint import pformat
from tempfile import gettempdir
from typing import Any, Optional, Union
from abc import ABC, abstractmethod
import requests
from mutagen.flac import FLAC, Picture
@ -48,11 +49,7 @@ class Track:
>>> t.tag()
"""
def __init__(
self,
client: ClientInterface,
**kwargs,
):
def __init__(self, client: ClientInterface, **kwargs):
"""Create a track object.
The only required parameter is client, but passing at an id is
@ -298,7 +295,7 @@ class Track:
return f"<Track - {self['title']}>"
class Tracklist(list):
class Tracklist(list, ABC):
"""A base class for tracklist-like objects.
Implements methods to give it dict-like behavior. If a Tracklist
@ -406,8 +403,13 @@ class Tracklist(list):
return cover_obj
@staticmethod
@abstractmethod
def _parse_get_resp(item, client):
raise NotImplementedError
pass
@abstractmethod
def download(self, **kwargs):
pass
class Album(Tracklist):
@ -632,31 +634,22 @@ class Playlist(Tracklist):
logger.debug(f"Loaded {len(self)} tracks from playlist {self.name}")
@classmethod
def from_api(cls, item: dict, client: ClientInterface, source: str = "qobuz"):
"""Create a Playlist object from the api response of Qobuz, Tidal,
or Deezer.
:param resp: response dict
:type resp: dict
:param source: in ('qobuz', 'deezer', 'tidal')
:type source: str
"""
if source in ("qobuz", "deezer"):
@staticmethod
def _parse_get_resp(item, client):
if client.source in ("qobuz", "deezer"):
info = {
"name": item.get("name"),
"id": item.get("id"),
}
elif source == "tidal":
elif client.source == "tidal":
info = {
"name": item.name,
"id": item.id,
}
else:
raise InvalidSourceError(source)
raise InvalidSourceError(client.source)
# equivalent to Playlist(client=client, **info)
return cls(client=client, **info)
return info
def __repr__(self) -> str:
"""Return a string representation of this Playlist object.