lint
This commit is contained in:
parent
3a5c6c80dc
commit
43cc4cd4c7
3 changed files with 32 additions and 11 deletions
|
|
@ -9,8 +9,8 @@ import yt_dlp as ytdl
|
||||||
|
|
||||||
class Downloader:
|
class Downloader:
|
||||||
"""
|
"""
|
||||||
Class that interacts with ytdl to perform the download of metadata and content, and should translate that to
|
Class that interacts with ytdl to perform the download of metadata and content,
|
||||||
list of Entry objects.
|
and should translate that to list of Entry objects.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -29,7 +29,7 @@ class Downloader:
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
"""Configure the ytdl options for the downloader"""
|
"""Configure the ytdl options for the downloader"""
|
||||||
if ytdl_options is None:
|
if ytdl_options is None:
|
||||||
ytdl_options = dict()
|
ytdl_options = {}
|
||||||
|
|
||||||
# Overwrite defaults with input
|
# Overwrite defaults with input
|
||||||
ytdl_options = dict(cls.ytdl_option_defaults(), **ytdl_options)
|
ytdl_options = dict(cls.ytdl_option_defaults(), **ytdl_options)
|
||||||
|
|
|
||||||
|
|
@ -7,23 +7,36 @@ from ytdl_subscribe.entries.soundcloud import SoundcloudTrack
|
||||||
|
|
||||||
|
|
||||||
class SoundcloudDownloader(Downloader):
|
class SoundcloudDownloader(Downloader):
|
||||||
|
"""
|
||||||
|
Class that handles downloading soundcloud entries via ytdl and converting them into
|
||||||
|
SoundcloudTrack / SoundcloudAlbumTrack objects
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def ytdl_option_defaults(cls) -> Dict:
|
def ytdl_option_defaults(cls) -> Dict:
|
||||||
|
"""Returns default format to be best mp3"""
|
||||||
return {
|
return {
|
||||||
"format": "bestaudio[ext=mp3]",
|
"format": "bestaudio[ext=mp3]",
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def artist_url(cls, artist_name: str) -> str:
|
def artist_url(cls, artist_name: str) -> str:
|
||||||
|
"""Returns full artist url"""
|
||||||
return f"https://soundcloud.com/{artist_name}"
|
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"
|
artist_albums_url = f"{self.artist_url(artist_name)}/albums"
|
||||||
|
|
||||||
info = self.extract_info(url=artist_albums_url)
|
info = self.extract_info(url=artist_albums_url)
|
||||||
return [SoundcloudAlbum(**e) for e in info["entries"]]
|
return [SoundcloudAlbum(**e) for e in info["entries"]]
|
||||||
|
|
||||||
def download_tracks(self, artist_name) -> List[SoundcloudTrack]:
|
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"
|
artist_tracks_url = f"{self.artist_url(artist_name)}/tracks"
|
||||||
|
|
||||||
info = self.extract_info(url=artist_tracks_url)
|
info = self.extract_info(url=artist_tracks_url)
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,21 @@ from ytdl_subscribe.entries.youtube import YoutubeVideo
|
||||||
|
|
||||||
|
|
||||||
class YoutubeDownloader(Downloader):
|
class YoutubeDownloader(Downloader):
|
||||||
|
"""
|
||||||
|
Class that handles downloading youtube entries via ytdl and converting them into
|
||||||
|
YoutubeVideo objects
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def playlist_url(cls, playlist_id: str) -> str:
|
def playlist_url(cls, playlist_id: str) -> str:
|
||||||
|
"""Returns full playlist url"""
|
||||||
return f"https://youtube.com/playlist?list={playlist_id}"
|
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.
|
Do not get entries from the extract info, let it write to the info.json file and load
|
||||||
This is because if the video is already downloaded in a playlist, it will not fetch the metadata
|
that instead. This is because if the video is already downloaded in a playlist, it will
|
||||||
(maybe there is a way??)
|
not fetch the metadata (maybe there is a way??)
|
||||||
"""
|
"""
|
||||||
ytdl_metadata_override = {
|
ytdl_metadata_override = {
|
||||||
"download_archive": str(
|
"download_archive": str(
|
||||||
|
|
@ -32,7 +38,7 @@ class YoutubeDownloader(Downloader):
|
||||||
"""
|
"""
|
||||||
playlist_url = self.playlist_url(playlist_id=playlist_id)
|
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
|
# Load the entries from info.json, ignore the playlist entry
|
||||||
entries: List[YoutubeVideo] = []
|
entries: List[YoutubeVideo] = []
|
||||||
|
|
@ -42,7 +48,9 @@ class YoutubeDownloader(Downloader):
|
||||||
if file_name.endswith(".info.json") and not file_name.startswith(
|
if file_name.endswith(".info.json") and not file_name.startswith(
|
||||||
playlist_id
|
playlist_id
|
||||||
):
|
):
|
||||||
with open(Path(self.working_directory) / file_name, "r") as f:
|
with open(
|
||||||
entries.append(YoutubeVideo(**json.load(f)))
|
Path(self.working_directory) / file_name, "r", encoding="utf-8"
|
||||||
|
) as file:
|
||||||
|
entries.append(YoutubeVideo(**json.load(file)))
|
||||||
|
|
||||||
return entries
|
return entries
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue