updated with new service reflecting spotframework model
This commit is contained in:
parent
2b009eb6df
commit
3f142e140e
@ -20,7 +20,7 @@ logger = logging.getLogger(__name__)
|
|||||||
@admin_required
|
@admin_required
|
||||||
def get_tasks(user=None):
|
def get_tasks(user=None):
|
||||||
|
|
||||||
tasks = [i for i in tasker.list_tasks(task_path)]
|
tasks = list(tasker.list_tasks(task_path))
|
||||||
|
|
||||||
urls = {}
|
urls = {}
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
|
@ -9,7 +9,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
from music.api.decorators import login_required, login_or_basic_auth, admin_required, gae_cron, cloud_task
|
from music.api.decorators import login_required, login_or_basic_auth, admin_required, gae_cron, cloud_task
|
||||||
from music.cloud.tasks import update_all_user_playlists, update_playlists, run_user_playlist_task
|
from music.cloud.tasks import update_all_user_playlists, update_playlists, run_user_playlist_task
|
||||||
from music.tasks.run_user_playlist import run_user_playlist as run_user_playlist
|
from music.tasks.run_user_playlist import run_user_playlist
|
||||||
|
|
||||||
from music.model.user import User
|
from music.model.user import User
|
||||||
from music.model.playlist import Playlist
|
from music.model.playlist import Playlist
|
||||||
@ -102,7 +102,7 @@ def playlist_route(user=None):
|
|||||||
if playlist is not None:
|
if playlist is not None:
|
||||||
return jsonify({'error': 'playlist already exists'}), 400
|
return jsonify({'error': 'playlist already exists'}), 400
|
||||||
|
|
||||||
from music.tasks.create_playlist import create_playlist as create_playlist
|
from music.tasks.create_playlist import create_playlist
|
||||||
|
|
||||||
new_db_playlist = Playlist(parent=user.key)
|
new_db_playlist = Playlist(parent=user.key)
|
||||||
|
|
||||||
|
@ -5,9 +5,8 @@ import logging
|
|||||||
from music.api.decorators import login_or_basic_auth, spotify_link_required
|
from music.api.decorators import login_or_basic_auth, spotify_link_required
|
||||||
import music.db.database as database
|
import music.db.database as database
|
||||||
|
|
||||||
from spotframework.model.track import SpotifyTrack
|
from spotframework.model.track import TrackFull, Context
|
||||||
from spotframework.model.uri import Uri
|
from spotframework.model.uri import Uri
|
||||||
from spotframework.model.service import Context
|
|
||||||
from spotframework.player.player import Player
|
from spotframework.player.player import Player
|
||||||
|
|
||||||
blueprint = Blueprint('player_api', __name__)
|
blueprint = Blueprint('player_api', __name__)
|
||||||
@ -57,13 +56,13 @@ def play(user=None):
|
|||||||
elif 'tracks' in request_json:
|
elif 'tracks' in request_json:
|
||||||
try:
|
try:
|
||||||
uris = [Uri(i) for i in request_json['tracks']]
|
uris = [Uri(i) for i in request_json['tracks']]
|
||||||
uris = [SpotifyTrack.wrap(uri=i) for i in uris if i.object_type == Uri.ObjectType.track]
|
|
||||||
|
|
||||||
|
# TODO check uri object type
|
||||||
if len(uris) > 0:
|
if len(uris) > 0:
|
||||||
net = database.get_authed_spotify_network(user)
|
net = database.get_authed_spotify_network(user)
|
||||||
|
|
||||||
player = Player(net)
|
player = Player(net)
|
||||||
player.play(tracks=uris, device_name=request_json.get('device_name', None))
|
player.play(uris=uris, device_name=request_json.get('device_name', None))
|
||||||
|
|
||||||
logger.info(f'played tracks')
|
logger.info(f'played tracks')
|
||||||
return jsonify({'message': 'played', 'status': 'success'}), 200
|
return jsonify({'message': 'played', 'status': 'success'}), 200
|
||||||
|
@ -10,12 +10,12 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def create_playlist(user, name):
|
def create_playlist(user, name):
|
||||||
logger.info(f'creating spotify playlist for {user.username} / {name}')
|
|
||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
logger.error(f'{user.username} not provided')
|
logger.error(f'username not provided')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
logger.info(f'creating spotify playlist for {user.username} / {name}')
|
||||||
net = database.get_authed_spotify_network(user)
|
net = database.get_authed_spotify_network(user)
|
||||||
|
|
||||||
playlist = net.create_playlist(net.user.username, name)
|
playlist = net.create_playlist(net.user.username, name)
|
||||||
|
@ -4,7 +4,7 @@ import random
|
|||||||
|
|
||||||
import spotframework.util.monthstrings as monthstrings
|
import spotframework.util.monthstrings as monthstrings
|
||||||
from spotframework.model.uri import Uri
|
from spotframework.model.uri import Uri
|
||||||
from spotframework.filter import remove_local
|
from spotframework.filter import remove_local, get_track_objects
|
||||||
from spotframework.filter.added import added_after
|
from spotframework.filter.added import added_after
|
||||||
from spotframework.filter.sort import sort_by_release_date
|
from spotframework.filter.sort import sort_by_release_date
|
||||||
from spotframework.filter.deduplicate import deduplicate_by_name
|
from spotframework.filter.deduplicate import deduplicate_by_name
|
||||||
@ -132,12 +132,16 @@ def run_user_playlist(username, playlist_name):
|
|||||||
|
|
||||||
# RECOMMENDATIONS
|
# RECOMMENDATIONS
|
||||||
if playlist.include_recommendations:
|
if playlist.include_recommendations:
|
||||||
recommendations = net.get_recommendations(tracks=[i.uri.object_id for i
|
recommendations = net.get_recommendations(tracks=[i.uri.object_id for i, j
|
||||||
in random.sample(playlist_tracks, k=min(5, len(playlist_tracks)))
|
in zip(*get_track_objects(
|
||||||
|
random.sample(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) > 0:
|
if recommendations and len(recommendations.tracks) > 0:
|
||||||
playlist_tracks += recommendations
|
playlist_tracks += recommendations.tracks
|
||||||
else:
|
else:
|
||||||
logger.error(f'error getting recommendations {username} / {playlist_name}')
|
logger.error(f'error getting recommendations {username} / {playlist_name}')
|
||||||
|
|
||||||
@ -145,7 +149,8 @@ def run_user_playlist(username, playlist_name):
|
|||||||
playlist_tracks = deduplicate_by_name(playlist_tracks)
|
playlist_tracks = deduplicate_by_name(playlist_tracks)
|
||||||
|
|
||||||
# EXECUTE
|
# EXECUTE
|
||||||
resp = net.replace_playlist_tracks(uri_string=playlist.uri, uris=[i.uri for i in playlist_tracks])
|
resp = net.replace_playlist_tracks(uri_string=playlist.uri, uris=[i.uri for i, j
|
||||||
|
in zip(*get_track_objects(playlist_tracks))])
|
||||||
if resp:
|
if resp:
|
||||||
if playlist.description_overwrite:
|
if playlist.description_overwrite:
|
||||||
string = playlist.description_overwrite
|
string = playlist.description_overwrite
|
||||||
|
Loading…
Reference in New Issue
Block a user