private void OnChangePlaylist(MutatePlaylistResponse response) { this.Invoke(new MethodInvoker(delegate { getPlaylistsButton.PerformClick(); })); }
private void PlaylistSongsDeleted(HttpWebRequest request, HttpWebResponse response, String jsonData, Exception error) { MutatePlaylistResponse mutateResponse = JsonConvert.DeserializeObject <MutatePlaylistResponse>(jsonData); // Add the callback if (OnDeleteFromPlaylistComplete != null) { OnDeleteFromPlaylistComplete(mutateResponse); } }
private void PlaylistCreated(HttpWebRequest request, HttpWebResponse response, String jsonData, Exception error) { MutatePlaylistResponse mutateResponse = JsonConvert.DeserializeObject <MutatePlaylistResponse>(jsonData); MutateResponse responseObject = mutateResponse.MutateResponses.FirstOrDefault(); if (OnCreatePlaylistComplete != null) { OnCreatePlaylistComplete(responseObject); } }
public async Task <List <IPlaylistSyncError> > SyncToGoogle(MusicBeeSyncHelper mb, List <MusicBeePlaylist> mbPlaylistsToSync, bool includeFoldersInPlaylistName = false, bool includeZAtStartOfDatePlaylistName = true) { List <IPlaylistSyncError> errors = new List <IPlaylistSyncError>(); foreach (MusicBeePlaylist playlist in mbPlaylistsToSync) { // Use LINQ to check for a playlist with the same name // If there is one, clear it's contents, otherwise create one // Unless it's been deleted, in which case pretend it doesn't exist. // I'm not sure how to undelete a playlist, or even if you can string gpmPlaylistName = null; if (includeFoldersInPlaylistName) { gpmPlaylistName = playlist.Name; } else { gpmPlaylistName = playlist.Name.Split('\\').Last(); } if (includeZAtStartOfDatePlaylistName) { // if it starts with a 2, it's a date playlist if (gpmPlaylistName.StartsWith("2")) { gpmPlaylistName = $"Z {gpmPlaylistName}"; } } Playlist thisPlaylist = GooglePlaylists.FirstOrDefault(p => p.Name == gpmPlaylistName && p.Deleted == false); String thisPlaylistID = ""; if (thisPlaylist != null) { List <PlaylistEntry> allPlsSongs = thisPlaylist.Songs; if (allPlsSongs.Count > 0) { MutatePlaylistResponse response = await api.RemoveFromPlaylistAsync(allPlsSongs); } thisPlaylistID = thisPlaylist.Id; } else { MutatePlaylistResponse response = await api.CreatePlaylistAsync(gpmPlaylistName); thisPlaylistID = response.MutateResponses.First().ID; } List <Track> songsToAdd = new List <Track>(); // And get the title and artist of each file, and add it to the GMusic playlist foreach (var song in playlist.Songs) { string title = song.Title; string artist = song.Artist; string album = song.Album; // First check for matching title, artist, album, if we find nothing, then check for matching title/artist Track gSong = GoogleSongsFetched.FirstOrDefault(item => (item.Artist.ToLower() == artist.ToLower() && item.Title.ToLower() == title.ToLower() && item.Album.ToLower() == album.ToLower())); if (gSong == null) { gSong = GoogleSongsFetched.FirstOrDefault(item => (item.Artist.ToLower() == artist.ToLower() && item.Title.ToLower() == title.ToLower())); if (gSong != null) { songsToAdd.Add(gSong); } else { // Didn't find it in cached library, so query for it Track result = await TryGetTrackAsync(artist, title, album); if (result != null) { GoogleSongsFetched.Add(result); songsToAdd.Add(result); } else { // didn't find it even via querying errors.Add(new UnableToFindGPMTrackError() { PlaylistName = gpmPlaylistName, AlbumName = album, ArtistName = artist, TrackName = title, SearchedService = true, }); } } } else { songsToAdd.Add(gSong); } } await api.AddToPlaylistAsync(thisPlaylistID, songsToAdd); } return(errors); }