Ejemplo n.º 1
0
 public void Refresh()
 {
     if (Subsonic.IsInitialized)
     {
         Subsonic.Refresh();
     }
     else
     {
         Subsonic.SendNotificationsHandler.Invoke(Subsonic.Initialize()
             ? Interfaces.Plugin.CallbackType.StorageReady
             : Interfaces.Plugin.CallbackType.StorageFailed);
     }
 }
Ejemplo n.º 2
0
        // called by MusicBee when the user clicks Apply or Save in the MusicBee Preferences screen.
        // its up to you to figure out whether anything has changed and needs updating
        public void SaveSettings()
        {
            var settings = new SubsonicSettings
            {
                Host      = _host.Text,
                Port      = _port.Text,
                BasePath  = _basePath.Text,
                Username  = _username.Text,
                Password  = _password.Text,
                Transcode = _transcode.Checked,
                Protocol  =
                    _protocol.SelectedItem.ToString().Equals("HTTP")
                        ? SubsonicSettings.ConnectionProtocol.Http
                        : SubsonicSettings.ConnectionProtocol.Https,
                Auth =
                    _authMethodBox.SelectedIndex.Equals(0)
                        ? SubsonicSettings.AuthMethod.Token
                        : SubsonicSettings.AuthMethod.HexPass,
                //Null reference. Issue #36 - https://github.com/midwan/MB_SubSonic/issues/36. If there is no bitrate, set it to a default.
                BitRate = String.IsNullOrEmpty((String)_bitRate.SelectedItem) ? "128K" : _bitRate.SelectedItem.ToString()
            };

            var setHostSuccess = Subsonic.SetHost(settings);

            if (setHostSuccess)
            {
                DeleteCacheFile();
                Refresh();
                return;
            }

            var error   = Subsonic.GetError();
            var message = error?.Message;

            if (!string.IsNullOrEmpty(message))
            {
                MessageBox.Show(_host, $@"Error: {message}", @"Subsonic Plugin", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
            }
        }
Ejemplo n.º 3
0
        // receive event notifications from MusicBee
        // you need to set about.ReceiveNotificationFlags = PlayerEvents to receive all notifications, and not just the startup event
        public void ReceiveNotification(string sourceFileUrl, Interfaces.Plugin.NotificationType type)
        {
            // perform some action depending on the notification type
            //switch (type)

            if (type != Interfaces.Plugin.NotificationType.PluginStartup)
            {
                return;
            }

            var dataPath = _mbApiInterface.Setting_GetPersistentStoragePath();

            Subsonic.CacheFilename    = Path.Combine(dataPath, "subsonicCache.dat");
            Subsonic.SettingsFilename = Path.Combine(dataPath, "subsonicSettings.dat");

            Subsonic.SendNotificationsHandler.Invoke(Subsonic.Initialize()
                ? Interfaces.Plugin.CallbackType.StorageReady
                : Interfaces.Plugin.CallbackType.StorageFailed);

            //case NotificationType.TrackChanged:
            //    string artist = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist);
            //    // ...
            //    break;
        }
Ejemplo n.º 4
0
        // receive event notifications from MusicBee
        // you need to set about.ReceiveNotificationFlags = PlayerEvents to receive all notifications, and not just the startup event
        public void ReceiveNotification(string sourceFileUrl, Interfaces.Plugin.NotificationType type)
        {
            // perform some action depending on the notification type
            switch (type)
            {
            case Interfaces.Plugin.NotificationType.PluginStartup:
                var dataPath = _mbApiInterface.Setting_GetPersistentStoragePath();
                Subsonic.CacheFilename    = Path.Combine(dataPath, "subsonicCache.dat");
                Subsonic.SettingsFilename = Path.Combine(dataPath, "subsonicSettings.dat");

                Subsonic.SendNotificationsHandler.Invoke(Subsonic.Initialize()
                        ? Interfaces.Plugin.CallbackType.StorageReady
                        : Interfaces.Plugin.CallbackType.StorageFailed);
                break;

            case Interfaces.Plugin.NotificationType.TagsChanged:
                //var tags = new List<Interfaces.Plugin.MetaDataType>
                //{
                //    Interfaces.Plugin.MetaDataType.Artist,
                //    Interfaces.Plugin.MetaDataType.TrackTitle,
                //    Interfaces.Plugin.MetaDataType.Album,
                //    Interfaces.Plugin.MetaDataType.Year,
                //    Interfaces.Plugin.MetaDataType.TrackNo,
                //    Interfaces.Plugin.MetaDataType.Genre,
                //    Interfaces.Plugin.MetaDataType.Artwork,
                //    Interfaces.Plugin.MetaDataType.DiscNo,
                //    Interfaces.Plugin.MetaDataType.RatingLove,
                //    Interfaces.Plugin.MetaDataType.Rating
                //};

                //Subsonic.GetFileTags(sourceFileUrl, tags.ToArray(), out var results);
                //Subsonic.UpdateTags(results);

                var rating  = Subsonic.GetFileTag(sourceFileUrl, Interfaces.Plugin.MetaDataType.Rating);
                var starred = Subsonic.GetFileTag(sourceFileUrl, Interfaces.Plugin.MetaDataType.RatingLove);
                var id      = Subsonic.GetFileTag(sourceFileUrl, Interfaces.Plugin.MetaDataType.Custom16);

                Subsonic.UpdateRating(id, rating);
                Subsonic.UpdateRatingLove(id, starred);
                break;

            //case Interfaces.Plugin.NotificationType.PlaylistCreated:
            //    // TODO send new playlist to Subsonic Server
            //    string[] filenames;
            //    Subsonic.QueryPlaylistFilesEx(sourceFileUrl, out filenames);

            //    break;

            //case Interfaces.Plugin.NotificationType.PlaylistUpdated:
            //    //TODO check what happens here
            //    string[] filenames1;
            //    Subsonic.QueryPlaylistFilesEx(sourceFileUrl, out filenames1);

            //    break;

            case Interfaces.Plugin.NotificationType.PlaylistDeleted:
                //TODO Delete playlist
                var serverPlaylists  = Subsonic.GetPlaylists();
                var playlistToDelete = serverPlaylists.Where(p => p.Value.Equals(GetPlaylistName(sourceFileUrl)));
                foreach (var item in playlistToDelete)
                {
                    Subsonic.DeletePlaylist(int.Parse(item.Key));
                }
                break;

            case Interfaces.Plugin.NotificationType.PlaylistMoved:
                string[] filenames;
                Subsonic.QueryPlaylistFilesEx(sourceFileUrl, out filenames);

                // Get Song IDs to add to playlist
                var songIds = new List <int>();
                foreach (var filename in filenames)
                {
                    id = Subsonic.GetFileTag(filename, Interfaces.Plugin.MetaDataType.Custom16);
                    if (int.TryParse(id, out var songId))
                    {
                        songIds.Add(songId);
                    }
                }

                Subsonic.CreatePlaylist(GetPlaylistName(sourceFileUrl), songIds);
                break;

                //case NotificationType.TrackChanged:
                //    string artist = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist);
                //    // ...
                //    break;
            }
        }
Ejemplo n.º 5
0
 // MusicBee is closing the plugin (plugin is being disabled by user or MusicBee is shutting down)
 public void Close(Interfaces.Plugin.PluginCloseReason reason)
 {
     Subsonic.Close();
 }
Ejemplo n.º 6
0
 public Exception GetError()
 {
     return(Subsonic.GetError());
 }
Ejemplo n.º 7
0
 public Stream GetStream(string url)
 {
     return(Subsonic.GetStream(url));
 }
Ejemplo n.º 8
0
 public KeyValuePair <byte, string>[][] GetPlaylistFiles(string id)
 {
     return(Subsonic.GetPlaylistFiles(id));
 }
Ejemplo n.º 9
0
 public KeyValuePair <string, string>[] GetPlaylists()
 {
     return(Subsonic.GetPlaylists());
 }
Ejemplo n.º 10
0
 public byte[] GetFileArtwork(string url)
 {
     return(Subsonic.GetFileArtwork(url));
 }
Ejemplo n.º 11
0
 public bool FileExists(string url)
 {
     return(Subsonic.FileExists(url));
 }
Ejemplo n.º 12
0
 public KeyValuePair <byte, string>[] GetFile(string url)
 {
     return(Subsonic.GetFile(url));
 }
Ejemplo n.º 13
0
 public KeyValuePair <byte, string>[][] GetFiles(string path)
 {
     return(Subsonic.GetFiles(path));
 }
Ejemplo n.º 14
0
 public string[] GetFolders(string path)
 {
     return(Subsonic.GetFolders(path));
 }
Ejemplo n.º 15
0
 public bool FolderExists(string path)
 {
     return(Subsonic.FolderExists(path));
 }
Ejemplo n.º 16
0
 // MusicBee is closing the plugin (plugin is being disabled by user or MusicBee is shutting down)
 public void Close(PluginCloseReason reason)
 {
     Subsonic.Close();
 }