including fmframework network exceptions
This commit is contained in:
parent
bd404fa62b
commit
94075b14a8
@ -1,6 +1,6 @@
|
|||||||
from spotframework.net.network import Network as SpotNetwork, SpotifyNetworkException
|
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, LastFMNetworkException
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -13,21 +13,24 @@ def get_chart_of_spotify_tracks(spotnet: SpotNetwork,
|
|||||||
username: str = None):
|
username: str = None):
|
||||||
logger.info(f'pulling {period.name} chart')
|
logger.info(f'pulling {period.name} chart')
|
||||||
|
|
||||||
chart = fmnet.get_top_tracks(period=period, username=username, limit=limit)
|
try:
|
||||||
|
chart = fmnet.get_top_tracks(period=period, username=username, limit=limit)
|
||||||
|
|
||||||
spotify_chart = []
|
spotify_chart = []
|
||||||
for track in chart:
|
for track in chart:
|
||||||
try:
|
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,
|
||||||
response_limit=5).tracks
|
response_limit=5).tracks
|
||||||
if len(spotify_search) > 0:
|
if len(spotify_search) > 0:
|
||||||
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:
|
except SpotifyNetworkException as e:
|
||||||
logger.error(f'error during search function - {e}')
|
logger.error(f'error during search function - {e}')
|
||||||
|
|
||||||
return spotify_chart
|
|
||||||
|
|
||||||
|
return spotify_chart
|
||||||
|
except LastFMNetworkException as e:
|
||||||
|
logger.error(f'error during chart retrieval function - {e}')
|
||||||
|
return []
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from fmframework.net.network import Network as FmNet
|
from fmframework.net.network import Network as FmNet, LastFMNetworkException
|
||||||
from spotframework.net.network import Network as SpotNet
|
from spotframework.net.network import Network as SpotNet
|
||||||
|
|
||||||
from spotframework.model.uri import Uri
|
from spotframework.model.uri import Uri
|
||||||
@ -33,12 +33,10 @@ class ChartSource(TrackSource):
|
|||||||
def process(self, params: Params, uris: List[Uri] = None):
|
def process(self, params: Params, uris: List[Uri] = None):
|
||||||
# TODO add processor support?
|
# TODO add processor support?
|
||||||
|
|
||||||
tracks = get_chart_of_spotify_tracks(spotnet=self.net,
|
try:
|
||||||
fmnet=self.fmnet,
|
return get_chart_of_spotify_tracks(spotnet=self.net,
|
||||||
period=params.chart_range,
|
fmnet=self.fmnet,
|
||||||
limit=params.limit)
|
period=params.chart_range,
|
||||||
|
limit=params.limit)
|
||||||
if tracks is not None and len(tracks) > 0:
|
except LastFMNetworkException as e:
|
||||||
return tracks
|
logger.error(f'error occured during chart retrieval - {e}')
|
||||||
else:
|
|
||||||
logger.error('no tracks returned')
|
|
||||||
|
@ -5,7 +5,7 @@ from spotframework.model.album import SimplifiedAlbum
|
|||||||
from spotframework.model.artist import SimplifiedArtist
|
from spotframework.model.artist import SimplifiedArtist
|
||||||
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, LastFMNetworkException
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -96,15 +96,13 @@ class Counter:
|
|||||||
logger.error(f'error occured during track retrieval - {e}')
|
logger.error(f'error occured during track retrieval - {e}')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if username is not None:
|
try:
|
||||||
fmtrack = self.fmnet.get_track(name=track.name, artist=track.artists[0].name, username=username)
|
fmtrack = self.fmnet.get_track(name=track.name,
|
||||||
else:
|
artist=track.artists[0].name,
|
||||||
fmtrack = self.fmnet.get_track(name=track.name, artist=track.artists[0].name, username=self.fmnet.username)
|
username=username or self.fmnet.username)
|
||||||
|
|
||||||
if fmtrack is not None:
|
|
||||||
return fmtrack.user_scrobbles
|
return fmtrack.user_scrobbles
|
||||||
else:
|
except LastFMNetworkException as e:
|
||||||
logger.error(f'no album returned for {track}')
|
logger.error(f'error occured during track retrieval - {e}')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def count_album(self, username: str = None, uri: Uri = None, album: SimplifiedAlbum = None) -> int:
|
def count_album(self, username: str = None, uri: Uri = None, album: SimplifiedAlbum = None) -> int:
|
||||||
@ -121,15 +119,13 @@ class Counter:
|
|||||||
logger.error(f'error occured during album retrieval - {e}')
|
logger.error(f'error occured during album retrieval - {e}')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if username is not None:
|
try:
|
||||||
fmalbum = self.fmnet.get_album(name=album.name, artist=album.artists[0].name, username=username)
|
fmalbum = self.fmnet.get_album(name=album.name,
|
||||||
else:
|
artist=album.artists[0].name,
|
||||||
fmalbum = self.fmnet.get_album(name=album.name, artist=album.artists[0].name, username=self.fmnet.username)
|
username=username or self.fmnet.username)
|
||||||
|
|
||||||
if fmalbum is not None:
|
|
||||||
return fmalbum.user_scrobbles
|
return fmalbum.user_scrobbles
|
||||||
else:
|
except LastFMNetworkException as e:
|
||||||
logger.error(f'no album returned for {album}')
|
logger.error(f'error occured during album retrieval - {e}')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def count_artist(self, username: str = None, uri: Uri = None, artist: SimplifiedArtist = None) -> int:
|
def count_artist(self, username: str = None, uri: Uri = None, artist: SimplifiedArtist = None) -> int:
|
||||||
@ -146,13 +142,9 @@ class Counter:
|
|||||||
logger.error(f'error occured during artist retrieval - {e}')
|
logger.error(f'error occured during artist retrieval - {e}')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if username is not None:
|
try:
|
||||||
fmartist = self.fmnet.get_artist(name=artist.name, username=username)
|
fmartist = self.fmnet.get_artist(name=artist.name, username=username or self.fmnet.username)
|
||||||
else:
|
|
||||||
fmartist = self.fmnet.get_artist(name=artist.name, username=self.fmnet.username)
|
|
||||||
|
|
||||||
if fmartist is not None:
|
|
||||||
return fmartist.user_scrobbles
|
return fmartist.user_scrobbles
|
||||||
else:
|
except LastFMNetworkException as e:
|
||||||
logger.error(f'no artist returned for {artist}')
|
logger.error(f'error occured during artist retrieval - {e}')
|
||||||
return 0
|
return 0
|
||||||
|
@ -5,7 +5,7 @@ import json
|
|||||||
from spotframework.net.network import Network as Spotnet
|
from spotframework.net.network import Network as Spotnet
|
||||||
from spotframework.engine.playlistengine import PlaylistEngine
|
from spotframework.engine.playlistengine import PlaylistEngine
|
||||||
from spotframework.model.uri import Uri
|
from spotframework.model.uri import Uri
|
||||||
from fmframework.net.network import Network as Fmnet
|
from fmframework.net.network import Network as Fmnet, LastFMNetworkException
|
||||||
from spotfm.maths.counter import Counter
|
from spotfm.maths.counter import Counter
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -29,7 +29,11 @@ class Stats(Cmd):
|
|||||||
if in_string is None or len(in_string) < 2:
|
if in_string is None or len(in_string) < 2:
|
||||||
in_string = input('uri group/uri>')
|
in_string = input('uri group/uri>')
|
||||||
|
|
||||||
user_total = self.fmnet.get_user_scrobble_count()
|
try:
|
||||||
|
user_total = self.fmnet.get_user_scrobble_count()
|
||||||
|
except LastFMNetworkException as e:
|
||||||
|
logger.error(f'error occured during scrobble count retrieval - {e}')
|
||||||
|
user_total = 0
|
||||||
|
|
||||||
total = 0
|
total = 0
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user