public async Task <PlaylistActionResponse> PlaylistOperationAsync(Namespace mediaNamespace, PlaylistActionType operation, PlaylistAction playlistAction) { Dictionary <string, string> requestParameters = await FormatRequestParametersAsync(); return(await PostWithRetryOnExpiredTokenAsync <PlaylistActionResponse, PlaylistAction>("/1/content/" + mediaNamespace + "/collection/playlists/" + operation, playlistAction, new CancellationToken(false), requestParameters)); }
/// <summary> /// Gets a playlist. /// </summary> /// <param name="playlistID">The playlist ID in the system, like "SQ:14" - for Saved Queue.</param> /// <param name="action">What to find out about the playlist, either return the items in the playlist or a count of the items.</param> /// <returns></returns> public static string GetPlaylist(string playlistID, PlaylistAction action, int index) { string zone = UPnP.Discovery.Zones[0].ToString(); // use first in list string path = "/MediaServer/ContentDirectory/Control"; string numResults = String.Empty; string retVal = String.Empty; Uri uri = new Uri(zone); string host = uri.Scheme + "://" + uri.Host + ":" + uri.Port.ToString(); string soapAction = "urn:schemas-upnp-org:service:ContentDirectory:1#Browse"; string soapBody = "<u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\">" + "<ObjectID>" + playlistID + "</ObjectID>" + "<BrowseFlag>BrowseDirectChildren</BrowseFlag>" + "<Filter></Filter>" + "<StartingIndex>" + (_maxPlaylistPagingResults * (index)).ToString() + "</StartingIndex>" + "<RequestedCount>" + (_maxPlaylistPagingResults).ToString() + "</RequestedCount>" + "<SortCriteria></SortCriteria>" + "</u:Browse>"; XmlDocument resp = SOAPRequest(path, host, soapBody, soapAction); XmlNamespaceManager nsm = new XmlNamespaceManager(resp.NameTable); nsm.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); XmlDocument resultNode = new XmlDocument(); numResults = resp.SelectSingleNode("*//TotalMatches").InnerText; switch (action) { default: case PlaylistAction.Count: retVal = numResults; break; case PlaylistAction.Save: if (Int32.Parse(numResults) > _maxPlaylistPagingResults * (index + 1) /* zero-based index */) { index += 1; // Get playlist items recursively. XDocument recurVal = XDocument.Parse(GetPlaylist(playlistID, action, index)); XDocument currVal = XDocument.Parse(resp.SelectSingleNode("*//Result").InnerText); currVal.Root.Add(recurVal.Root.Elements()); retVal = currVal.ToString(); } else { retVal = resp.SelectSingleNode("*//Result").InnerText; } break; } return(retVal); }
public async Task <PlaylistActionResponse> PlaylistOperationAsync( MediaNamespace mediaNamespace, PlaylistActionType operation, PlaylistAction playlistAction) { Dictionary <string, string> requestParameters = FormatRequestParameters(); return(await ApiCallWithUserAuthorizationHeaderRefreshAsync( headers => PostAsync <PlaylistActionResponse, PlaylistAction>( Hostname, $"/1/content/{mediaNamespace}/collection/playlists/{operation}", playlistAction, new CancellationToken(false), requestParameters, headers))); }
private async Task <List <PlaylistActionResponse> > PerformPlaylistActions(List <PlaylistAction> playlistActions) { int totalTrackActions = 0; playlistActions.ForEach(a => { if (a.TrackActions != null) { totalTrackActions += a.TrackActions.Count; } else { totalTrackActions++; } }); List <PlaylistActionResponse> responses = new List <PlaylistActionResponse>(); int totalTrackActionsSoFar = 0; for (int i = 0; i < playlistActions.Count; i++) { PlaylistAction action = playlistActions[i]; PlaylistActionType operation = action.Name == null ? PlaylistActionType.Delete : PlaylistActionType.Create; PlaylistActionResponse response = await _client.PlaylistOperationAsync(MediaNamespace.music, operation, playlistActions[i]); responses.Add(response); if (response.Error == null) { if (action.TrackActions != null) { totalTrackActionsSoFar += action.TrackActions.Count; } _window.UpdateSyncProgress(100 * totalTrackActionsSoFar / totalTrackActions); } else { _window.WriteOutputLine($"Error when syncing: {response.Error.Description}"); } } return(responses); }
public PlaylistManagerEventArgs(PlaylistAction playlistAction) { PlaylistAction = playlistAction; }
public PlayListChangedEventArgs(List<int> cardIDs, string description, PlaylistAction action) { CardIDs = cardIDs; Description = description; Action = action; }
void onPlayListChanged(PlaylistAction action) { if (PlayListChanged != null) PlayListChanged(new PlayListChangedEventArgs(Cards.GetIDList(), Description, action)); }
private async Task <List <PlaylistAction> > GetPlaylistActions(List <MusicBeePlaylist> playlistsToSync, List <Playlist> existingGroovePlaylists) { List <PlaylistAction> playlistActions = new List <PlaylistAction>(); int totalPlaylistsProcessed = 0; foreach (MusicBeePlaylist playlist in playlistsToSync) { _window.WriteOutputLine($"Preparing {playlist.Name} for sync"); // If playlist already exists, // for now, delete playlist and remake completely // eventually, calculate diff Playlist matchingGroovePlaylist = existingGroovePlaylists.Where(p => p.Name == playlist.Name).FirstOrDefault(); if (matchingGroovePlaylist != null) { PlaylistAction deletePlaylist = new PlaylistAction() { Id = matchingGroovePlaylist.Id, }; playlistActions.Add(deletePlaylist); } // Get list of file paths to tracks in music bee library string[] playlistFiles = null; if (_mbApiInterface.Playlist_QueryFiles(playlist.MusicBeeName)) { bool success = _mbApiInterface.Playlist_QueryFilesEx(playlist.MusicBeeName, ref playlistFiles); if (!success) { _window.WriteOutputLine($"Couldn't find playlist file for: {playlist.Name}"); return(null); } } else { playlistFiles = new string[] { }; } // Map the track in music bee to Groove List <TrackAction> tracksToAdd = new List <TrackAction>(); foreach (string file in playlistFiles) { string title = _mbApiInterface.Library_GetFileTag(file, MetaDataType.TrackTitle); string artist = _mbApiInterface.Library_GetFileTag(file, MetaDataType.Artist); ContentResponse response = await _client.SearchAsync(MediaNamespace.music, HttpUtility.UrlEncode(title), ContentSource.Collection, SearchFilter.Tracks); if (response.Error == null || response.Error.ErrorCode == Enum.GetName(typeof(ErrorCode), ErrorCode.COLLECTION_INVALID_DATA)) { TrackAction action = null; List <Track> tracksFound = response.Tracks.Items.Cast <Track>().ToList(); foreach (Track track in tracksFound) { if (track.Name == title && track.Artists.Where(c => c.Artist.Name == artist).FirstOrDefault() != null) { action = new TrackAction() { Action = TrackActionType.Add, Id = track.Id }; tracksToAdd.Add(action); } } if (action == null) { _window.WriteOutputLine($"Could not match track {artist} - {title}"); } } else { _window.WriteOutputLine($"Could not match track {artist} - {title}"); } } PlaylistAction createPlaylist = new PlaylistAction() { Name = playlist.Name, TrackActions = tracksToAdd }; playlistActions.Add(createPlaylist); totalPlaylistsProcessed++; _window.UpdatePreparationProgress(100 * totalPlaylistsProcessed / playlistsToSync.Count); } return(playlistActions); }
/// <summary> /// Gets a playlist. /// </summary> /// <param name="playlistID">The playlist ID in the system, like "SQ:14" - for Saved Queue.</param> /// <param name="action">What to find out about the playlist, either return the items in the playlist or a count of the items.</param> /// <returns></returns> public static string GetPlaylist(string playlistID, PlaylistAction action, int index) { string zone = UPnP.Discovery.Zones[0].ToString(); // use first in list string path = "/MediaServer/ContentDirectory/Control"; string numResults = String.Empty; string retVal = String.Empty; Uri uri = new Uri(zone); string host = uri.Scheme + "://" + uri.Host + ":" + uri.Port.ToString(); string soapAction = "urn:schemas-upnp-org:service:ContentDirectory:1#Browse"; string soapBody = "<u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\">" + "<ObjectID>" + playlistID + "</ObjectID>" + "<BrowseFlag>BrowseDirectChildren</BrowseFlag>" + "<Filter></Filter>" + "<StartingIndex>" + (_maxPlaylistPagingResults * (index)).ToString() + "</StartingIndex>" + "<RequestedCount>" + (_maxPlaylistPagingResults).ToString() + "</RequestedCount>" + "<SortCriteria></SortCriteria>" + "</u:Browse>"; XmlDocument resp = SOAPRequest(path, host, soapBody, soapAction); XmlNamespaceManager nsm = new XmlNamespaceManager(resp.NameTable); nsm.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); XmlDocument resultNode = new XmlDocument(); numResults = resp.SelectSingleNode("*//TotalMatches").InnerText; switch (action) { default: case PlaylistAction.Count: retVal = numResults; break; case PlaylistAction.Save: if (Int32.Parse(numResults) > _maxPlaylistPagingResults*(index+1) /* zero-based index */) { index += 1; // Get playlist items recursively. XDocument recurVal = XDocument.Parse(GetPlaylist(playlistID, action, index)); XDocument currVal = XDocument.Parse(resp.SelectSingleNode("*//Result").InnerText); currVal.Root.Add(recurVal.Root.Elements()); retVal = currVal.ToString(); } else { retVal = resp.SelectSingleNode("*//Result").InnerText; } break; } return retVal; }