mirror of
https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
synced 2024-11-29 19:24:34 +01:00
added exception handling and retry-logic to zspotify
This commit is contained in:
parent
16c7ee5d51
commit
9a48746b79
@ -9,7 +9,7 @@ It's like youtube-dl, but for Spotify.
|
|||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
|
import time
|
||||||
import requests
|
import requests
|
||||||
from librespot.audio.decoders import VorbisOnlyAudioQuality
|
from librespot.audio.decoders import VorbisOnlyAudioQuality
|
||||||
from librespot.core import Session
|
from librespot.core import Session
|
||||||
@ -19,7 +19,6 @@ from const import TYPE, \
|
|||||||
PLAYLIST_READ_PRIVATE, USER_LIBRARY_READ
|
PLAYLIST_READ_PRIVATE, USER_LIBRARY_READ
|
||||||
from config import Config
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
class ZSpotify:
|
class ZSpotify:
|
||||||
SESSION: Session = None
|
SESSION: Session = None
|
||||||
DOWNLOAD_QUALITY = None
|
DOWNLOAD_QUALITY = None
|
||||||
@ -82,10 +81,19 @@ class ZSpotify:
|
|||||||
return requests.get(url, headers=headers, params=params).json()
|
return requests.get(url, headers=headers, params=params).json()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def invoke_url(cls, url):
|
def invoke_url(cls, url, tryCount = 0):
|
||||||
headers = cls.get_auth_header()
|
headers = cls.get_auth_header()
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
return response.text, response.json()
|
responseText = response.text
|
||||||
|
responseJson = response.json()
|
||||||
|
|
||||||
|
if 'error' in responseJson and tryCount < 20:
|
||||||
|
|
||||||
|
print(f"Spotify API Error ({responseJson['error']['status']}): {responseJson['error']['message']}")
|
||||||
|
time.sleep(5)
|
||||||
|
return cls.invoke_url(url, tryCount + 1)
|
||||||
|
|
||||||
|
return responseText, responseJson
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def check_premium(cls) -> bool:
|
def check_premium(cls) -> bool:
|
||||||
|
Loading…
Reference in New Issue
Block a user