Esempio n. 1
0
        public async Task <string> StartPartyWithSeedSongsAsync(List <string> seedTrackUris, PartyGoer host)
        {
            Party newParty = new Party(host);

            List <Song> playlistSongs = await _spotifyHttpClient.GetRecommendedSongsAsync(host.Id, seedTrackUris, 0);

            newParty.Playlist = new Playlist(playlistSongs, newParty.Listeners, newParty.PartyCode);

            _partyRepository.CreateParty(newParty);

            await newParty.Playlist.StartAsync();

            return(newParty.PartyCode);
        }
Esempio n. 2
0
        private async Task<List<Track>> GenerateNewPlaylist(Party party)
        {
            if (party.Playlist.History.Count > 0)
            {
                return await _spotifyHttpClient.GetRecommendedSongsAsync(party.Listeners.ElementAt(0).Id, party.Playlist.History.ToList().GetRandomNItems(5).Select(p => p.Uri).ToList(), 0);
            }
            else
            {
                List<Track> songs = new List<Track>();

                foreach (PartyGoer listener in party.Listeners)
                {
                    songs.AddRange(await _partyGoerService.GetRecommendedSongsAsync(listener.Id, 2));
                }

                return await _spotifyHttpClient.GetRecommendedSongsAsync(party.Listeners.ElementAt(0).Id, songs.GetRandomNItems(5).Select(p => p.Uri).ToList(), 0);
            }
        }
Esempio n. 3
0
        public async Task HandleAsync(PlaylistEnded args)
        {
            await _logService.LogAppActivityAsync($"Playlist has ended for party with code {args.PartyCode}. Sending to all listeners");

            Party party = await _partyService.GetPartyWithCodeAsync(args.PartyCode);

            if (party.Listeners.Count < 1)
            {
                await party.DeletePlaylistAsync();

                await _partyService.EndPartyAsync(args.PartyCode);

                return;
            }

            List <Song> songs = new List <Song>();

            foreach (PartyGoer listener in party.Listeners)
            {
                songs.AddRange(await _partyGoerService.GetRecommendedSongsAsync(listener.Id, 5));
            }

            List <Song> playlistSongs = await _spotifyHttpClient.GetRecommendedSongsAsync(party.Listeners.ElementAt(0).Id, songs.GetRandomNItems(5).Select(p => p.TrackUri).ToList(), 0);

            // If there is atleast 1 person still in the party, regenerate the playlist
            party.Playlist = new Playlist(playlistSongs, party.Listeners, party.PartyCode, party.Playlist.History);

            await party.Playlist.StartAsync();

            await _partyHubContext.Clients.Group(args.PartyCode).SendAsync("UpdatePartyView",
                                                                           new
            {
                Song     = party.Playlist.CurrentSong,
                Position = party.Playlist.CurrentPositionInSong()
            },
                                                                           party.Playlist.History,
                                                                           party.Playlist.Queue
                                                                           );
        }