コード例 #1
0
ファイル: LastfmApi.cs プロジェクト: 0Delfo0/Emby.Plugins
        public async Task <UserGetArtistTracksRespose> UserGetArtistTracks(LfmUser user, LfmArtist artist, int page = 0)
        {
            var request = new UserGetArtistTracksRequest
            {
                user   = user.Username,
                artist = artist.name,
                page   = page,
                limit  = 0,
                method = PluginConst.Methods.User.GetArtistTracks
            };

            return(await Get <UserGetArtistTracksRequest, UserGetArtistTracksRespose>(request));
        }
コード例 #2
0
        private async Task <List <LfmTrack> > GetUserGetArtistTracks(LfmUser lfmUser, LfmArtist lfmArtist, IProgress <double> progress, CancellationToken cancellationToken, double maxProgress, double progressOffset)
        {
            var  tracks = new List <LfmTrack>();
            var  page   = 1;
            bool moreTracks;

            do
            {
                cancellationToken.ThrowIfCancellationRequested();

                var response = await _lastfmApi.UserGetArtistTracks(lfmUser, lfmArtist, page ++).ConfigureAwait(false);

                if (response?.artisttracks?.track == null || !response.artisttracks.track.Any())
                {
                    break;
                }

                tracks.AddRange(response.artisttracks.track);

                moreTracks = !response.artisttracks.attr.IsLastPage();

                //Only report progress in download because it will be 90% of the time taken
                var currentProgress = (double)response.artisttracks.attr.page / response.artisttracks.attr.totalPages * (maxProgress - progressOffset) + progressOffset;

                Plugin.Logger.Debug("Progress: " + currentProgress * 100);

                progress.Report(currentProgress * 100);
            } while(moreTracks);

            return(tracks);
        }