Advertisement
Guest User

MusicBee_MediaMonkey_Import_Plugin

a guest
Feb 28th, 2017
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.52 KB | None | 0 0
  1. using SongsDB;
  2. using System;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6.  
  7. namespace MusicBeePlugin
  8. {
  9.     public partial class Plugin
  10.     {
  11.         private MusicBeeApiInterface MbApiInterface;
  12.         private PluginInfo about = new PluginInfo();
  13.  
  14.         public PluginInfo Initialise(IntPtr apiInterfacePtr)
  15.         {
  16.             MbApiInterface = new MusicBeeApiInterface();
  17.             MbApiInterface.Initialise(apiInterfacePtr);
  18.             about.PluginInfoVersion = PluginInfoVersion;
  19.             about.Name = "MusicBee_MediaMonkey_Import_Plugin";
  20.             about.Description = "Imports added date, play count and custom fields from MediaMonkey.";
  21.             about.Author = "stax76";
  22.             about.TargetApplication = "";   // current only applies to artwork, lyrics or instant messenger name that appears in the provider drop down selector or target Instant Messenger
  23.             about.Type = PluginType.General;
  24.             about.VersionMajor = 1;  // your plugin version
  25.             about.VersionMinor = 0;
  26.             about.Revision = 1;
  27.             about.MinInterfaceVersion = MinInterfaceVersion;
  28.             about.MinApiRevision = MinApiRevision;
  29.             about.ReceiveNotifications = (ReceiveNotificationFlags.PlayerEvents | ReceiveNotificationFlags.TagEvents);
  30.             about.ConfigurationPanelHeight = 0;   // height in pixels that musicbee should reserve in a panel for config settings. When set, a handle to an empty panel will be passed to the Configure function
  31.  
  32.             MbApiInterface.MB_AddMenuItem("mnuTools/MediaMonkey Import", "MediaMonkey Import", Import);
  33.  
  34.             return about;
  35.         }
  36.  
  37.         private SDBApplication mm = new SDBApplication();
  38.  
  39.         public void Import(object sender, EventArgs e)
  40.         {
  41.             for (int i = 0; i < mm.AllVisibleSongList.Count; i++)
  42.             {
  43.                 var track = mm.AllVisibleSongList.Item[i];
  44.                 MbApiInterface.Library_SetFileTag(track.Path, (MetaDataType)14, track.PlayCounter.ToString());
  45.                 MbApiInterface.Library_SetFileTag(track.Path, (MetaDataType)12, track.DateAdded.ToShortDateString());
  46.                 MbApiInterface.Library_SetFileTag(track.Path, MetaDataType.Custom1, track.Custom1);
  47.                 MbApiInterface.Library_CommitTagsToFile(track.Path);
  48.                 Debug.WriteLine(track.DateAdded.ToShortDateString() + ": " + track.Path);
  49.             }
  50.  
  51.             MbApiInterface.MB_RefreshPanels();
  52.             MessageBox.Show("done");
  53.         }
  54.  
  55.         public bool Configure(IntPtr panelHandle)
  56.         {
  57.             // save any persistent settings in a sub-folder of this path
  58.             string dataPath = MbApiInterface.Setting_GetPersistentStoragePath();
  59.             // panelHandle will only be set if you set about.ConfigurationPanelHeight to a non-zero value
  60.             // keep in mind the panel width is scaled according to the font the user has selected
  61.             // if about.ConfigurationPanelHeight is set to 0, you can display your own popup window
  62.             if (panelHandle != IntPtr.Zero)
  63.             {
  64.                 Panel configPanel = (Panel)Panel.FromHandle(panelHandle);
  65.                 Label prompt = new Label();
  66.                 prompt.AutoSize = true;
  67.                 prompt.Location = new Point(0, 0);
  68.                 prompt.Text = "prompt:";
  69.                 TextBox textBox = new TextBox();
  70.                 textBox.Bounds = new Rectangle(60, 0, 100, textBox.Height);
  71.                 configPanel.Controls.AddRange(new Control[] { prompt, textBox });
  72.             }
  73.             return false;
  74.         }
  75.        
  76.         // called by MusicBee when the user clicks Apply or Save in the MusicBee Preferences screen.
  77.         // its up to you to figure out whether anything has changed and needs updating
  78.         public void SaveSettings()
  79.         {
  80.             // save any persistent settings in a sub-folder of this path
  81.             string dataPath = MbApiInterface.Setting_GetPersistentStoragePath();
  82.         }
  83.  
  84.         // MusicBee is closing the plugin (plugin is being disabled by user or MusicBee is shutting down)
  85.         public void Close(PluginCloseReason reason)
  86.         {
  87.         }
  88.  
  89.         // uninstall this plugin - clean up any persisted files
  90.         public void Uninstall()
  91.         {
  92.         }
  93.  
  94.         // receive event notifications from MusicBee
  95.         // you need to set about.ReceiveNotificationFlags = PlayerEvents to receive all notifications, and not just the startup event
  96.         public void ReceiveNotification(string sourceFileUrl, NotificationType type)
  97.         {
  98.             // perform some action depending on the notification type
  99.             switch (type)
  100.             {
  101.                 case NotificationType.PluginStartup:
  102.                     // perform startup initialisation
  103.                     switch (MbApiInterface.Player_GetPlayState())
  104.                     {
  105.                         case PlayState.Playing:
  106.                         case PlayState.Paused:
  107.                             // ...
  108.                             break;
  109.                     }
  110.                     break;
  111.                 case NotificationType.TrackChanged:
  112.                     string artist = MbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist);
  113.                     // ...
  114.                     break;
  115.             }
  116.         }
  117.  
  118.         // return an array of lyric or artwork provider names this plugin supports
  119.         // the providers will be iterated through one by one and passed to the RetrieveLyrics/ RetrieveArtwork function in order set by the user in the MusicBee Tags(2) preferences screen until a match is found
  120.         public string[] GetProviders()
  121.         {
  122.             return null;
  123.         }
  124.  
  125.         // return lyrics for the requested artist/title from the requested provider
  126.         // only required if PluginType = LyricsRetrieval
  127.         // return null if no lyrics are found
  128.         public string RetrieveLyrics(string sourceFileUrl, string artist, string trackTitle, string album, bool synchronisedPreferred, string provider)
  129.         {
  130.             return null;
  131.         }
  132.  
  133.         // return Base64 string representation of the artwork binary data from the requested provider
  134.         // only required if PluginType = ArtworkRetrieval
  135.         // return null if no artwork is found
  136.         public string RetrieveArtwork(string sourceFileUrl, string albumArtist, string album, string provider)
  137.         {
  138.             //Return Convert.ToBase64String(artworkBinaryData)
  139.             return null;
  140.         }
  141.    }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement