including fmframework network exceptions

This commit is contained in:
aj 2020-06-28 10:05:40 +01:00
parent bd404fa62b
commit 94075b14a8
4 changed files with 51 additions and 54 deletions

View File

@ -1,6 +1,6 @@
from spotframework.net.network import Network as SpotNetwork, SpotifyNetworkException
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
logger = logging.getLogger(__name__)
@ -13,6 +13,7 @@ def get_chart_of_spotify_tracks(spotnet: SpotNetwork,
username: str = None):
logger.info(f'pulling {period.name} chart')
try:
chart = fmnet.get_top_tracks(period=period, username=username, limit=limit)
spotify_chart = []
@ -30,4 +31,6 @@ def get_chart_of_spotify_tracks(spotnet: SpotNetwork,
logger.error(f'error during search function - {e}')
return spotify_chart
except LastFMNetworkException as e:
logger.error(f'error during chart retrieval function - {e}')
return []

View File

@ -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.model.uri import Uri
@ -33,12 +33,10 @@ class ChartSource(TrackSource):
def process(self, params: Params, uris: List[Uri] = None):
# TODO add processor support?
tracks = get_chart_of_spotify_tracks(spotnet=self.net,
try:
return get_chart_of_spotify_tracks(spotnet=self.net,
fmnet=self.fmnet,
period=params.chart_range,
limit=params.limit)
if tracks is not None and len(tracks) > 0:
return tracks
else:
logger.error('no tracks returned')
except LastFMNetworkException as e:
logger.error(f'error occured during chart retrieval - {e}')

View File

@ -5,7 +5,7 @@ from spotframework.model.album import SimplifiedAlbum
from spotframework.model.artist import SimplifiedArtist
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
@ -96,15 +96,13 @@ class Counter:
logger.error(f'error occured during track retrieval - {e}')
return 0
if username is not None:
fmtrack = self.fmnet.get_track(name=track.name, artist=track.artists[0].name, username=username)
else:
fmtrack = self.fmnet.get_track(name=track.name, artist=track.artists[0].name, username=self.fmnet.username)
if fmtrack is not None:
try:
fmtrack = self.fmnet.get_track(name=track.name,
artist=track.artists[0].name,
username=username or self.fmnet.username)
return fmtrack.user_scrobbles
else:
logger.error(f'no album returned for {track}')
except LastFMNetworkException as e:
logger.error(f'error occured during track retrieval - {e}')
return 0
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}')
return 0
if username is not None:
fmalbum = self.fmnet.get_album(name=album.name, artist=album.artists[0].name, username=username)
else:
fmalbum = self.fmnet.get_album(name=album.name, artist=album.artists[0].name, username=self.fmnet.username)
if fmalbum is not None:
try:
fmalbum = self.fmnet.get_album(name=album.name,
artist=album.artists[0].name,
username=username or self.fmnet.username)
return fmalbum.user_scrobbles
else:
logger.error(f'no album returned for {album}')
except LastFMNetworkException as e:
logger.error(f'error occured during album retrieval - {e}')
return 0
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}')
return 0
if username is not None:
fmartist = self.fmnet.get_artist(name=artist.name, username=username)
else:
fmartist = self.fmnet.get_artist(name=artist.name, username=self.fmnet.username)
if fmartist is not None:
try:
fmartist = self.fmnet.get_artist(name=artist.name, username=username or self.fmnet.username)
return fmartist.user_scrobbles
else:
logger.error(f'no artist returned for {artist}')
except LastFMNetworkException as e:
logger.error(f'error occured during artist retrieval - {e}')
return 0

View File

@ -5,7 +5,7 @@ import json
from spotframework.net.network import Network as Spotnet
from spotframework.engine.playlistengine import PlaylistEngine
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
logger = logging.getLogger(__name__)
@ -29,7 +29,11 @@ class Stats(Cmd):
if in_string is None or len(in_string) < 2:
in_string = input('uri group/uri>')
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
try: