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)
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:
logger.exception(f'error occured during {_playlist.name} / {user.username} playlist retrieval')
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)
total = net.get_scrobble_count_from_date(input_date=date.today())
total = net.count_scrobbles_from_date(input_date=date.today())
return jsonify({
'username': net.username,

View File

@ -41,7 +41,7 @@ def play(user=None):
elif 'playlist_name' in request_json:
net = database.get_authed_spotify_network(user)
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)
if playlist_to_play is not None:

View File

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

View File

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

View File

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

View File

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

14
package-lock.json generated
View File

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

View File

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