concise method names
This commit is contained in:
parent
42d7158f27
commit
41ae299be6
@ -6,7 +6,7 @@ import logging
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def get_chart_of_spotify_tracks(spotnet: SpotNetwork,
|
def map_lastfm_track_chart_to_spotify(spotnet: SpotNetwork,
|
||||||
fmnet: FmNetwork,
|
fmnet: FmNetwork,
|
||||||
period: FmNetwork.Range,
|
period: FmNetwork.Range,
|
||||||
limit: int,
|
limit: int,
|
||||||
@ -14,7 +14,7 @@ def get_chart_of_spotify_tracks(spotnet: SpotNetwork,
|
|||||||
logger.info(f'pulling {period.name} chart')
|
logger.info(f'pulling {period.name} chart')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
chart = fmnet.get_top_tracks(period=period, username=username, limit=limit)
|
chart = fmnet.top_tracks(period=period, username=username or fmnet.username, limit=limit)
|
||||||
|
|
||||||
spotify_chart = []
|
spotify_chart = []
|
||||||
for track in chart:
|
for track in chart:
|
||||||
@ -22,7 +22,7 @@ def get_chart_of_spotify_tracks(spotnet: SpotNetwork,
|
|||||||
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=1).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:
|
||||||
|
@ -5,7 +5,7 @@ from spotframework.model.uri import Uri
|
|||||||
from spotframework.engine.playlistengine import TrackSource, SourceParameter
|
from spotframework.engine.playlistengine import TrackSource, SourceParameter
|
||||||
from spotframework.engine.processor.abstract import AbstractProcessor
|
from spotframework.engine.processor.abstract import AbstractProcessor
|
||||||
|
|
||||||
from spotfm.chart import get_chart_of_spotify_tracks
|
from spotfm.chart import map_lastfm_track_chart_to_spotify
|
||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
import logging
|
import logging
|
||||||
@ -34,7 +34,7 @@ class ChartSource(TrackSource):
|
|||||||
# TODO add processor support?
|
# TODO add processor support?
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return get_chart_of_spotify_tracks(spotnet=self.net,
|
return map_lastfm_track_chart_to_spotify(spotnet=self.net,
|
||||||
fmnet=self.fmnet,
|
fmnet=self.fmnet,
|
||||||
period=params.chart_range,
|
period=params.chart_range,
|
||||||
limit=params.limit)
|
limit=params.limit)
|
||||||
|
@ -44,7 +44,7 @@ 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:
|
try:
|
||||||
playlist.tracks = self.spotnet.get_playlist_tracks(uri=playlist.uri)
|
playlist.tracks = self.spotnet.playlist_tracks(uri=playlist.uri)
|
||||||
except SpotifyNetworkException:
|
except SpotifyNetworkException:
|
||||||
logger.exception(f'error occured during playlist track retrieval')
|
logger.exception(f'error occured during playlist track retrieval')
|
||||||
return 0
|
return 0
|
||||||
@ -53,7 +53,7 @@ class Counter:
|
|||||||
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')
|
||||||
try:
|
try:
|
||||||
playlist = self.spotnet.get_playlist(uri=uri, tracks=True)
|
playlist = self.spotnet.playlist(uri=uri, tracks=True)
|
||||||
except SpotifyNetworkException:
|
except SpotifyNetworkException:
|
||||||
logger.exception(f'error occured during playlist retrieval')
|
logger.exception(f'error occured during playlist retrieval')
|
||||||
return 0
|
return 0
|
||||||
@ -91,13 +91,13 @@ class Counter:
|
|||||||
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:
|
try:
|
||||||
track = self.spotnet.get_track(uri=uri)
|
track = self.spotnet.track(uri=uri)
|
||||||
except SpotifyNetworkException:
|
except SpotifyNetworkException:
|
||||||
logger.exception(f'error occured during track retrieval')
|
logger.exception(f'error occured during track retrieval')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fmtrack = self.fmnet.get_track(name=track.name,
|
fmtrack = self.fmnet.track(name=track.name,
|
||||||
artist=track.artists[0].name,
|
artist=track.artists[0].name,
|
||||||
username=username or self.fmnet.username)
|
username=username or self.fmnet.username)
|
||||||
if fmtrack is not None:
|
if fmtrack is not None:
|
||||||
@ -118,13 +118,13 @@ class Counter:
|
|||||||
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:
|
try:
|
||||||
album = self.spotnet.get_album(uri=uri)
|
album = self.spotnet.album(uri=uri)
|
||||||
except SpotifyNetworkException:
|
except SpotifyNetworkException:
|
||||||
logger.exception(f'error occured during album retrieval')
|
logger.exception(f'error occured during album retrieval')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fmalbum = self.fmnet.get_album(name=album.name,
|
fmalbum = self.fmnet.album(name=album.name,
|
||||||
artist=album.artists[0].name,
|
artist=album.artists[0].name,
|
||||||
username=username or self.fmnet.username)
|
username=username or self.fmnet.username)
|
||||||
if fmalbum is not None:
|
if fmalbum is not None:
|
||||||
@ -145,13 +145,13 @@ class Counter:
|
|||||||
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:
|
try:
|
||||||
artist = self.spotnet.get_artist(uri=uri)
|
artist = self.spotnet.artist(uri=uri)
|
||||||
except SpotifyNetworkException:
|
except SpotifyNetworkException:
|
||||||
logger.exception(f'error occured during artist retrieval')
|
logger.exception(f'error occured during artist retrieval')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fmartist = self.fmnet.get_artist(name=artist.name, username=username or self.fmnet.username)
|
fmartist = self.fmnet.artist(name=artist.name, username=username or self.fmnet.username)
|
||||||
if fmartist is not None:
|
if fmartist is not None:
|
||||||
return fmartist.user_scrobbles
|
return fmartist.user_scrobbles
|
||||||
else:
|
else:
|
||||||
|
@ -30,7 +30,7 @@ class Stats(Cmd):
|
|||||||
in_string = input('uri group/uri>')
|
in_string = input('uri group/uri>')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user_total = self.fmnet.get_user_scrobble_count()
|
user_total = self.fmnet.user_scrobble_count()
|
||||||
except LastFMNetworkException:
|
except LastFMNetworkException:
|
||||||
logger.exception(f'error occured during scrobble count retrieval')
|
logger.exception(f'error occured during scrobble count retrieval')
|
||||||
user_total = 0
|
user_total = 0
|
||||||
|
@ -61,7 +61,7 @@ def time_artist(spotnet: SpotNet, artist: str, username: str, fmnet: FmNet = Non
|
|||||||
return_tracks: bool = False) -> int:
|
return_tracks: bool = False) -> int:
|
||||||
logger.info(f'timing {artist} for {username}')
|
logger.info(f'timing {artist} for {username}')
|
||||||
|
|
||||||
fmtracks = LibraryScraper.get_scrobbled_tracks(username=username, artist=artist, whole_track=False,
|
fmtracks = LibraryScraper.artist_tracks(username=username, artist=artist, whole_track=False,
|
||||||
from_date=from_date, to_date=to_date, date_preset=date_preset)
|
from_date=from_date, to_date=to_date, date_preset=date_preset)
|
||||||
|
|
||||||
return time_track_collection(tracks=fmtracks, spotnet=spotnet, username=username, fmnet=fmnet,
|
return time_track_collection(tracks=fmtracks, spotnet=spotnet, username=username, fmnet=fmnet,
|
||||||
@ -73,7 +73,7 @@ def time_album(spotnet: SpotNet, artist: str, album: str, username: str, fmnet:
|
|||||||
return_tracks: bool = False) -> int:
|
return_tracks: bool = False) -> int:
|
||||||
logger.info(f'timing {album} / {artist} for {username}')
|
logger.info(f'timing {album} / {artist} for {username}')
|
||||||
|
|
||||||
fmtracks = LibraryScraper.get_albums_tracks(username=username, artist=artist, album=album, whole_track=False,
|
fmtracks = LibraryScraper.album_tracks(username=username, artist=artist, album=album, whole_track=False,
|
||||||
from_date=from_date, to_date=to_date, date_preset=date_preset)
|
from_date=from_date, to_date=to_date, date_preset=date_preset)
|
||||||
|
|
||||||
return time_track_collection(tracks=fmtracks, spotnet=spotnet, username=username, fmnet=fmnet,
|
return time_track_collection(tracks=fmtracks, spotnet=spotnet, username=username, fmnet=fmnet,
|
||||||
@ -85,7 +85,7 @@ def time_track(spotnet: SpotNet, artist: str, track: str, username: str, fmnet:
|
|||||||
return_tracks: bool = False) -> int:
|
return_tracks: bool = False) -> int:
|
||||||
logger.info(f'timing {track} / {artist} for {username}')
|
logger.info(f'timing {track} / {artist} for {username}')
|
||||||
|
|
||||||
fmtracks = LibraryScraper.get_track_scrobbles(username=username, artist=artist, track=track, whole_track=False,
|
fmtracks = LibraryScraper.track_scrobbles(username=username, artist=artist, track=track, whole_track=False,
|
||||||
from_date=from_date, to_date=to_date, date_preset=date_preset)
|
from_date=from_date, to_date=to_date, date_preset=date_preset)
|
||||||
if fmtracks is not None:
|
if fmtracks is not None:
|
||||||
if len(fmtracks) == 0:
|
if len(fmtracks) == 0:
|
||||||
@ -112,7 +112,7 @@ def time_track_collection(tracks, spotnet: SpotNet, username: str, fmnet: FmNet
|
|||||||
logger.error(f'no track returned for search {track.name} / {track.artist.name} / {username}'
|
logger.error(f'no track returned for search {track.name} / {track.artist.name} / {username}'
|
||||||
f', pulling last.fm track')
|
f', pulling last.fm track')
|
||||||
|
|
||||||
fmtrack = fmnet.get_track(name=track.name, artist=track.artist.name, username=username)
|
fmtrack = fmnet.track(name=track.name, artist=track.artist.name, username=username)
|
||||||
|
|
||||||
if fmtrack is not None and fmtrack.duration is not None and fmtrack.duration > 0:
|
if fmtrack is not None and fmtrack.duration is not None and fmtrack.duration > 0:
|
||||||
track_pairs.append((track, fmtrack))
|
track_pairs.append((track, fmtrack))
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from spotframework.net.network import Network as Spotnet, NetworkUser
|
from spotframework.net.network import Network as Spotnet, NetworkUser
|
||||||
from fmframework.net.network import Network as Fmnet
|
from fmframework.net.network import Network as Fmnet
|
||||||
from spotfm.timer import time_artist
|
from spotfm.timer import time, seconds_to_time_str
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@ -44,20 +44,11 @@ while len(fmuser) == 0:
|
|||||||
|
|
||||||
fmnet = Fmnet(username=fmuser, api_key=fmclient)
|
fmnet = Fmnet(username=fmuser, api_key=fmclient)
|
||||||
|
|
||||||
def convert(seconds):
|
top_artists = fmnet.top_artists(period=Fmnet.Range.OVERALL, limit=10)
|
||||||
seconds = seconds % (24 * 3600)
|
|
||||||
hour = seconds // 3600
|
|
||||||
seconds %= 3600
|
|
||||||
minutes = seconds // 60
|
|
||||||
seconds %= 60
|
|
||||||
|
|
||||||
return "%d:%02d:%02d" % (hour, minutes, seconds)
|
|
||||||
|
|
||||||
top_artists = fmnet.get_top_artists(period=Fmnet.Range.OVERALL, limit=10)
|
|
||||||
|
|
||||||
artist_counts = dict()
|
artist_counts = dict()
|
||||||
for artist in top_artists:
|
for artist in top_artists:
|
||||||
artist_counts[artist.name] = time_artist(spotnet=spotnet, fmnet=fmnet, artist=artist.name, username=fmnet.username)
|
artist_counts[artist.name] = time(spotnet=spotnet, fmnet=fmnet, artist=artist.name, username=fmnet.username)
|
||||||
|
|
||||||
for name, count in artist_counts.items():
|
for name, count in artist_counts.items():
|
||||||
print(name, f'{count}ms,', f'{count/1000}s,', convert(count/1000))
|
print(name, f'{count}ms,', f'{count/1000}s,', seconds_to_time_str(milliseconds=count))
|
||||||
|
Loading…
Reference in New Issue
Block a user