@@ -245,7 +245,11 @@ async def getTracks(bot: commands.Bot, data: Dict) -> Dict:
245245
246246 payload ["tracks" ] = [ track .track_id for track in (tracks .tracks if isinstance (tracks , Playlist ) else tracks ) ]
247247 return payload
248-
248+
249+ async def searchAndPlay (player : Player , member : Member , data : Dict ) -> None :
250+ payload = await getTracks (player .bot , data )
251+ await addTracks (player , member , payload )
252+
249253async def shuffleTrack (player : Player , member : Member , data : Dict ) -> None :
250254 if not player .is_privileged (member ):
251255 if member in player .shuffle_votes :
@@ -699,6 +703,49 @@ async def updateSettings(bot: commands.Bot, data: Dict) -> None:
699703
700704 await func .update_settings (guild .id , {"$set" : data })
701705
706+ async def getFeaturedPlaylists (bot : commands .Bot , data : Dict ) -> Dict :
707+ locale = data .get ("locale" , "sv_SE" )
708+ limit = data .get ("limit" , 20 )
709+ offset = data .get ("offset" , 0 )
710+
711+ request_url = f"https://api.spotify.com/v1/browse/featured-playlists?locale={ locale } &limit={ max (1 , min (limit , 50 ))} &offset={ max (0 , offset )} "
712+
713+ node = NodePool .get_node ()
714+ result = await node .spotify_client .get_request (request_url )
715+
716+ return {
717+ "op" : "getFeaturedPlaylists" ,
718+ "userId" : data .get ("userId" ),
719+ "callback" : data .get ("callback" ),
720+ "playlists" : [
721+ {
722+ "id" : item .get ("id" ),
723+ "title" : item .get ("name" ),
724+ "description" : item .get ("description" ),
725+ "imageUrl" : item .get ("images" , [{}])[0 ].get ("url" ),
726+ "href" : item .get ("external_urls" , {}).get ("spotify" )
727+ }
728+ for item in result .get ("playlists" , {}).get ("items" , [])
729+ ]
730+ }
731+
732+ async def getCategoryPlaylists (bot : commands .Bot , data : Dict ) -> Dict :
733+ node = NodePool .get_node ()
734+
735+ return {
736+ "op" : "getCategoryPlaylists" ,
737+ "userId" : data .get ("userId" ),
738+ "callback" : data .get ("callback" ),
739+ "playlists" : [
740+ {
741+ "id" : category .id ,
742+ "title" : category .name ,
743+ "imageUrl" : category .icon ,
744+ }
745+ for category in await node .spotify_client .get_categories ()
746+ ]
747+ }
748+
702749METHODS : Dict [str , Union [SystemMethod , PlayerMethod ]] = {
703750 "initBot" : SystemMethod (initBot , credit = 0 ),
704751 "initUser" : SystemMethod (initUser , credit = 2 ),
@@ -725,6 +772,9 @@ async def updateSettings(bot: commands.Bot, data: Dict) -> None:
725772 "updatePosition" : PlayerMethod (updatePosition ),
726773 "toggleAutoplay" : PlayerMethod (toggleAutoplay ),
727774 "updateFilter" : PlayerMethod (updateFilter ),
775+ "searchAndPlay" : PlayerMethod (searchAndPlay , credit = 5 , auto_connect = True ),
776+ "getFeaturedPlaylists" : SystemMethod (getFeaturedPlaylists , credit = 5 ),
777+ "getCategoryPlaylists" : SystemMethod (getCategoryPlaylists , credit = 2 )
728778}
729779
730780async def process_methods (ipc_client , bot : commands .Bot , data : Dict ) -> None :
0 commit comments