Fixed issue when downloading multiple playlists

This commit is contained in:
logykk 2021-11-17 21:29:15 +13:00
parent 2638805741
commit b9d42c4d7d
3 changed files with 16 additions and 10 deletions

View File

@ -259,8 +259,13 @@ def search(search_term):
print('NO RESULTS FOUND - EXITING...') print('NO RESULTS FOUND - EXITING...')
else: else:
selection = '' selection = ''
print('\n> SELECT A DOWNLOAD OPTION BY ID')
print('> SELECT A RANGE BY ADDING A DASH BETWEEN BOTH ID\'s')
print('> OR PARTICULAR OPTIONS BY ADDING A COMMA BETWEEN ID\'s')
print('> For example, typing 5 to get option 5 or 10-20 to get\nevery option from 10-20 (inclusive)\n')
print('> Or type 10,12,15,18 to get those options in particular')
while len(selection) == 0: while len(selection) == 0:
selection = str(input('SELECT ITEM(S) BY S.NO: ')) selection = str(input('ID(s): '))
inputs = split_input(selection) inputs = split_input(selection)
for pos in inputs: for pos in inputs:
position = int(pos) position = int(pos)

View File

@ -2,7 +2,7 @@ from tqdm import tqdm
from const import ITEMS, ID, TRACK, NAME from const import ITEMS, ID, TRACK, NAME
from track import download_track from track import download_track
from utils import fix_filename from utils import fix_filename, split_input
from zspotify import ZSpotify from zspotify import ZSpotify
MY_PLAYLISTS_URL = 'https://api.spotify.com/v1/me/playlists' MY_PLAYLISTS_URL = 'https://api.spotify.com/v1/me/playlists'
@ -69,17 +69,18 @@ def download_from_user_playlist():
print(str(count) + ': ' + playlist[NAME].strip()) print(str(count) + ': ' + playlist[NAME].strip())
count += 1 count += 1
selection = ''
print('\n> SELECT A PLAYLIST BY ID') print('\n> SELECT A PLAYLIST BY ID')
print('> SELECT A RANGE BY ADDING A DASH BETWEEN BOTH ID\'s') print('> SELECT A RANGE BY ADDING A DASH BETWEEN BOTH ID\'s')
print('> OR PARTICULAR OPTIONS BY ADDING A COMMA BETWEEN ID\'s')
print('> For example, typing 10 to get one playlist or 10-20 to get\nevery playlist from 10-20 (inclusive)\n') print('> For example, typing 10 to get one playlist or 10-20 to get\nevery playlist from 10-20 (inclusive)\n')
print('> Or type 10,12,15,18 to get those playlists in particular')
while len(selection) == 0:
selection = str(input('ID(s): '))
playlist_choices = map(int, split_input(selection))
playlist_choices = map(int, input('ID(s): ').split('-')) for playlist_number in playlist_choices:
playlist = playlists[playlist_number - 1]
start = next(playlist_choices) - 1
end = next(playlist_choices, start + 1)
for playlist_number in range(start, end):
playlist = playlists[playlist_number]
print(f'Downloading {playlist[NAME].strip()}') print(f'Downloading {playlist[NAME].strip()}')
download_playlist(playlist) download_playlist(playlist)

View File

@ -176,7 +176,7 @@ def convert_audio_format(filename) -> None:
os.replace(filename, temp_filename) os.replace(filename, temp_filename)
download_format = ZSpotify.get_config(DOWNLOAD_FORMAT).lower() download_format = ZSpotify.get_config(DOWNLOAD_FORMAT).lower()
file_codec = CODEC_MAP.get(download_format, "copy") file_codec = CODEC_MAP.get(download_format, 'copy')
if file_codec != 'copy': if file_codec != 'copy':
bitrate = ZSpotify.get_config(BITRATE) bitrate = ZSpotify.get_config(BITRATE)
if not bitrate: if not bitrate: