getmusicbee.com

Support => Developers' Area => MusicBee API => Topic started by: tumuyan on October 10, 2020, 08:49:18 PM

Title: album cover plug have some problems
Post by: tumuyan on October 10, 2020, 08:49:18 PM
I'm working on a plugin for getting album covers. Currently there are some problems.
1. The cover url is correctly. But at musicbee is showing that the search cover doesn't match the results.
I don't have experience in developing C# software, the following code to get the image and convert it to byte[] is copy from google. is there something wrong?
2. I have set the plug-in name, in the settings interface shows normal, but the search interface shows "plug" not display the correct name. Why and how to change it?
3. Is there an open source album cover plug-in I can refer to? I didn't find it on github.


Code
  

        public PluginInfo Initialise(IntPtr apiInterfacePtr)
        {
            mbApiInterface = new MusicBeeApiInterface();
            mbApiInterface.Initialise(apiInterfacePtr);
            about.PluginInfoVersion = PluginInfoVersion;
            about.Name = "Douban Music";
            about.Description = "Get information from douban music";
            about.Author = "Tumuyan";
            about.TargetApplication = "";   //  the name of a Plugin Storage device or panel header for a dockable panel
            about.Type = PluginType.ArtworkRetrieval;
            about.VersionMajor = 1;  // your plugin version
            about.VersionMinor = 0;
            about.Revision = 1;
            about.MinInterfaceVersion = MinInterfaceVersion;
            about.MinApiRevision = MinApiRevision;
            about.ReceiveNotifications = (ReceiveNotificationFlags.PlayerEvents | ReceiveNotificationFlags.TagEvents);
            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
            return about;
        }

...

        public string[] GetProviders()
        {

            string[] s = { "Douban" };
            return s;
        }

public string RetrieveArtwork(string sourceFileUrl, string albumArtist, string album, string provider){
      // url builder is removed to debug    ....

              string url = "https://img1.doubanio.com/view/subject/public/s28790429.jpg";

            var request2 = (HttpWebRequest)WebRequest.Create(url);

            byte[] bytes;
            using (Stream stream = request2.GetResponse().GetResponseStream())
            {
                using (MemoryStream mstream = new MemoryStream())
                {
                    int count = 0;
                    byte[] buffer = new byte[1024];
                    int readNum = 0;
                    while ((readNum = stream.Read(buffer, 0, 1024)) > 0)
                    {
                        count = count + readNum;
                        mstream.Write(buffer, 0, readNum);
                    }
                    mstream.Position = 0;
                    using (BinaryReader br = new BinaryReader(mstream))
                    {
                        bytes = br.ReadBytes(count);
                    }
                }
            }
            return Convert.ToBase64String(bytes);

        }

(https://i.loli.net/2020/10/11/bOryvhcXtBI4Mnf.png)
Title: Re: album cover plug have some problems
Post by: Steven on October 10, 2020, 10:39:07 PM
The function should return the url of the image eg. "https://img1.doubanio.com/view/subject/public/s28790429.jpg" from your example
Title: Re: album cover plug have some problems
Post by: tumuyan on October 11, 2020, 03:10:23 AM
i have upload a screenshot. it is strange. actualy the plug doesn‘t shows this image but shows not match.
and the plug name is not same as I set, only shows "plug"
Title: Re: album cover plug have some problems
Post by: Steven on October 11, 2020, 05:02:26 AM
did you change your code to return the url of the artwork? - the code you provided returns the decoded bitmap data which is not what musicbee expects
Title: Re: album cover plug have some problems
Post by: tumuyan on October 11, 2020, 05:55:10 AM
Oh, it's working fine now.
I was misled by the comments in the sample project.
The function only need return the url, I mistakenly thought I needed to return a encode bin file.

Code

        // return Base64 string representation of the artwork binary data from the requested provider
        // only required if PluginType = ArtworkRetrieval
        // return null if no artwork is found


Now only the plug-in name shows "plugin" not defined name
Title: Re: album cover plug have some problems
Post by: Steven on October 11, 2020, 07:52:43 AM
That documentation is very old and now incorrect.
Title: Re: album cover plug have some problems
Post by: tumuyan on October 13, 2020, 04:50:32 AM
hi steven,
I find that the find artwork panel could only show only one  artwork plugin search result ,no matter how many plugins ars applied. and the result resource is named as plugin
Title: Re: album cover plug have some problems
Post by: Steven on October 13, 2020, 07:51:41 AM
Yes thats all that is currently supported - as long as you return all the artwork sources in the GetProviders() function, then the user can prioritise the providers and the first artwork in order of that priority is displayed.
Title: Re: album cover plug have some problems
Post by: tumuyan on October 13, 2020, 05:26:31 PM
I don't understand the current design. They are also artwork providers, why do user-added plugins only share one position in the search panel and named as “plug-in", but the original plugins have separate position and have name?
I think that although in most cases the providers download artworks automatically,  sometimes user needs to show all the results from the providers and pick the most suitable one by himself.
Due to my somewhat poor network, I found that the search for Artwork seems to be in a single thread, with the first provide getting the image url then the latter provider starts running. Wouldn't you consider changing to a multi-threaded operation to speed up the search action?