private void CreateTargetPlaylist(PlaylistItem[] inPlaylist, string sourceFile, string targetDirectory, IStorage storage) { var playlistHandler = PlaylistHandlerFactory.GetHandler(_targetPlaylistType.ToString().ToLower()); var newPlaylistRawContent = playlistHandler.SetPlaylistItems(storage.File, inPlaylist, targetDirectory); var targetFileName = $"{Path.GetFileNameWithoutExtension(sourceFile)}.{_targetPlaylistType.ToString().ToLower()}"; storage.File.WriteAllText(Path.Combine(targetDirectory, targetFileName), newPlaylistRawContent); PlaylistCreated?.Invoke(this, new ProgressEventArgs(targetFileName, 1)); }
protected SpecialPlaylistBase(IMediaLibrary library, PlaylistType type, string name) { if (library == null) throw new ArgumentNullException("library"); if (type == PlaylistType.None) throw new ArgumentException("type"); if (string.IsNullOrEmpty(name)) name = type.ToString(); m_library = library; m_type = type; m_id = library.Id + (byte)type; m_name = name; }
protected SpecialPlaylistBase(IMediaLibrary library, PlaylistType type, string name) { if (library == null) { throw new ArgumentNullException("library"); } if (type == PlaylistType.None) { throw new ArgumentException("type"); } if (string.IsNullOrEmpty(name)) { name = type.ToString(); } m_library = library; m_type = type; m_id = library.Id + (byte)type; m_name = name; }
public async Task <long> GetTrackCount(PlaylistType type, string lastFmUser) { var method = Extensions.GetAttributeNameProperty <PlaylistType, LastFmMethod>(type.ToString()); var result = await _client.GetAsync($"{_apiUrl}/lastfm/count?user={lastFmUser}&method={method}"); if (result.IsSuccessStatusCode) { var model = JsonSerializer.Deserialize <LastFmCount>(await result.Content.ReadAsStringAsync()); return(model.Count); } return(0); }
public async Task <List <LastFmTrack> > GetTracksList(PlaylistType type, string lastFmUser, int nrToGet) { var returnValue = new List <LastFmTrack>(); var perPage = nrToGet < 100 ? nrToGet : 100; var pageNr = 1; var method = Extensions.GetAttributeNameProperty <PlaylistType, LastFmMethod>(type.ToString()); var result = await _client.GetStringAsync($"{_apiUrl}/lastfm/tracks?user={lastFmUser}&method={method}&perpage={perPage}&page={pageNr}"); var lfmResult = GetTracksResult(type, result); var totalTracks = lfmResult.Attributes.TotalTracks; nrToGet = (int)totalTracks < nrToGet ? (int)totalTracks : nrToGet; returnValue.AddRange(lfmResult.Tracks); while (returnValue.Count < nrToGet) { if ((nrToGet - returnValue.Count) < perPage) { perPage = nrToGet - returnValue.Count; } pageNr++; result = await _client.GetStringAsync($"{_apiUrl}/lastfm/tracks?user={lastFmUser}&method={method}&perpage={perPage}&page={pageNr}"); returnValue.AddRange(GetTracksResult(type, result).Tracks); if (returnValue.Count % 50 == 0) { RequestRefresh?.Invoke(this, new MessageEventArgs { Messages = new List <string> { $"{returnValue.Count} of {nrToGet} fetched." }, Type = UIUpdateType.Processing }); } } return(returnValue); }
public void LoadPlaylist(string channelid, string playlistid, PlaylistType type, string paginationToken) { if (currentPlaylistChannelid != channelid) { _Playlist.Clear(); } if (!_Playlist.ContainsKey(type)) { // Static global variable data to be referenced by the LoadMoreItems function string pagination = paginationToken; string firstpagination = null; bool isLoadComplete = false; // Function IncrementalLoadingCollection <Google.Apis.YouTube.v3.Data.PlaylistItem> currentPlaylistArrayObj = new IncrementalLoadingCollection <Google.Apis.YouTube.v3.Data.PlaylistItem>((CancellationToken cts, uint count) => { return(Task.Run <ObservableCollection <Google.Apis.YouTube.v3.Data.PlaylistItem> >(async() => { ObservableCollection <Google.Apis.YouTube.v3.Data.PlaylistItem> newcollection = new ObservableCollection <Google.Apis.YouTube.v3.Data.PlaylistItem>(); if (!isLoadComplete) { IList <Google.Apis.YouTube.v3.Data.PlaylistItem> collection = null; // Load playlist var videoInfoRequest = YoutubeService.service.PlaylistItems.List("contentDetails,id,status,snippet"); videoInfoRequest.PlaylistId = playlistid; videoInfoRequest.MaxResults = 50; if (pagination != null) { videoInfoRequest.PageToken = pagination; } try { var videoResultResponse = await videoInfoRequest.ExecuteAsync(); // Set new pagination pagination = videoResultResponse.NextPageToken; if (firstpagination == null) { firstpagination = pagination; // no choice, we might load the first at the end again.. there's no pagination information for the first page } else if (firstpagination == pagination) { isLoadComplete = true; return newcollection; } collection = videoResultResponse.Items; } catch { } // Add it to new collection if (collection != null) { foreach (Google.Apis.YouTube.v3.Data.PlaylistItem item in collection) { newcollection.Add(item); } } } Debug.WriteLine("Loaded new items " + new Random().Next(999)); return newcollection; })); }); _Playlist.Add(type, currentPlaylistArrayObj); this.OnPropertyChanged("Playlist_" + type.ToString()); } }