Ejemplo n.º 1
0
        private void renameButton_Click(object sender, EventArgs e)
        {
            api.OnRenamePlaylistComplete = OnRenamePlaylist;
            GMusicPlaylist selectedPlaylist = (GMusicPlaylist)playlistListBox.SelectedItem;

            api.RenamePlaylist(selectedPlaylist.ID, renamePlaylistTextBox.Text);
        }
Ejemplo n.º 2
0
        // Deletes the playlist currently selected by the user
        private void deletePlaylistButton_Click(object sender, EventArgs e)
        {
            api.OnDeletePlaylistComplete = DeletePlaylistDone;
            GMusicPlaylist selectedPlaylist = (GMusicPlaylist)playlistListBox.SelectedItem;

            api.DeletePlaylist(selectedPlaylist.ID);
        }
Ejemplo n.º 3
0
        // This feels awfully hacky. (and potentially very slow).
        // For each element in the received JSON, fetch the song object from our previously created "allSongs" list
        // then fetch the playlist from our "allPlaylists" list
        // finally, remove the playlist from the list, update it to have the song object attached, and then re-add it to the list (this will change the list order, but that's not particuarly important)
        // A song which has been "deleted" from a playlist won't be added to it.
        private void PlaylistSongsReceived(HttpWebRequest request, HttpWebResponse response, String jsonData, Exception error)
        {
            JObject allSongsReceived = JObject.Parse(jsonData);

            foreach (JObject song in allSongsReceived["data"]["items"])
            {
                GMusicPlaylistEntry thisSong     = JsonConvert.DeserializeObject <GMusicPlaylistEntry>(song.ToString());
                GMusicPlaylist      thisPlaylist = allPlaylists.FirstOrDefault(p => p.ID == thisSong.PlaylistID);
                if (thisPlaylist != null)
                {
                    // I think as the list contains a reference to the object, it will be updated
                    thisPlaylist.Songs.Add(thisSong);
                }
            }

            JToken nextPageToken = allSongsReceived.GetValue("nextPageToken");

            if (nextPageToken != null)
            {
                string nextPageTokenString = nextPageToken.ToString();
                GetAllPlaylistSongs(nextPageTokenString);
                return;
            }

            log.Log("Playlists fetched!");

            if (OnGetAllPlaylistsComplete != null)
            {
                OnGetAllPlaylistsComplete(allPlaylists);
            }
        }
Ejemplo n.º 4
0
        // This could delete multiple selections at once, but it doesn't
        private void deleteSong_Click(object sender, EventArgs e)
        {
            api.OnDeleteFromPlaylistComplete = OnChangePlaylist;
            GMusicSong          selectedSong     = (GMusicSong)playlistSongsBox.SelectedItem;
            GMusicPlaylist      selectedPlaylist = (GMusicPlaylist)playlistListBox.SelectedItem;
            GMusicPlaylistEntry songEntry        = selectedPlaylist.Songs.First(s => s.TrackID == selectedSong.ID);

            api.DeleteFromPlaylist(new List <GMusicPlaylistEntry> {
                songEntry
            });
        }
Ejemplo n.º 5
0
        private void playlistListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            playlistSongsBox.Items.Clear();
            GMusicPlaylist selectedPlaylist = (GMusicPlaylist)playlistListBox.SelectedItem;

            foreach (GMusicPlaylistEntry song in selectedPlaylist.Songs)
            {
                if (!song.Deleted)
                {
                    GMusicSong thisSong = AllSongs.FirstOrDefault(s => s.ID == song.TrackID);
                    playlistSongsBox.Items.Add(thisSong);
                }
            }
        }
Ejemplo n.º 6
0
        private void addSongsButton_Click(object sender, EventArgs e)
        {
            api.OnAddToPlaylistComplete = OnChangePlaylist;
            ListBox.SelectedObjectCollection songsSelected = songListBox.SelectedItems;
            List <GMusicSong> songsList = new List <GMusicSong>();

            foreach (GMusicSong song in songsSelected)
            {
                songsList.Add(song);
            }

            GMusicPlaylist selectedPlaylist = (GMusicPlaylist)playlistListBox.SelectedItem;

            api.AddToPlaylist(selectedPlaylist.ID, songsList);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This is blocking, so run it on a thread
        /// </summary>
        public void SyncPlaylists()
        {
            if (!_gMusic.LoggedIn || _gMusic.SyncRunning)
            {
                return;
            }

            if (_settings.SyncLocalToRemote)
            {
                List <MbPlaylist> playlists    = new List <MbPlaylist>();
                List <MbPlaylist> allPlaylists = _mbSync.GetMbPlaylists();
                // Only sync the playlists that the settings say we should
                // Surely there's a nicer LINQ query for this?
                foreach (MbPlaylist pls in allPlaylists)
                {
                    if (_settings.MBPlaylistsToSync.Contains(pls.mbName))
                    {
                        playlists.Add(pls);
                    }
                }
                _gMusic.SyncPlaylistsToGMusic(playlists);
            }
            else
            {
                if (_gMusic.DataFetched)
                {
                    List <GMusicPlaylist> playlists = new List <GMusicPlaylist>();
                    foreach (string id in _settings.GMusicPlaylistsToSync)
                    {
                        GMusicPlaylist pls = _gMusic.AllPlaylists.FirstOrDefault(p => p.ID == id);
                        if (pls != null)
                        {
                            playlists.Add(pls);
                        }
                    }
                    _mbSync.SyncPlaylistsToMusicBee(playlists, _gMusic.AllSongs);
                    return;
                }
                else
                {
                    return;
                }
            }
        }
Ejemplo n.º 8
0
        // Synchronise the playlists defined in the settings file to Google Music
        public void SyncPlaylistsToGMusic(List <MbPlaylist> mbPlaylistsToSync)
        {
            _syncRunning = true;
            AutoResetEvent waitForEvent = new AutoResetEvent(false);


            if (_dataFetched)
            {
                // Get the MusicBee playlists
                foreach (MbPlaylist 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
                    GMusicPlaylist thisPlaylist   = _allPlaylists.FirstOrDefault(p => p.Name == playlist.Name && p.Deleted == false);
                    String         thisPlaylistID = "";
                    if (thisPlaylist != null)
                    {
                        List <GMusicPlaylistEntry> allPlsSongs = thisPlaylist.Songs;
                        // This simply signals the wait handle when done
                        api.OnDeleteFromPlaylistComplete = delegate(MutatePlaylistResponse response)
                        {
                            waitForEvent.Set();
                        };
                        api.DeleteFromPlaylist(allPlsSongs);

                        // Wait until the deletion is done
                        waitForEvent.WaitOne();
                        thisPlaylistID = thisPlaylist.ID;
                    }
                    else
                    {
                        // Set the callback
                        api.OnCreatePlaylistComplete = delegate(MutateResponse response)
                        {
                            thisPlaylistID = response.ID;
                            waitForEvent.Set();
                        };
                        // Create the playlist
                        api.CreatePlaylist(playlist.Name);
                        // Wait until creation is done
                        waitForEvent.WaitOne();
                    }

                    // Create a list of files based on the MB Playlist
                    string[] playlistFiles = null;
                    if (_mbApiInterface.Playlist_QueryFiles(playlist.mbName))
                    {
                        // Old method:
                        //  playlistFiles = _mbApiInterface.Playlist_QueryGetAllFiles().Split(filesSeparators, StringSplitOptions.RemoveEmptyEntries);

                        bool success = _mbApiInterface.Playlist_QueryFilesEx(playlist.mbName, ref playlistFiles);
                        if (!success)
                        {
                            throw new Exception("Couldn't get playlist files");
                        }
                    }
                    else
                    {
                        playlistFiles = new string[0];
                    }

                    List <GMusicSong> songsToAdd = new List <GMusicSong>();
                    // And get the title and artist of each file, and add it to the GMusic playlist
                    foreach (string file in playlistFiles)
                    {
                        string     title  = _mbApiInterface.Library_GetFileTag(file, Plugin.MetaDataType.TrackTitle);
                        string     artist = _mbApiInterface.Library_GetFileTag(file, Plugin.MetaDataType.Artist);
                        GMusicSong gSong  = _allSongs.FirstOrDefault(item => (item.Artist == artist && item.Title == title));
                        if (gSong != null)
                        {
                            songsToAdd.Add(gSong);
                        }
                    }

                    api.OnAddToPlaylistComplete = delegate(MutatePlaylistResponse response)
                    {
                        waitForEvent.Set();
                    };
                    api.AddToPlaylist(thisPlaylistID, songsToAdd);
                    waitForEvent.WaitOne();
                }

                _syncRunning = false;
                // Signal to anyone calling that we're done
                if (OnSyncComplete != null)
                {
                    OnSyncComplete(this, new EventArgs());
                }
            }
            else
            {
                throw new Exception("Not fetched data yet");
            }
        }