From 43cc4cd4c7f67bdf1a150f324544bb6f96c481d7 Mon Sep 17 00:00:00 2001 From: jbannon Date: Wed, 30 Mar 2022 22:14:21 +0000 Subject: [PATCH] lint --- ytdl_subscribe/downloaders/downloader.py | 6 ++--- .../downloaders/soundcloud_downloader.py | 15 ++++++++++++- .../downloaders/youtube_downloader.py | 22 +++++++++++++------ 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/ytdl_subscribe/downloaders/downloader.py b/ytdl_subscribe/downloaders/downloader.py index 3f4bc280..15ffd70e 100644 --- a/ytdl_subscribe/downloaders/downloader.py +++ b/ytdl_subscribe/downloaders/downloader.py @@ -9,8 +9,8 @@ import yt_dlp as ytdl class Downloader: """ - Class that interacts with ytdl to perform the download of metadata and content, and should translate that to - list of Entry objects. + Class that interacts with ytdl to perform the download of metadata and content, + and should translate that to list of Entry objects. """ @classmethod @@ -29,7 +29,7 @@ class Downloader: ) -> Dict: """Configure the ytdl options for the downloader""" if ytdl_options is None: - ytdl_options = dict() + ytdl_options = {} # Overwrite defaults with input ytdl_options = dict(cls.ytdl_option_defaults(), **ytdl_options) diff --git a/ytdl_subscribe/downloaders/soundcloud_downloader.py b/ytdl_subscribe/downloaders/soundcloud_downloader.py index 18d64d60..dbba1da3 100644 --- a/ytdl_subscribe/downloaders/soundcloud_downloader.py +++ b/ytdl_subscribe/downloaders/soundcloud_downloader.py @@ -7,23 +7,36 @@ from ytdl_subscribe.entries.soundcloud import SoundcloudTrack class SoundcloudDownloader(Downloader): + """ + Class that handles downloading soundcloud entries via ytdl and converting them into + SoundcloudTrack / SoundcloudAlbumTrack objects + """ + @classmethod def ytdl_option_defaults(cls) -> Dict: + """Returns default format to be best mp3""" return { "format": "bestaudio[ext=mp3]", } @classmethod def artist_url(cls, artist_name: str) -> str: + """Returns full artist url""" return f"https://soundcloud.com/{artist_name}" - def download_albums(self, artist_name) -> List[SoundcloudAlbum]: + def download_albums(self, artist_name: str) -> List[SoundcloudAlbum]: + """ + Given an artist name, download all of their albums + """ artist_albums_url = f"{self.artist_url(artist_name)}/albums" info = self.extract_info(url=artist_albums_url) return [SoundcloudAlbum(**e) for e in info["entries"]] def download_tracks(self, artist_name) -> List[SoundcloudTrack]: + """ + Given an artist name, download all of their tracks + """ artist_tracks_url = f"{self.artist_url(artist_name)}/tracks" info = self.extract_info(url=artist_tracks_url) diff --git a/ytdl_subscribe/downloaders/youtube_downloader.py b/ytdl_subscribe/downloaders/youtube_downloader.py index d93ea4b8..2784a3b1 100644 --- a/ytdl_subscribe/downloaders/youtube_downloader.py +++ b/ytdl_subscribe/downloaders/youtube_downloader.py @@ -8,15 +8,21 @@ from ytdl_subscribe.entries.youtube import YoutubeVideo class YoutubeDownloader(Downloader): + """ + Class that handles downloading youtube entries via ytdl and converting them into + YoutubeVideo objects + """ + @classmethod def playlist_url(cls, playlist_id: str) -> str: + """Returns full playlist url""" return f"https://youtube.com/playlist?list={playlist_id}" - def _download_metadata(self, url: str) -> None: + def _download_with_metadata(self, url: str) -> None: """ - Do not get entries from the extract info, let it write to the info.json file and load that instead. - This is because if the video is already downloaded in a playlist, it will not fetch the metadata - (maybe there is a way??) + Do not get entries from the extract info, let it write to the info.json file and load + that instead. This is because if the video is already downloaded in a playlist, it will + not fetch the metadata (maybe there is a way??) """ ytdl_metadata_override = { "download_archive": str( @@ -32,7 +38,7 @@ class YoutubeDownloader(Downloader): """ playlist_url = self.playlist_url(playlist_id=playlist_id) - self._download_metadata(url=playlist_url) + self._download_with_metadata(url=playlist_url) # Load the entries from info.json, ignore the playlist entry entries: List[YoutubeVideo] = [] @@ -42,7 +48,9 @@ class YoutubeDownloader(Downloader): if file_name.endswith(".info.json") and not file_name.startswith( playlist_id ): - with open(Path(self.working_directory) / file_name, "r") as f: - entries.append(YoutubeVideo(**json.load(f))) + with open( + Path(self.working_directory) / file_name, "r", encoding="utf-8" + ) as file: + entries.append(YoutubeVideo(**json.load(file))) return entries