diff --git a/streamrip/bases.py b/streamrip/bases.py index b7d0f3a..f532985 100644 --- a/streamrip/bases.py +++ b/streamrip/bases.py @@ -1,4 +1,6 @@ -"""These are the lower level classes that are handled by Album, Playlist, +"""Bases that handle parsing and downloading media. + +These are the lower level classes that are handled by Album, Playlist, and the other objects. They can also be downloaded individually, for example, as a single track. """ @@ -103,7 +105,6 @@ class Track: def load_meta(self): """Send a request to the client to get metadata for this Track.""" - assert self.id is not None, "id must be set before loading metadata" self.resp = self.client.get(self.id, media_type="track") @@ -128,7 +129,8 @@ class Track: self.cover_url = None def _prepare_download(self, **kwargs): - """This function does preprocessing to prepare for downloading tracks. + """Do preprocessing before downloading items. + It creates the directories, downloads cover art, and (optionally) downloads booklets. @@ -269,7 +271,7 @@ class Track: ) def move(self, path: str): - """Moves the Track and sets self.path to the new path. + """Move the Track and set self.path to the new path. :param path: :type path: str @@ -279,8 +281,10 @@ class Track: self.path = path def _soundcloud_download(self, dl_info: dict): - """Downloads a soundcloud track. This requires a seperate function - because there are three methods that can be used to download a track: + """Download a soundcloud track. + + This requires a seperate function because there are three methods that + can be used to download a track: * original file downloads * direct mp3 downloads * hls stream ripping @@ -319,15 +323,14 @@ class Track: @property def _progress_desc(self) -> str: - """The description that is used on the progress bar. + """Get the description that is used on the progress bar. :rtype: str """ return click.style(f"Track {int(self.meta.tracknumber):02}", fg="blue") def download_cover(self): - """Downloads the cover art, if cover_url is given.""" - + """Download the cover art, if cover_url is given.""" if not hasattr(self, "cover_url"): return False @@ -362,8 +365,7 @@ class Track: @classmethod def from_album_meta(cls, album: TrackMetadata, track: dict, client: Client): - """Return a new Track object initialized with info from the album dicts - returned by client.get calls. + """Return a new Track object initialized with info. :param album: album metadata returned by API :param pos: index of the track @@ -371,14 +373,12 @@ class Track: :type client: Client :raises IndexError """ - meta = TrackMetadata(album=album, track=track, source=client.source) return cls(client=client, meta=meta, id=track["id"]) @classmethod def from_api(cls, item: dict, client: Client): - """Given a track dict from an API, return a new Track object - initialized with the proper values. + """Return a new Track initialized from search result. :param item: :type item: dict @@ -501,7 +501,7 @@ class Track: self.tagged = True def convert(self, codec: str = "ALAC", **kwargs): - """Converts the track to another codec. + """Convert the track to another codec. Valid values for codec: * FLAC @@ -565,7 +565,7 @@ class Track: @property def title(self) -> str: - """The title of the track. + """Get the title of the track. :rtype: str """ @@ -586,8 +586,9 @@ class Track: return safe_get(self.meta, *keys, default=default) def set(self, key, val): - """Equivalent to __setitem__. Implemented only for - consistency. + """Set attribute `key` to `val`. + + Equivalent to __setitem__. Implemented only for consistency. :param key: :param val: @@ -617,8 +618,7 @@ class Track: return f"" def __str__(self) -> str: - """Return a readable string representation of - this track. + """Return a readable string representation of this track. :rtype: str """ @@ -629,6 +629,14 @@ class Video: """Only for Tidal.""" def __init__(self, client: Client, id: str, **kwargs): + """Initialize a Video object. + + :param client: + :type client: Client + :param id: The TIDAL Video ID + :type id: str + :param kwargs: title, explicit, and tracknumber + """ self.id = id self.client = client self.title = kwargs.get("title", "MusicVideo") @@ -660,7 +668,9 @@ class Video: return False # so that it is not tagged def tag(self, *args, **kwargs): - """Dummy method. + """Return False. + + This is a dummy method. :param args: :param kwargs: @@ -669,10 +679,9 @@ class Video: @classmethod def from_album_meta(cls, track: dict, client: Client): - """Given an video response dict from an album, return a new - Video object from the information. + """Return a new Video object given an album API response. - :param track: + :param track: track dict from album :type track: dict :param client: :type client: Client @@ -687,7 +696,7 @@ class Video: @property def path(self) -> str: - """The path to download the mp4 file. + """Get path to download the mp4 file. :rtype: str """ @@ -701,9 +710,17 @@ class Video: return os.path.join(self.parent_folder, f"{fname}.mp4") def __str__(self) -> str: + """Return the title. + + :rtype: str + """ return self.title def __repr__(self) -> str: + """Return a string representation of self. + + :rtype: str + """ return f"