mirror of
https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
synced 2024-11-26 18:03:17 +01:00
Fixed multiple issues including split disks breaking
This commit is contained in:
parent
0b51951b5f
commit
1993fc05e1
3
.gitignore
vendored
3
.gitignore
vendored
@ -151,6 +151,3 @@ ZSpotify\ Podcasts/
|
|||||||
|
|
||||||
# Intellij
|
# Intellij
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
#Configuration json file
|
|
||||||
zs_config.json
|
|
||||||
|
@ -22,7 +22,8 @@ def get_saved_tracks() -> list:
|
|||||||
limit = 50
|
limit = 50
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
resp = ZSpotify.invoke_url_with_params(SAVED_TRACKS_URL, limit=limit, offset=offset)
|
resp = ZSpotify.invoke_url_with_params(
|
||||||
|
SAVED_TRACKS_URL, limit=limit, offset=offset)
|
||||||
offset += limit
|
offset += limit
|
||||||
songs.extend(resp[ITEMS])
|
songs.extend(resp[ITEMS])
|
||||||
if len(resp[ITEMS]) < limit:
|
if len(resp[ITEMS]) < limit:
|
||||||
@ -53,24 +54,29 @@ def get_song_info(song_id) -> Tuple[List[str], str, str, Any, Any, Any, Any, Any
|
|||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='', disable_progressbar=False) -> None:
|
def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='', disable_progressbar=False) -> None:
|
||||||
""" Downloads raw song audio from Spotify """
|
""" Downloads raw song audio from Spotify """
|
||||||
download_directory = os.path.join(os.path.dirname(__file__), ZSpotify.get_config(ROOT_PATH), extra_paths)
|
|
||||||
try:
|
try:
|
||||||
(artists, album_name, name, image_url, release_year, disc_number,
|
(artists, album_name, name, image_url, release_year, disc_number,
|
||||||
track_number, scraped_song_id, is_playable) = get_song_info(track_id)
|
track_number, scraped_song_id, is_playable) = get_song_info(track_id)
|
||||||
|
|
||||||
|
if ZSpotify.get_config(SPLIT_ALBUM_DISCS):
|
||||||
|
download_directory = os.path.join(os.path.dirname(
|
||||||
|
__file__), ZSpotify.get_config(ROOT_PATH), extra_paths, f'Disc {disc_number}')
|
||||||
|
else:
|
||||||
|
download_directory = os.path.join(os.path.dirname(
|
||||||
|
__file__), ZSpotify.get_config(ROOT_PATH), extra_paths)
|
||||||
|
|
||||||
song_name = artists[0] + ' - ' + name
|
song_name = artists[0] + ' - ' + name
|
||||||
if prefix:
|
if prefix:
|
||||||
song_name = f'{prefix_value.zfill(2)} - {song_name}' if prefix_value.isdigit(
|
song_name = f'{prefix_value.zfill(2)} - {song_name}' if prefix_value.isdigit(
|
||||||
) else f'{prefix_value} - {song_name}'
|
) else f'{prefix_value} - {song_name}'
|
||||||
|
|
||||||
if ZSpotify.get_config(SPLIT_ALBUM_DISCS):
|
filename = os.path.join(
|
||||||
filename = os.path.join(download_directory, f'Disc {disc_number}',
|
download_directory, f'{song_name}.{ZSpotify.get_config(DOWNLOAD_FORMAT)}')
|
||||||
f'{song_name}.{ZSpotify.get_config(DOWNLOAD_FORMAT)}')
|
|
||||||
else:
|
except Exception as e:
|
||||||
filename = os.path.join(download_directory,
|
|
||||||
f'{song_name}.{ZSpotify.get_config(DOWNLOAD_FORMAT)}')
|
|
||||||
except Exception:
|
|
||||||
print('### SKIPPING SONG - FAILED TO QUERY METADATA ###')
|
print('### SKIPPING SONG - FAILED TO QUERY METADATA ###')
|
||||||
|
print(e)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
if not is_playable:
|
if not is_playable:
|
||||||
@ -84,7 +90,8 @@ def download_track(track_id: str, extra_paths='', prefix=False, prefix_value='',
|
|||||||
if track_id != scraped_song_id:
|
if track_id != scraped_song_id:
|
||||||
track_id = scraped_song_id
|
track_id = scraped_song_id
|
||||||
track_id = TrackId.from_base62(track_id)
|
track_id = TrackId.from_base62(track_id)
|
||||||
stream = ZSpotify.get_content_stream(track_id, ZSpotify.DOWNLOAD_QUALITY)
|
stream = ZSpotify.get_content_stream(
|
||||||
|
track_id, ZSpotify.DOWNLOAD_QUALITY)
|
||||||
create_download_directory(download_directory)
|
create_download_directory(download_directory)
|
||||||
total_size = stream.input_stream.size
|
total_size = stream.input_stream.size
|
||||||
|
|
||||||
@ -125,4 +132,5 @@ def convert_audio_format(filename) -> None:
|
|||||||
bitrate = '320k'
|
bitrate = '320k'
|
||||||
else:
|
else:
|
||||||
bitrate = '160k'
|
bitrate = '160k'
|
||||||
raw_audio.export(filename, format=ZSpotify.get_config(DOWNLOAD_FORMAT), bitrate=bitrate)
|
raw_audio.export(filename, format=ZSpotify.get_config(
|
||||||
|
DOWNLOAD_FORMAT), bitrate=bitrate)
|
||||||
|
Loading…
Reference in New Issue
Block a user