concise method names

This commit is contained in:
aj 2020-08-12 09:30:26 +01:00
parent 51a8eb1aa5
commit 5096c3c2a9
9 changed files with 55 additions and 55 deletions

View File

@ -309,7 +309,7 @@ def image(user=None):
net = database.get_authed_spotify_network(user) net = database.get_authed_spotify_network(user)
try: try:
return jsonify({'images': net.get_playlist(uri=_playlist.uri).images, 'status': 'success'}), 200 return jsonify({'images': net.playlist(uri=_playlist.uri).images, 'status': 'success'}), 200
except SpotifyNetworkException as e: except SpotifyNetworkException as e:
logger.exception(f'error occured during {_playlist.name} / {user.username} playlist retrieval') logger.exception(f'error occured during {_playlist.name} / {user.username} playlist retrieval')
return jsonify({'error': f"spotify error occured: {e.http_code}"}), 404 return jsonify({'error': f"spotify error occured: {e.http_code}"}), 404

View File

@ -17,7 +17,7 @@ def daily_scrobbles(user=None):
net = database.get_authed_lastfm_network(user) net = database.get_authed_lastfm_network(user)
total = net.get_scrobble_count_from_date(input_date=date.today()) total = net.count_scrobbles_from_date(input_date=date.today())
return jsonify({ return jsonify({
'username': net.username, 'username': net.username,

View File

@ -41,7 +41,7 @@ def play(user=None):
elif 'playlist_name' in request_json: elif 'playlist_name' in request_json:
net = database.get_authed_spotify_network(user) net = database.get_authed_spotify_network(user)
try: try:
playlists = net.get_playlists() playlists = net.playlists()
playlist_to_play = next((i for i in playlists if i.name == request_json['playlist_name']), None) playlist_to_play = next((i for i in playlists if i.name == request_json['playlist_name']), None)
if playlist_to_play is not None: if playlist_to_play is not None:

View File

@ -51,7 +51,7 @@ def count(user=None):
}), 200 }), 200
elif playlist_name: elif playlist_name:
try: try:
playlists = spotnet.get_playlists() playlists = spotnet.playlists()
playlist = next((i for i in playlists if i.name == playlist_name), None) playlist = next((i for i in playlists if i.name == playlist_name), None)
if playlist is not None: if playlist is not None:

View File

@ -36,14 +36,14 @@ def refresh_lastfm_track_stats(username, playlist_name):
return return
try: try:
spotify_playlist = spotnet.get_playlist(uri=playlist.uri) spotify_playlist = spotnet.playlist(uri=playlist.uri)
except SpotifyNetworkException: except SpotifyNetworkException:
logger.exception(f'error retrieving spotify playlist {username} / {playlist_name}') logger.exception(f'error retrieving spotify playlist {username} / {playlist_name}')
return return
track_count = counter.count_playlist(playlist=spotify_playlist) track_count = counter.count_playlist(playlist=spotify_playlist)
try: try:
user_count = fmnet.get_user_scrobble_count() user_count = fmnet.user_scrobble_count()
if user_count > 0: if user_count > 0:
percent = round((track_count * 100) / user_count, 2) percent = round((track_count * 100) / user_count, 2)
else: else:
@ -82,14 +82,14 @@ def refresh_lastfm_album_stats(username, playlist_name):
return return
try: try:
spotify_playlist = spotnet.get_playlist(uri=playlist.uri) spotify_playlist = spotnet.playlist(uri=playlist.uri)
except SpotifyNetworkException: except SpotifyNetworkException:
logger.exception(f'error retrieving spotify playlist {username} / {playlist_name}') logger.exception(f'error retrieving spotify playlist {username} / {playlist_name}')
return return
album_count = counter.count_playlist(playlist=spotify_playlist, query_album=True) album_count = counter.count_playlist(playlist=spotify_playlist, query_album=True)
try: try:
user_count = fmnet.get_user_scrobble_count() user_count = fmnet.user_scrobble_count()
if user_count > 0: if user_count > 0:
album_percent = round((album_count * 100) / user_count, 2) album_percent = round((album_count * 100) / user_count, 2)
else: else:
@ -128,14 +128,14 @@ def refresh_lastfm_artist_stats(username, playlist_name):
return return
try: try:
spotify_playlist = spotnet.get_playlist(uri=playlist.uri) spotify_playlist = spotnet.playlist(uri=playlist.uri)
except SpotifyNetworkException: except SpotifyNetworkException:
logger.exception(f'error retrieving spotify playlist {username} / {playlist_name}') logger.exception(f'error retrieving spotify playlist {username} / {playlist_name}')
return return
artist_count = counter.count_playlist(playlist=spotify_playlist, query_artist=True) artist_count = counter.count_playlist(playlist=spotify_playlist, query_artist=True)
try: try:
user_count = fmnet.get_user_scrobble_count() user_count = fmnet.user_scrobble_count()
if user_count > 0: if user_count > 0:
artist_percent = round((artist_count * 100) / user_count, 2) artist_percent = round((artist_count * 100) / user_count, 2)
else: else:

View File

@ -11,7 +11,7 @@ from spotframework.filter.deduplicate import deduplicate_by_name
from spotframework.net.network import SpotifyNetworkException from spotframework.net.network import SpotifyNetworkException
from fmframework.net.network import Network from fmframework.net.network import Network
from spotfm.chart import get_chart_of_spotify_tracks from spotfm.chart import map_lastfm_track_chart_to_spotify
import music.db.database as database import music.db.database as database
from music.db.part_generator import PartGenerator from music.db.part_generator import PartGenerator
@ -51,7 +51,7 @@ def run_user_playlist(username, playlist_name):
return return
try: try:
user_playlists = net.get_user_playlists() user_playlists = net.user_playlists()
except SpotifyNetworkException: except SpotifyNetworkException:
logger.exception(f'error occured while retrieving playlists {username} / {playlist_name}') logger.exception(f'error occured while retrieving playlists {username} / {playlist_name}')
return return
@ -70,15 +70,7 @@ def run_user_playlist(username, playlist_name):
for part_name in part_names: for part_name in part_names:
try: # attempt to cast to uri try: # attempt to cast to uri
uri = Uri(part_name) uri = Uri(part_name)
log_name = uri
try:
_tracks = net.get_playlist_tracks(uri=uri)
if _tracks and len(_tracks) > 0:
playlist_tracks += _tracks
else:
logger.warning(f'no tracks returned for {uri} {username} / {playlist_name}')
except SpotifyNetworkException:
logger.exception(f'error occured while retrieving {uri} {username} / {playlist_name}')
except ValueError: # is a playlist name except ValueError: # is a playlist name
part_playlist = next((i for i in user_playlists if i.name == part_name), None) part_playlist = next((i for i in user_playlists if i.name == part_name), None)
@ -86,21 +78,24 @@ def run_user_playlist(username, playlist_name):
logger.warning(f'playlist {part_name} not found {username} / {playlist_name}') logger.warning(f'playlist {part_name} not found {username} / {playlist_name}')
continue continue
try: uri = part_playlist.uri
part_playlist_tracks = net.get_playlist_tracks(uri=part_playlist.uri) log_name = part_playlist.name
if part_playlist_tracks and len(part_playlist_tracks) > 0:
playlist_tracks += part_playlist_tracks
else:
logger.warning(f'no tracks returned for {part_playlist.name} {username} / {playlist_name}')
except SpotifyNetworkException:
logger.exception(f'error occured while retrieving {part_name} {username} / {playlist_name}')
playlist_tracks = remove_local(playlist_tracks) try:
_tracks = net.playlist_tracks(uri=uri)
if _tracks and len(_tracks) > 0:
playlist_tracks += _tracks
else:
logger.warning(f'no tracks returned for {log_name} {username} / {playlist_name}')
except SpotifyNetworkException:
logger.exception(f'error occured while retrieving {log_name} {username} / {playlist_name}')
playlist_tracks = list(remove_local(playlist_tracks))
# LIBRARY # LIBRARY
if playlist.include_library_tracks: if playlist.include_library_tracks:
try: try:
library_tracks = net.get_library_tracks() library_tracks = net.saved_tracks()
if library_tracks and len(library_tracks) > 0: if library_tracks and len(library_tracks) > 0:
playlist_tracks += library_tracks playlist_tracks += library_tracks
else: else:
@ -112,7 +107,7 @@ def run_user_playlist(username, playlist_name):
if playlist.type == 'recents': if playlist.type == 'recents':
boundary_date = datetime.datetime.now(datetime.timezone.utc) - \ boundary_date = datetime.datetime.now(datetime.timezone.utc) - \
datetime.timedelta(days=int(playlist.day_boundary)) datetime.timedelta(days=int(playlist.day_boundary))
playlist_tracks = added_after(playlist_tracks, boundary_date) playlist_tracks = list(added_after(playlist_tracks, boundary_date))
elif playlist.type == 'fmchart': elif playlist.type == 'fmchart':
if user.lastfm_username is None: if user.lastfm_username is None:
logger.error(f'no associated last.fm username, chart source skipped {username} / {playlist_name}') logger.error(f'no associated last.fm username, chart source skipped {username} / {playlist_name}')
@ -126,7 +121,7 @@ def run_user_playlist(username, playlist_name):
fmnet = database.get_authed_lastfm_network(user) fmnet = database.get_authed_lastfm_network(user)
if fmnet is not None: if fmnet is not None:
chart_tracks = get_chart_of_spotify_tracks(spotnet=net, chart_tracks = map_lastfm_track_chart_to_spotify(spotnet=net,
fmnet=fmnet, fmnet=fmnet,
period=chart_range, period=chart_range,
limit=playlist.chart_limit) limit=playlist.chart_limit)
@ -147,12 +142,12 @@ def run_user_playlist(username, playlist_name):
# RECOMMENDATIONS # RECOMMENDATIONS
if playlist.include_recommendations: if playlist.include_recommendations:
try: try:
recommendations = net.get_recommendations(tracks=[i.uri.object_id for i, j recommendations = net.recommendations(tracks=[i.uri.object_id for i, j
in zip(*get_track_objects( in get_track_objects(
random.sample(playlist_tracks, random.sample(playlist_tracks,
k=min(5, len(playlist_tracks)) k=min(5, len(playlist_tracks))
) )
)) )
if i.uri.object_type == Uri.ObjectType.track], if i.uri.object_type == Uri.ObjectType.track],
response_limit=playlist.recommendation_sample) response_limit=playlist.recommendation_sample)
if recommendations and len(recommendations.tracks) > 0: if recommendations and len(recommendations.tracks) > 0:
@ -167,8 +162,7 @@ def run_user_playlist(username, playlist_name):
# EXECUTE # EXECUTE
try: try:
net.replace_playlist_tracks(uri=playlist.uri, uris=[i.uri for i, j net.replace_playlist_tracks(uri=playlist.uri, uris=[i.uri for i, j in get_track_objects(playlist_tracks)])
in zip(*get_track_objects(playlist_tracks))])
if playlist.description_overwrite: if playlist.description_overwrite:
string = playlist.description_overwrite string = playlist.description_overwrite

View File

@ -36,7 +36,7 @@ def update_tag(username, tag_id):
tag_count = 0 tag_count = 0
try: try:
user_scrobbles = net.get_user_scrobble_count() user_scrobbles = net.user_scrobble_count()
except LastFMNetworkException: except LastFMNetworkException:
logger.exception(f'error retrieving scrobble count {username} / {tag_id}') logger.exception(f'error retrieving scrobble count {username} / {tag_id}')
user_scrobbles = 0 user_scrobbles = 0
@ -44,7 +44,7 @@ def update_tag(username, tag_id):
artists = [] artists = []
for artist in tag.artists: for artist in tag.artists:
try: try:
net_artist = net.get_artist(name=artist['name']) net_artist = net.artist(name=artist['name'])
if net_artist is not None: if net_artist is not None:
artist['count'] = net_artist.user_scrobbles artist['count'] = net_artist.user_scrobbles
@ -57,7 +57,7 @@ def update_tag(username, tag_id):
albums = [] albums = []
for album in tag.albums: for album in tag.albums:
try: try:
net_album = net.get_album(name=album['name'], artist=album['artist']) net_album = net.album(name=album['name'], artist=album['artist'])
if net_album is not None: if net_album is not None:
album['count'] = net_album.user_scrobbles album['count'] = net_album.user_scrobbles
@ -72,7 +72,7 @@ def update_tag(username, tag_id):
tracks = [] tracks = []
for track in tag.tracks: for track in tag.tracks:
try: try:
net_track = net.get_track(name=track['name'], artist=track['artist']) net_track = net.track(name=track['name'], artist=track['artist'])
if net_track is not None: if net_track is not None:
track['count'] = net_track.user_scrobbles track['count'] = net_track.user_scrobbles

14
package-lock.json generated
View File

@ -42,16 +42,16 @@
} }
}, },
"@babel/core": { "@babel/core": {
"version": "7.11.0", "version": "7.11.1",
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.11.0.tgz", "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.11.1.tgz",
"integrity": "sha512-mkLq8nwaXmDtFmRkQ8ED/eA2CnVw4zr7dCztKalZXBvdK5EeNUAesrrwUqjQEzFgomJssayzB0aqlOsP1vGLqg==", "integrity": "sha512-XqF7F6FWQdKGGWAzGELL+aCO1p+lRY5Tj5/tbT3St1G8NaH70jhhDIKknIZaDans0OQBG5wRAldROLHSt44BgQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/code-frame": "^7.10.4", "@babel/code-frame": "^7.10.4",
"@babel/generator": "^7.11.0", "@babel/generator": "^7.11.0",
"@babel/helper-module-transforms": "^7.11.0", "@babel/helper-module-transforms": "^7.11.0",
"@babel/helpers": "^7.10.4", "@babel/helpers": "^7.10.4",
"@babel/parser": "^7.11.0", "@babel/parser": "^7.11.1",
"@babel/template": "^7.10.4", "@babel/template": "^7.10.4",
"@babel/traverse": "^7.11.0", "@babel/traverse": "^7.11.0",
"@babel/types": "^7.11.0", "@babel/types": "^7.11.0",
@ -65,6 +65,12 @@
"source-map": "^0.5.0" "source-map": "^0.5.0"
}, },
"dependencies": { "dependencies": {
"@babel/parser": {
"version": "7.11.3",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.11.3.tgz",
"integrity": "sha512-REo8xv7+sDxkKvoxEywIdsNFiZLybwdI7hcT5uEPyQrSMB4YQ973BfC9OOrD/81MaIjh6UxdulIQXkjmiH3PcA==",
"dev": true
},
"@babel/types": { "@babel/types": {
"version": "7.11.0", "version": "7.11.0",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.11.0.tgz", "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.11.0.tgz",

View File

@ -29,7 +29,7 @@
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.10.5", "@babel/cli": "^7.10.5",
"@babel/core": "^7.11.0", "@babel/core": "^7.11.1",
"@babel/preset-env": "^7.11.0", "@babel/preset-env": "^7.11.0",
"@babel/preset-react": "^7.10.4", "@babel/preset-react": "^7.10.4",
"babel-loader": "^8.1.0", "babel-loader": "^8.1.0",