예제 #1
0
        private async Task AddSongToPlaylist(Track song, string playlistId)
        {
            var request = ConstructRequestMessage("POST", $"https://api.spotify.com/v1/users/akgjohansson/playlists/{playlistId}/tracks");

            request.Content = new StringContent(JsonConvert.SerializeObject(new { uris = new List <string> {
                                                                                      song.Uri
                                                                                  } }));
            var response = await _client.SendAsync(request);

            LandingPlaylist.Add(song);
        }
예제 #2
0
        public async Task <CurrentStateResponseDto> GetCurrentPlaybackState()
        {
            await MakeSureIdsAreSet();

            var currentPlaybackState = await GetState();

            await UpdatePlaybackState(currentPlaybackState);

            LandingPlaylist = await GetPlaylistTracks(LandingPlaylistId);

            Queue = await GetPlaylistTracks(RuntimeQueuePlaylistId);

            var doublettes = Queue.Where(t => LandingPlaylist.Any(p => p.Id == t.Id));

            foreach (var track in doublettes)
            {
                await RemoveSong(track, RuntimeQueuePlaylistId);
            }
            var playingTrackIndex = GetPlayingIndex(currentPlaybackState, LandingPlaylist);

            if (playingTrackIndex < 0)
            {
                IssueWarning("Starta om spellistan Bröllop_kö!");
            }
            else
            {
                if (playingTrackIndex > 1)
                {
                    await RemoveFirstLandingTrack();

                    if (LandingPlaylist.Count <= LandingListSize)
                    {
                        if (TakeFromQueue && Queue.Count > 0)
                        {
                            await AddQueuedSongToLandingList();
                        }
                        else
                        {
                            await AddBasicSongToLandingList();
                        }
                    }
                    playingTrackIndex = GetPlayingIndex(currentPlaybackState, LandingPlaylist);
                }
            }
            //await RepopulateLandingListIfNeeded(LandingPlaylist);
            var response = currentPlaybackState.ToDto(LandingPlaylist[playingTrackIndex + 1]);

            return(response);
        }
예제 #3
0
        public async Task <IEnumerable <TrackBase> > NextSongInLine()
        {
            Track nextSong;

            if (Queue.Count == 0) // No song in queue
            {
                if (BasicPlaylist == null || BasicPlaylist.Count == 0)
                {
                    await RepopulateBasicPlaylistIds();
                }
                nextSong = BasicPlaylist[new Random().Next(BasicPlaylist.Count)];
            }
            else
            {
                nextSong = Queue[0];
            }

            if (LandingPlaylist == null || LandingPlaylist.Count < LandingListSize)
            {
                await RefreshLandingList();
            }
            else
            {
                if (LandingPlaylist.Count <= LandingListSize)
                {
                    if (TakeFromQueue && Queue.Count > 0)
                    {
                        await AddQueuedSongToLandingList();
                    }
                    else
                    {
                        await AddBasicSongToLandingList();
                    }
                    await RemoveRecentlyPlayedSong();

                    LandingPlaylist.RemoveAt(0);
                }
            }

            //TakeFromQueue = !TakeFromQueue;
            var landingSongs = await GetLandingSongs();

            return(landingSongs);
        }
예제 #4
0
        private async Task AddBasicSongToLandingList(int i = 0)
        {
            Track song;
            bool  duplicate;

            do
            {
                if (i == 0)
                {
                    song = BasicPlaylist[new Random().Next(BasicPlaylist.Count)];
                }
                else
                {
                    song = BasicPlaylist[new Random(i++).Next(BasicPlaylist.Count)];
                }
                duplicate = LandingPlaylist.Any(t => t.Id == song.Id);
            } while (duplicate);
            await AddSongToPlaylist(song, LandingPlaylistId);
        }
예제 #5
0
        public async Task <string> QueueSong(string id)
        {
            var queue = await GetPlaylistTracks(RuntimeQueuePlaylistId);

            if (Queue.Any(t => t.Id == id) || LandingPlaylist.Any(p => p.Id == id) || queue.Any(t => t.Id == id))
            {
                return("Låten är redan köad");
            }
            var trackRequest  = ConstructRequestMessage("GET", $"https://api.spotify.com/v1/tracks/{id}");
            var trackResponse = await _client.SendAsync(trackRequest);

            var content = await trackResponse.Content.ReadAsStringAsync();

            var track = ConvertJsonTrack(content);

            Queue.Add(track);
            await AddSongToPlaylist(track, RuntimeQueuePlaylistId);

            return($"Låten {track.Name} lades till i kön");
        }
예제 #6
0
        public async Task RemoveRecentlyPlayedSong()
        {
            var recentlyPlayed = LandingPlaylist.First();

            await RemoveSong(recentlyPlayed, LandingPlaylistId);
        }