Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 38 additions & 29 deletions ytm/apis/YouTubeMusicDL/YouTubeMusicDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def _download \
thumbnail = None,
directory = None,
video = False,
**ydl_extra_opts
):
'''
'''
Expand Down Expand Up @@ -86,6 +87,7 @@ def _download \
'outtmpl': str(path_file),
'postprocessors': post_processors,
'format': format,
**ydl_extra_opts
}
)

Expand Down Expand Up @@ -118,29 +120,32 @@ def _download \
)
info.setdefault('track', any_title)

sanitized_name = info['title']
illegal_chars = ['\\', '/', ':', '*', '?', '<', '>', '|', '"']
for char in illegal_chars:
sanitized_name = sanitized_name.replace(char, '_')
file_path_src = self._get_file_path \
(
info,
file_name_format % \
{
'title': sanitized_name,
'ext': to_ext,
},
directory,
)

file_path_dst = file_path_src.parent.joinpath \
(
file_name_format % \
{
'title': sanitized_name,
'ext': to_ext,
}
)
if info['requested_downloads'][0]['filepath']:
file_path_dst = info['requested_downloads'][0]['filepath']
else:
sanitized_name = info['title']
illegal_chars = ['\\', '/', ':', '*', '?', '<', '>', '|', '"']
for char in illegal_chars:
sanitized_name = sanitized_name.replace(char, '_')
file_path_src = self._get_file_path \
(
info,
file_name_format % \
{
'title': sanitized_name,
'ext': to_ext,
},
directory,
)
print(file_path_src)
file_path_dst = file_path_src.parent.joinpath \
(
file_name_format % \
{
'title': sanitized_name,
'ext': to_ext,
}
)

if not thumbnail:
thumbnail = self._get_album_art(info['thumbnails'][0]['url'], crop=True)
Expand Down Expand Up @@ -243,30 +248,32 @@ def _get_album_art(self, url, crop=True):
return buffer.read()

class AbstractYouTubeMusicDL(object):
def __init__(self: object, api: object = None):
def __init__(self: object, api: object = None, youtube_downloader=None):
if api is None:
api = YouTubeMusic()

self._base = BaseYouTubeMusicDL()
self._base = BaseYouTubeMusicDL(youtube_downloader)
self._api = api

def download_song(self, song_id, directory=None):
def download_song(self, song_id, directory=None, **ydl_extra_opts):
return self._base._download \
(
song_id = song_id,
directory = directory,
video = False,
**ydl_extra_opts
)

def download_video(self, song_id, directory=None):
def download_video(self, song_id, directory=None, **ydl_extra_opts):
return self._base._download \
(
song_id = song_id,
directory = directory,
video = True,
**ydl_extra_opts
)

def download_album(self, album_id, directory=None):
def download_album(self, album_id, directory=None, **ydl_extra_opts):
album = self._api.album(album_id)

album_thumbnail_url = album['thumbnail']['url']
Expand Down Expand Up @@ -313,11 +320,12 @@ def download_album(self, album_id, directory=None):
thumbnail = thumbnail,
directory = directory, # CHANGE THIS
video = False,
**ydl_extra_opts
)

return album

def download_playlist(self, playlist_id, directory=None):
def download_playlist(self, playlist_id, directory=None, **ydl_extra_opts):
playlist = self._api.playlist(playlist_id)

playlist_name = playlist['name']
Expand Down Expand Up @@ -370,6 +378,7 @@ def download_playlist(self, playlist_id, directory=None):
thumbnail = thumbnail,
directory = directory, # CHANGE THIS
video = False,
**ydl_extra_opts
)

return playlist
Expand Down