mirror of https://github.com/afkcodes/zspotify.git
Bugfixes
This commit is contained in:
parent
a15d966d93
commit
58670d8081
|
@ -1,6 +1,5 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from threading import Thread
|
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Any, Tuple, List
|
from typing import Any, Tuple, List
|
||||||
|
@ -9,7 +8,7 @@ from librespot.audio.decoders import AudioQuality
|
||||||
from librespot.metadata import TrackId
|
from librespot.metadata import TrackId
|
||||||
from ffmpy import FFmpeg
|
from ffmpy import FFmpeg
|
||||||
|
|
||||||
from const import TRACKS, ALBUM, GENRES, GENRE, NAME, ITEMS, DISC_NUMBER, TRACK_NUMBER, IS_PLAYABLE, ARTISTS, IMAGES, URL, \
|
from const import TRACKS, ALBUM, GENRES, NAME, ITEMS, DISC_NUMBER, TRACK_NUMBER, IS_PLAYABLE, ARTISTS, IMAGES, URL, \
|
||||||
RELEASE_DATE, ID, TRACKS_URL, SAVED_TRACKS_URL, TRACK_STATS_URL, CODEC_MAP, EXT_MAP, DURATION_MS
|
RELEASE_DATE, ID, TRACKS_URL, SAVED_TRACKS_URL, TRACK_STATS_URL, CODEC_MAP, EXT_MAP, DURATION_MS
|
||||||
from termoutput import Printer, PrintChannel
|
from termoutput import Printer, PrintChannel
|
||||||
from utils import fix_filename, set_audio_tags, set_music_thumbnail, create_download_directory, \
|
from utils import fix_filename, set_audio_tags, set_music_thumbnail, create_download_directory, \
|
||||||
|
@ -57,11 +56,11 @@ def get_song_info(song_id) -> Tuple[List[str], List[str], str, str, Any, Any, An
|
||||||
genres.append(genre)
|
genres.append(genre)
|
||||||
elif len(artistInfo[GENRES]) > 0:
|
elif len(artistInfo[GENRES]) > 0:
|
||||||
genres.append(artistInfo[GENRES][0])
|
genres.append(artistInfo[GENRES][0])
|
||||||
|
|
||||||
if len(genres) == 0:
|
if len(genres) == 0:
|
||||||
Printer.print(PrintChannel.SKIPS, '### No Genre found.')
|
Printer.print(PrintChannel.SKIPS, '### No Genre found.')
|
||||||
genres.append('')
|
genres.append('')
|
||||||
|
|
||||||
album_name = info[TRACKS][0][ALBUM][NAME]
|
album_name = info[TRACKS][0][ALBUM][NAME]
|
||||||
name = info[TRACKS][0][NAME]
|
name = info[TRACKS][0][NAME]
|
||||||
image_url = info[TRACKS][0][ALBUM][IMAGES][0][URL]
|
image_url = info[TRACKS][0][ALBUM][IMAGES][0][URL]
|
||||||
|
@ -97,15 +96,15 @@ def get_song_duration(song_id: str) -> float:
|
||||||
def download_track(mode: str, track_id: str, extra_keys={}, disable_progressbar=False) -> None:
|
def download_track(mode: str, track_id: str, extra_keys={}, disable_progressbar=False) -> None:
|
||||||
""" Downloads raw song audio from Spotify """
|
""" Downloads raw song audio from Spotify """
|
||||||
|
|
||||||
|
prepare_download_loader = Loader(PrintChannel.PROGRESS_INFO, "Preparing download...")
|
||||||
|
prepare_download_loader.start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output_template = ZSpotify.CONFIG.get_output(mode)
|
output_template = ZSpotify.CONFIG.get_output(mode)
|
||||||
|
|
||||||
(artists, genres, album_name, name, image_url, release_year, disc_number,
|
(artists, genres, album_name, name, image_url, release_year, disc_number,
|
||||||
track_number, scraped_song_id, is_playable, duration_ms) = get_song_info(track_id)
|
track_number, scraped_song_id, is_playable, duration_ms) = get_song_info(track_id)
|
||||||
|
|
||||||
prepareDownloadLoader = Loader(PrintChannel.PROGRESS_INFO, "Preparing download...");
|
|
||||||
prepareDownloadLoader.start()
|
|
||||||
|
|
||||||
song_name = fix_filename(artists[0]) + ' - ' + fix_filename(name)
|
song_name = fix_filename(artists[0]) + ' - ' + fix_filename(name)
|
||||||
|
|
||||||
for k in extra_keys:
|
for k in extra_keys:
|
||||||
|
@ -152,15 +151,15 @@ def download_track(mode: str, track_id: str, extra_keys={}, disable_progressbar=
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
if not is_playable:
|
if not is_playable:
|
||||||
prepareDownloadLoader.stop();
|
prepare_download_loader.stop()
|
||||||
Printer.print(PrintChannel.SKIPS, '\n### SKIPPING: ' + song_name + ' (SONG IS UNAVAILABLE) ###' + "\n")
|
Printer.print(PrintChannel.SKIPS, '\n### SKIPPING: ' + song_name + ' (SONG IS UNAVAILABLE) ###' + "\n")
|
||||||
else:
|
else:
|
||||||
if check_id and check_name and ZSpotify.CONFIG.get_skip_existing_files():
|
if check_id and check_name and ZSpotify.CONFIG.get_skip_existing_files():
|
||||||
prepareDownloadLoader.stop();
|
prepare_download_loader.stop()
|
||||||
Printer.print(PrintChannel.SKIPS, '\n### SKIPPING: ' + song_name + ' (SONG ALREADY EXISTS) ###' + "\n")
|
Printer.print(PrintChannel.SKIPS, '\n### SKIPPING: ' + song_name + ' (SONG ALREADY EXISTS) ###' + "\n")
|
||||||
|
|
||||||
elif check_all_time and ZSpotify.CONFIG.get_skip_previously_downloaded():
|
elif check_all_time and ZSpotify.CONFIG.get_skip_previously_downloaded():
|
||||||
prepareDownloadLoader.stop();
|
prepare_download_loader.stop()
|
||||||
Printer.print(PrintChannel.SKIPS, '\n### SKIPPING: ' + song_name + ' (SONG ALREADY DOWNLOADED ONCE) ###' + "\n")
|
Printer.print(PrintChannel.SKIPS, '\n### SKIPPING: ' + song_name + ' (SONG ALREADY DOWNLOADED ONCE) ###' + "\n")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -171,7 +170,7 @@ def download_track(mode: str, track_id: str, extra_keys={}, disable_progressbar=
|
||||||
create_download_directory(filedir)
|
create_download_directory(filedir)
|
||||||
total_size = stream.input_stream.size
|
total_size = stream.input_stream.size
|
||||||
|
|
||||||
prepareDownloadLoader.stop();
|
prepare_download_loader.stop()
|
||||||
|
|
||||||
time_start = time.time()
|
time_start = time.time()
|
||||||
downloaded = 0
|
downloaded = 0
|
||||||
|
@ -222,8 +221,10 @@ def download_track(mode: str, track_id: str, extra_keys={}, disable_progressbar=
|
||||||
Printer.print(PrintChannel.ERRORS, "".join(traceback.TracebackException.from_exception(e).format()) + "\n")
|
Printer.print(PrintChannel.ERRORS, "".join(traceback.TracebackException.from_exception(e).format()) + "\n")
|
||||||
if os.path.exists(filename_temp):
|
if os.path.exists(filename_temp):
|
||||||
os.remove(filename_temp)
|
os.remove(filename_temp)
|
||||||
|
|
||||||
prepareDownloadLoader.stop()
|
prepare_download_loader.stop()
|
||||||
|
|
||||||
|
|
||||||
def convert_audio_format(filename) -> None:
|
def convert_audio_format(filename) -> None:
|
||||||
""" Converts raw audio into playable file """
|
""" Converts raw audio into playable file """
|
||||||
temp_filename = f'{os.path.splitext(filename)[0]}.tmp'
|
temp_filename = f'{os.path.splitext(filename)[0]}.tmp'
|
||||||
|
@ -250,9 +251,9 @@ def convert_audio_format(filename) -> None:
|
||||||
inputs={temp_filename: None},
|
inputs={temp_filename: None},
|
||||||
outputs={filename: output_params}
|
outputs={filename: output_params}
|
||||||
)
|
)
|
||||||
|
|
||||||
with Loader(PrintChannel.PROGRESS_INFO, "Converting file..."):
|
with Loader(PrintChannel.PROGRESS_INFO, "Converting file..."):
|
||||||
ff_m.run()
|
ff_m.run()
|
||||||
|
|
||||||
if os.path.exists(temp_filename):
|
if os.path.exists(temp_filename):
|
||||||
os.remove(temp_filename)
|
os.remove(temp_filename)
|
||||||
|
|
|
@ -86,16 +86,16 @@ class ZSpotify:
|
||||||
from termoutput import Printer, PrintChannel
|
from termoutput import Printer, PrintChannel
|
||||||
headers = cls.get_auth_header()
|
headers = cls.get_auth_header()
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
responseText = response.text
|
responsetext = response.text
|
||||||
responseJson = response.json()
|
responsejson = response.json()
|
||||||
|
|
||||||
if 'error' in responseJson and tryCount < 5:
|
if 'error' in responsejson and tryCount < 5:
|
||||||
|
|
||||||
Printer.Print(PrintChannel.API_ERROR, f"Spotify API Error ({responseJson['error']['status']}): {responseJson['error']['message']}")
|
Printer.print(PrintChannel.API_ERRORS, f"Spotify API Error ({responsejson['error']['status']}): {responsejson['error']['message']}")
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
return cls.invoke_url(url, tryCount + 1)
|
return cls.invoke_url(url, tryCount + 1)
|
||||||
|
|
||||||
return responseText, responseJson
|
return responsetext, responsejson
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def check_premium(cls) -> bool:
|
def check_premium(cls) -> bool:
|
||||||
|
|
Loading…
Reference in New Issue