From e86d26b8b836fe823d8c338e4f86165fe9dc388d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= <57042029+rucete@users.noreply.github.com> Date: Sat, 2 Jul 2022 17:44:36 +0200 Subject: [PATCH 1/8] Specify youtube URL manually With this new option it is possible to specify a youtube URL manually in case the one determined by the program does not match the right one for the song. --- spotify_dl/spotify_dl.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/spotify_dl/spotify_dl.py b/spotify_dl/spotify_dl.py index 11136ba8..9ba32994 100755 --- a/spotify_dl/spotify_dl.py +++ b/spotify_dl/spotify_dl.py @@ -23,6 +23,13 @@ def spotify_dl(): help='Specify download directory.', required=False, default = ".") parser.add_argument('-d', '--download', action='store_true', help='Download using youtube-dl', default=True) + + """Newly added argument (by kinglobster). Specifies an alternative youtube url in case that the one + determined by the program is mistaken or does not fulfill the requirements of quality or any other.""" + parser.add_argument('-y', '--alternative_yt_url', action='store', type=str, required=False, + help='Specify youtube url to download the song from. The metadata form spotify' + 'and the audio from youtube will still merge in a single file.') + parser.add_argument('-f', '--format_str', type=str, action='store', help='Specify youtube-dl format string.', default='bestaudio/best') @@ -99,8 +106,18 @@ def spotify_dl(): if args.keep_playlist_order: file_name_f = playlist_num_filename if save_path is not None: - download_songs(songs, save_path, args.format_str, args.skip_mp3, args.keep_playlist_order, args.no_overwrites, args.skip_non_music_sections, file_name_f) + #download_songs(songs, save_path, args.format_str, args.skip_mp3, args.keep_playlist_order, args.no_overwrites, args.skip_non_music_sections, file_name_f) + # From this line downwards, modified code by kinglobster + if args.alternative_yt_url is not None: + alternative_yt_url = args.alternative_yt_url + download_songs(songs, save_path, args.format_str, args.skip_mp3, args.keep_playlist_order, + args.no_overwrites, args.skip_non_music_sections, file_name_f, alternative_yt_url) + else: + download_songs(songs, save_path, args.format_str, args.skip_mp3, args.keep_playlist_order, + args.no_overwrites, args.skip_non_music_sections, file_name_f) + + # End of modified code by kinglobster if __name__ == '__main__': spotify_dl() From c359f3451ebc6253474c1914bf9b1558a5e9b3d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= <57042029+rucete@users.noreply.github.com> Date: Sat, 2 Jul 2022 17:55:04 +0200 Subject: [PATCH 2/8] Specify youtube URL manually With this new option it is possible to specify a youtube URL manually in case the one determined by the program does not match the right one for the song. --- spotify_dl/youtube.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/spotify_dl/youtube.py b/spotify_dl/youtube.py index 478092f7..c6209374 100644 --- a/spotify_dl/youtube.py +++ b/spotify_dl/youtube.py @@ -76,11 +76,20 @@ def download_songs(songs, download_directory, format_string, skip_mp3, with youtube_dl.YoutubeDL(ydl_opts) as ydl: try: - ydl.download([query]) - except Exception as e: - log.debug(e) - print('Failed to download: {}, please ensure YouTubeDL is up-to-date. '.format(query)) - continue + #ydl.download([query]) + # From this line, modified code by kinglobster + + if alternative_yt_url is None: + ydl.download([query]) + else: + print('###### Downloading from alternative url!!!: ' + alternative_yt_url) + ydl.download(alternative_yt_url) + + # End of modified code + except Exception as e: + log.debug(e) + print('Failed to download: {}, please ensure YouTubeDL is up-to-date. '.format(query)) + continue if not skip_mp3: mp3filename = f"{file_path}.mp3" From 48a1d35274b77045cdaa3542619ce24c1833f2f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= <57042029+rucete@users.noreply.github.com> Date: Sat, 2 Jul 2022 17:56:56 +0200 Subject: [PATCH 3/8] Update youtube.py --- spotify_dl/youtube.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spotify_dl/youtube.py b/spotify_dl/youtube.py index c6209374..ea602973 100644 --- a/spotify_dl/youtube.py +++ b/spotify_dl/youtube.py @@ -85,11 +85,12 @@ def download_songs(songs, download_directory, format_string, skip_mp3, print('###### Downloading from alternative url!!!: ' + alternative_yt_url) ydl.download(alternative_yt_url) - # End of modified code - except Exception as e: - log.debug(e) - print('Failed to download: {}, please ensure YouTubeDL is up-to-date. '.format(query)) - continue + # End of modified code + + except Exception as e: + log.debug(e) + print('Failed to download: {}, please ensure YouTubeDL is up-to-date. '.format(query)) + continue if not skip_mp3: mp3filename = f"{file_path}.mp3" From a9fe028ffb371b972980ef823cbd2879d08f6eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= <57042029+rucete@users.noreply.github.com> Date: Sat, 2 Jul 2022 18:08:14 +0200 Subject: [PATCH 4/8] Update youtube.py --- spotify_dl/youtube.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spotify_dl/youtube.py b/spotify_dl/youtube.py index ea602973..6805e1d5 100644 --- a/spotify_dl/youtube.py +++ b/spotify_dl/youtube.py @@ -21,7 +21,7 @@ def playlist_num_filename(song): def download_songs(songs, download_directory, format_string, skip_mp3, keep_playlist_order=False, no_overwrites=False, skip_non_music_sections=False, - file_name_f=default_filename): + file_name_f=default_filename, alternative_yt_url=None): """ Downloads songs from the YouTube URL passed to either current directory or download_directory, is it is passed. :param songs: Dictionary of songs and associated artist @@ -32,6 +32,7 @@ def download_songs(songs, download_directory, format_string, skip_mp3, :param no_overwrites: Whether we should avoid overwriting the song if it already exists :param skip_non_music_sections: Whether we should skip Non-Music sections using SponsorBlock API :param file_name_f: optional func(song) -> str that returns a filename for the download (without extension) + :param alternative_yt_url: added by kinglobster, contains alternative youtube video to download the song from """ overwrites = not no_overwrites log.debug(f"Downloading to {download_directory}") @@ -70,7 +71,7 @@ def download_songs(songs, download_directory, format_string, skip_mp3, mp3_postprocess_opts = { 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', - 'preferredquality': '192', + 'preferredquality': '320', # 320kbps is spotify's 'very high' quality. Was '192' } ydl_opts['postprocessors'].append(mp3_postprocess_opts.copy()) @@ -85,8 +86,8 @@ def download_songs(songs, download_directory, format_string, skip_mp3, print('###### Downloading from alternative url!!!: ' + alternative_yt_url) ydl.download(alternative_yt_url) - # End of modified code - + # End of modified code + except Exception as e: log.debug(e) print('Failed to download: {}, please ensure YouTubeDL is up-to-date. '.format(query)) From cd96e273be4ef1d5701f7decdbed606b651f0f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= <57042029+rucete@users.noreply.github.com> Date: Sat, 2 Jul 2022 18:08:39 +0200 Subject: [PATCH 5/8] Minor bugs --- spotify_dl/spotify_dl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spotify_dl/spotify_dl.py b/spotify_dl/spotify_dl.py index 9ba32994..1e5c6896 100755 --- a/spotify_dl/spotify_dl.py +++ b/spotify_dl/spotify_dl.py @@ -23,13 +23,13 @@ def spotify_dl(): help='Specify download directory.', required=False, default = ".") parser.add_argument('-d', '--download', action='store_true', help='Download using youtube-dl', default=True) - + """Newly added argument (by kinglobster). Specifies an alternative youtube url in case that the one determined by the program is mistaken or does not fulfill the requirements of quality or any other.""" parser.add_argument('-y', '--alternative_yt_url', action='store', type=str, required=False, help='Specify youtube url to download the song from. The metadata form spotify' 'and the audio from youtube will still merge in a single file.') - + parser.add_argument('-f', '--format_str', type=str, action='store', help='Specify youtube-dl format string.', default='bestaudio/best') From 722d62197bd93980a317934194627111ede17247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= <57042029+rucete@users.noreply.github.com> Date: Mon, 4 Jul 2022 20:58:55 +0200 Subject: [PATCH 6/8] Update spotify_dl.py --- spotify_dl/spotify_dl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spotify_dl/spotify_dl.py b/spotify_dl/spotify_dl.py index 1e5c6896..bdaf1566 100755 --- a/spotify_dl/spotify_dl.py +++ b/spotify_dl/spotify_dl.py @@ -24,8 +24,8 @@ def spotify_dl(): parser.add_argument('-d', '--download', action='store_true', help='Download using youtube-dl', default=True) - """Newly added argument (by kinglobster). Specifies an alternative youtube url in case that the one - determined by the program is mistaken or does not fulfill the requirements of quality or any other.""" + '''Newly added argument (by kinglobster). Specifies an alternative youtube url in case that the one + determined by the program is mistaken or does not fulfill the requirements of quality or any other.''' parser.add_argument('-y', '--alternative_yt_url', action='store', type=str, required=False, help='Specify youtube url to download the song from. The metadata form spotify' 'and the audio from youtube will still merge in a single file.') @@ -56,7 +56,7 @@ def spotify_dl(): if os.path.isfile(os.path.expanduser('~/.spotify_dl_settings')): with open(os.path.expanduser('~/.spotify_dl_settings')) as file: - config = json.loads(file.read()) + config = json.loads(file) for key, value in config.items(): if (isinstance(value, bool) and value) or (isinstance(value, str) and value and value.lower() in ['true', 't']): From 4ef0f228326dbef8048731f69c25be82004c95a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= <57042029+rucete@users.noreply.github.com> Date: Mon, 4 Jul 2022 21:08:52 +0200 Subject: [PATCH 7/8] Update youtube.py --- spotify_dl/youtube.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spotify_dl/youtube.py b/spotify_dl/youtube.py index 6805e1d5..6536cfb5 100644 --- a/spotify_dl/youtube.py +++ b/spotify_dl/youtube.py @@ -77,7 +77,7 @@ def download_songs(songs, download_directory, format_string, skip_mp3, with youtube_dl.YoutubeDL(ydl_opts) as ydl: try: - #ydl.download([query]) + # ydl.download([query]) # From this line, modified code by kinglobster if alternative_yt_url is None: From 2f3f7374aaeb0dbc72705811e1cf8706b0e560f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n?= <57042029+rucete@users.noreply.github.com> Date: Mon, 4 Jul 2022 21:13:26 +0200 Subject: [PATCH 8/8] Update spotify_dl.py --- spotify_dl/spotify_dl.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spotify_dl/spotify_dl.py b/spotify_dl/spotify_dl.py index bdaf1566..cfa2da70 100755 --- a/spotify_dl/spotify_dl.py +++ b/spotify_dl/spotify_dl.py @@ -24,8 +24,8 @@ def spotify_dl(): parser.add_argument('-d', '--download', action='store_true', help='Download using youtube-dl', default=True) - '''Newly added argument (by kinglobster). Specifies an alternative youtube url in case that the one - determined by the program is mistaken or does not fulfill the requirements of quality or any other.''' + # Newly added argument (by kinglobster). Specifies an alternative youtube url in case that the one + # determined by the program is mistaken or does not fulfill the requirements of quality or any other. parser.add_argument('-y', '--alternative_yt_url', action='store', type=str, required=False, help='Specify youtube url to download the song from. The metadata form spotify' 'and the audio from youtube will still merge in a single file.') @@ -106,7 +106,7 @@ def spotify_dl(): if args.keep_playlist_order: file_name_f = playlist_num_filename if save_path is not None: - #download_songs(songs, save_path, args.format_str, args.skip_mp3, args.keep_playlist_order, args.no_overwrites, args.skip_non_music_sections, file_name_f) + # download_songs(songs, save_path, args.format_str, args.skip_mp3, args.keep_playlist_order, args.no_overwrites, args.skip_non_music_sections, file_name_f) # From this line downwards, modified code by kinglobster if args.alternative_yt_url is not None: @@ -121,3 +121,5 @@ def spotify_dl(): if __name__ == '__main__': spotify_dl() + +