update spotframework network actions to be tried and caught
This commit is contained in:
parent
3089f25b59
commit
bd404fa62b
@ -1,4 +1,4 @@
|
|||||||
from spotframework.net.network import Network as SpotNetwork
|
from spotframework.net.network import Network as SpotNetwork, SpotifyNetworkException
|
||||||
from spotframework.model.uri import Uri
|
from spotframework.model.uri import Uri
|
||||||
from fmframework.net.network import Network as FmNetwork
|
from fmframework.net.network import Network as FmNetwork
|
||||||
import logging
|
import logging
|
||||||
@ -17,6 +17,7 @@ def get_chart_of_spotify_tracks(spotnet: SpotNetwork,
|
|||||||
|
|
||||||
spotify_chart = []
|
spotify_chart = []
|
||||||
for track in chart:
|
for track in chart:
|
||||||
|
try:
|
||||||
spotify_search = spotnet.search(query_types=[Uri.ObjectType.track],
|
spotify_search = spotnet.search(query_types=[Uri.ObjectType.track],
|
||||||
track=track.name,
|
track=track.name,
|
||||||
artist=track.artist.name,
|
artist=track.artist.name,
|
||||||
@ -25,6 +26,8 @@ def get_chart_of_spotify_tracks(spotnet: SpotNetwork,
|
|||||||
spotify_chart.append(spotify_search[0])
|
spotify_chart.append(spotify_search[0])
|
||||||
else:
|
else:
|
||||||
logger.debug('no search tracks returned')
|
logger.debug('no search tracks returned')
|
||||||
|
except SpotifyNetworkException as e:
|
||||||
|
logger.error(f'error during search function - {e}')
|
||||||
|
|
||||||
return spotify_chart
|
return spotify_chart
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from spotframework.net.network import Network as SpotifyNetwork
|
from spotframework.net.network import Network as SpotifyNetwork, SpotifyNetworkException
|
||||||
from spotframework.model.playlist import FullPlaylist
|
from spotframework.model.playlist import FullPlaylist
|
||||||
from spotframework.model.track import SimplifiedTrack
|
from spotframework.model.track import SimplifiedTrack
|
||||||
from spotframework.model.album import SimplifiedAlbum
|
from spotframework.model.album import SimplifiedAlbum
|
||||||
@ -43,12 +43,20 @@ class Counter:
|
|||||||
|
|
||||||
if playlist is not None:
|
if playlist is not None:
|
||||||
if playlist.has_tracks() is False:
|
if playlist.has_tracks() is False:
|
||||||
|
try:
|
||||||
playlist.tracks = self.spotnet.get_playlist_tracks(uri=playlist.uri)
|
playlist.tracks = self.spotnet.get_playlist_tracks(uri=playlist.uri)
|
||||||
|
except SpotifyNetworkException as e:
|
||||||
|
logger.error(f'error occured during playlist track retrieval - {e}')
|
||||||
|
return 0
|
||||||
|
|
||||||
if uri is not None:
|
if uri is not None:
|
||||||
if uri.object_type != Uri.ObjectType.playlist:
|
if uri.object_type != Uri.ObjectType.playlist:
|
||||||
raise ValueError('uri not a playlist')
|
raise ValueError('uri not a playlist')
|
||||||
playlist = self.spotnet.get_playlist(uri=uri)
|
try:
|
||||||
|
playlist = self.spotnet.get_playlist(uri=uri, tracks=True)
|
||||||
|
except SpotifyNetworkException as e:
|
||||||
|
logger.error(f'error occured during playlist retrieval - {e}')
|
||||||
|
return 0
|
||||||
|
|
||||||
scrobble_count = 0
|
scrobble_count = 0
|
||||||
|
|
||||||
@ -82,7 +90,11 @@ class Counter:
|
|||||||
if uri is not None:
|
if uri is not None:
|
||||||
if uri.object_type != Uri.ObjectType.track:
|
if uri.object_type != Uri.ObjectType.track:
|
||||||
raise ValueError('uri not a track')
|
raise ValueError('uri not a track')
|
||||||
|
try:
|
||||||
track = self.spotnet.get_track(uri=uri)
|
track = self.spotnet.get_track(uri=uri)
|
||||||
|
except SpotifyNetworkException as e:
|
||||||
|
logger.error(f'error occured during track retrieval - {e}')
|
||||||
|
return 0
|
||||||
|
|
||||||
if username is not None:
|
if username is not None:
|
||||||
fmtrack = self.fmnet.get_track(name=track.name, artist=track.artists[0].name, username=username)
|
fmtrack = self.fmnet.get_track(name=track.name, artist=track.artists[0].name, username=username)
|
||||||
@ -103,7 +115,11 @@ class Counter:
|
|||||||
if uri is not None:
|
if uri is not None:
|
||||||
if uri.object_type != Uri.ObjectType.album:
|
if uri.object_type != Uri.ObjectType.album:
|
||||||
raise ValueError('uri not an album')
|
raise ValueError('uri not an album')
|
||||||
|
try:
|
||||||
album = self.spotnet.get_album(uri=uri)
|
album = self.spotnet.get_album(uri=uri)
|
||||||
|
except SpotifyNetworkException as e:
|
||||||
|
logger.error(f'error occured during album retrieval - {e}')
|
||||||
|
return 0
|
||||||
|
|
||||||
if username is not None:
|
if username is not None:
|
||||||
fmalbum = self.fmnet.get_album(name=album.name, artist=album.artists[0].name, username=username)
|
fmalbum = self.fmnet.get_album(name=album.name, artist=album.artists[0].name, username=username)
|
||||||
@ -124,7 +140,11 @@ class Counter:
|
|||||||
if uri is not None:
|
if uri is not None:
|
||||||
if uri.object_type != Uri.ObjectType.artist:
|
if uri.object_type != Uri.ObjectType.artist:
|
||||||
raise ValueError('uri not an artist')
|
raise ValueError('uri not an artist')
|
||||||
|
try:
|
||||||
artist = self.spotnet.get_artist(uri=uri)
|
artist = self.spotnet.get_artist(uri=uri)
|
||||||
|
except SpotifyNetworkException as e:
|
||||||
|
logger.error(f'error occured during artist retrieval - {e}')
|
||||||
|
return 0
|
||||||
|
|
||||||
if username is not None:
|
if username is not None:
|
||||||
fmartist = self.fmnet.get_artist(name=artist.name, username=username)
|
fmartist = self.fmnet.get_artist(name=artist.name, username=username)
|
||||||
|
Loading…
Reference in New Issue
Block a user