Beispiel #1
0
        private async Task <(IReadOnlyCollection <SongModel> Songs, int?CurrentSongIndex)> LoadPlaylistData(CancellationToken cancellationToken)
        {
            var playListData = await sessionDataService.GetData <PlaylistData>(PlaylistDataKey, cancellationToken);

            if (playListData == null)
            {
                logger.LogInformation("No previous playlist data loaded");
                return(null, null);
            }

            return(await LoadPlaylistSongs(playListData, cancellationToken));
        }
Beispiel #2
0
        private async Task EnsureLoaded(CancellationToken cancellationToken)
        {
            if (loaded)
            {
                return;
            }

            var scrobbles = await sessionDataService.GetData <TrackScrobble[]>(ScrobblesDataKey, cancellationToken);

            foreach (var item in scrobbles ?? Enumerable.Empty <TrackScrobble>())
            {
                scrobblesQueue.Enqueue(item);
            }

            loaded = true;
        }
        public async Task <IReadOnlyCollection <AdvisedPlaylist> > Advise(IEnumerable <DiscModel> discs, int requiredAdvisesCount, CancellationToken cancellationToken)
        {
            Memo ??= await sessionDataService.GetData <PlaylistAdviserMemo>(PlaylistAdviserDataKey, cancellationToken) ?? CreateDefaultMemo();

            var playbacksMemo = Memo;

            var adviseGroups  = (await discGrouper.GroupLibraryDiscs(discs, cancellationToken)).ToList();
            var playbacksInfo = new PlaybacksInfo(adviseGroups);

            var highlyRatedSongsAdvises = await highlyRatedSongsAdviser.Advise(adviseGroups, playbacksInfo, cancellationToken);

            var favoriteAdviseGroupAdvises = await favoriteAdviseGroupsAdviser.Advise(adviseGroups, playbacksInfo, cancellationToken);

            var rankedAdvises = await rankBasedAdviser.Advise(adviseGroups, playbacksInfo, cancellationToken);

            var playlistQueue = new CompositeAdvisedPlaylistQueue(highlyRatedSongsAdvises, favoriteAdviseGroupAdvises, rankedAdvises);

            var advisedPlaylists = new List <AdvisedPlaylist>(requiredAdvisesCount);

            var knownAdviseSets = new HashSet <string>();

            while (advisedPlaylists.Count < requiredAdvisesCount)
            {
                var currentAdvise = GetNextAdvisedPlaylist(playbacksMemo, playlistQueue);
                if (currentAdvise == null)
                {
                    break;
                }

                var adviseSet = currentAdvise.AdviseSet;
                if (adviseSet != null)
                {
                    if (knownAdviseSets.Contains(adviseSet.Id))
                    {
                        continue;
                    }

                    knownAdviseSets.Add(adviseSet.Id);
                }

                advisedPlaylists.Add(currentAdvise);
                playbacksMemo = playbacksMemo.RegisterPlayback(currentAdvise);
            }

            return(advisedPlaylists);
        }