updated to playlist engine sources framework, added library tracks backend support

This commit is contained in:
aj 2019-09-23 23:12:26 +01:00
parent 9d763be6c1
commit 5909229d69
3 changed files with 28 additions and 23 deletions

View File

@ -136,7 +136,7 @@ def auth():
{ {
'client_id': client_id, 'client_id': client_id,
'response_type': 'code', 'response_type': 'code',
'scope': 'playlist-modify-public playlist-modify-private playlist-read-private user-modify-playback-state', 'scope': 'playlist-modify-public playlist-modify-private playlist-read-private user-modify-playback-state user-library-read',
'redirect_uri': 'https://spotify.sarsoo.xyz/auth/spotify/token' 'redirect_uri': 'https://spotify.sarsoo.xyz/auth/spotify/token'
} }
) )

View File

@ -3,7 +3,7 @@ from google.cloud import firestore
import datetime import datetime
import logging import logging
from spotframework.engine.playlistengine import PlaylistEngine from spotframework.engine.playlistengine import PlaylistEngine, PlaylistSource, RecommendationSource
from spotframework.engine.processor.shuffle import Shuffle from spotframework.engine.processor.shuffle import Shuffle
from spotframework.engine.processor.sort import SortReleaseDate from spotframework.engine.processor.sort import SortReleaseDate
from spotframework.engine.processor.deduplicate import DeduplicateByID from spotframework.engine.processor.deduplicate import DeduplicateByID
@ -60,7 +60,6 @@ def play_user_playlist(username,
user_dict['access_token'])) user_dict['access_token']))
engine = PlaylistEngine(net) engine = PlaylistEngine(net)
engine.load_user_playlists()
player = Player(net) player = Player(net)
@ -80,20 +79,21 @@ def play_user_playlist(username,
submit_parts = [i for i in {j for j in submit_parts}] submit_parts = [i for i in {j for j in submit_parts}]
params = [
PlaylistSource.Params(names=submit_parts, processors=processors)
]
if include_recommendations:
params.append(RecommendationSource.Params(recommendation_limit=int(recommendation_sample)))
if playlist_type == 'recents': if playlist_type == 'recents':
boundary_date = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=int(day_boundary)) boundary_date = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=int(day_boundary))
tracks = engine.get_recent_playlist(boundary_date, tracks = engine.get_recent_playlist(params=params,
submit_parts, boundary_date=boundary_date,
processors,
include_recommendations=include_recommendations,
recommendation_limit=int(recommendation_sample),
add_this_month=add_this_month, add_this_month=add_this_month,
add_last_month=add_last_month) add_last_month=add_last_month)
else: else:
tracks = engine.make_playlist(submit_parts, tracks = engine.make_playlist(params=params)
processors,
include_recommendations=include_recommendations,
recommendation_limit=int(recommendation_sample))
player.play(tracks=tracks) player.play(tracks=tracks)

View File

@ -3,7 +3,7 @@ from google.cloud import firestore
import datetime import datetime
import logging import logging
from spotframework.engine.playlistengine import PlaylistEngine from spotframework.engine.playlistengine import PlaylistEngine, PlaylistSource, RecommendationSource, LibraryTrackSource
from spotframework.engine.processor.shuffle import Shuffle from spotframework.engine.processor.shuffle import Shuffle
from spotframework.engine.processor.sort import SortReleaseDate from spotframework.engine.processor.sort import SortReleaseDate
from spotframework.engine.processor.deduplicate import DeduplicateByID from spotframework.engine.processor.deduplicate import DeduplicateByID
@ -54,7 +54,6 @@ def run_user_playlist(username, playlist_name):
user_dict['access_token'])) user_dict['access_token']))
engine = PlaylistEngine(net) engine = PlaylistEngine(net)
engine.load_user_playlists()
processors = [DeduplicateByID()] processors = [DeduplicateByID()]
@ -66,21 +65,27 @@ def run_user_playlist(username, playlist_name):
part_generator = PartGenerator(user_id=users[0].id) part_generator = PartGenerator(user_id=users[0].id)
submit_parts = part_generator.get_recursive_parts(playlist_dict['name']) submit_parts = part_generator.get_recursive_parts(playlist_dict['name'])
params = [
PlaylistSource.Params(names=submit_parts)
]
if playlist_dict['include_recommendations']:
params.append(RecommendationSource.Params(recommendation_limit=playlist_dict['recommendation_sample']))
if playlist_dict.get('include_library_tracks', False):
params.append(LibraryTrackSource.Params())
if playlist_dict['type'] == 'recents': if playlist_dict['type'] == 'recents':
boundary_date = datetime.datetime.now(datetime.timezone.utc) - \ boundary_date = datetime.datetime.now(datetime.timezone.utc) - \
datetime.timedelta(days=int(playlist_dict['day_boundary'])) datetime.timedelta(days=int(playlist_dict['day_boundary']))
tracks = engine.get_recent_playlist(boundary_date, tracks = engine.get_recent_playlist(params=params,
submit_parts, processors=processors,
processors, boundary_date=boundary_date,
include_recommendations=playlist_dict['include_recommendations'],
recommendation_limit=int(playlist_dict['recommendation_sample']),
add_this_month=playlist_dict.get('add_this_month', False), add_this_month=playlist_dict.get('add_this_month', False),
add_last_month=playlist_dict.get('add_last_month', False)) add_last_month=playlist_dict.get('add_last_month', False))
else: else:
tracks = engine.make_playlist(submit_parts, tracks = engine.make_playlist(params=params,
processors, processors=processors)
include_recommendations=playlist_dict['include_recommendations'],
recommendation_limit=int(playlist_dict['recommendation_sample']))
engine.execute_playlist(tracks, Uri(playlist_dict['uri'])) engine.execute_playlist(tracks, Uri(playlist_dict['uri']))