Example #1
0
        public ObsessedForm(Plugin.MusicBeeApiInterface pApi)
        {
            // C:\MusicBee\AppData\LastFmScrobbles.log | Scrobble log location
            InitializeComponent();

            // --------Initializing lastfm api--------
            string  apikey    = app.Default.API_KEY;    //ConfigurationManager.AppSettings["API_KEY"];
            string  secretkey = app.Default.SECRET_KEY; //ConfigurationManager.AppSettings["SECRET_KEY"];
            Session session   = new Session(apikey, secretkey);
            string  usr       = pApi.Setting_GetLastFmUserId();

            // -------- URL Construction --------
            string root = "http://ws.audioscrobbler.com/2.0/?";

            string m_topTracks = "method=user.gettoptracks&user="******"method=user.gettopalbums&user="******"method=user.getrecenttracks&user="******"&limit=200";
            string pages          = "&page=";
            int    pageNum        = 1;
            string tail           = "&api_key=" + apikey + "&format=json";
            // ---------------------------------------

            string url = root + m_recentTracks + limit + pages + pageNum + tail;

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

            var response = (HttpWebResponse)request.GetResponse();

            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();


            // Use QueryFilesEx to get the fileURLs
            pApi.Library_QueryFilesEx("domain=SelectedFiles", out String[] files); // files contains the fileURL for a selected track(s)

            string[] lines = System.IO.File.ReadAllLines(@"C:\MusicBee\AppData\LastFmScrobble.log");

            string artist = pApi.Library_GetFileTag(files[0], Plugin.MetaDataType.Artist);
            string title  = pApi.Library_GetFileTag(files[0], Plugin.MetaDataType.TrackTitle);
            int    plays  = Int32.Parse(pApi.Library_GetFileTag(files[0], (Plugin.MetaDataType) 14));

            string added = pApi.Library_GetFileProperty(files[0], Plugin.FilePropertyType.DateAdded); //Date the selected track was added to the library


            string track = artist + " - " + title;                 // Consolidation for matching in the scrobble log

            List <DateTime> history = filter(lines, track, plays); // history contains the history of scrobbles for a given track represented in unix time.

            if (history.Count <= 1)
            {
                label1.Text = "Not enough scrobbles for this track";
            }
            else
            {
                label1.Text = responseString + "";// +" | "+obsession(history, added, title, artist, plays);
            }
        }
Example #2
0
        public List <MbSong> GetMbSongs()
        {
            string[]      files      = null;
            List <MbSong> allMbSongs = new List <MbSong>();

            if (_mbApiInterface.Library_QueryFiles("domain=library"))
            {
                // Old (deprecated)
                //public char[] filesSeparators = { '\0' };
                //files = _mbApiInterface.Library_QueryGetAllFiles().Split(filesSeparators, StringSplitOptions.RemoveEmptyEntries);
                _mbApiInterface.Library_QueryFilesEx("domain=library", ref files);
            }
            else
            {
                files = new string[0];
            }

            foreach (string path in files)
            {
                MbSong thisSong = new MbSong();
                thisSong.Filename = path;
                thisSong.Artist   = _mbApiInterface.Library_GetFileTag(path, Plugin.MetaDataType.Artist);
                thisSong.Title    = _mbApiInterface.Library_GetFileTag(path, Plugin.MetaDataType.TrackTitle);
                allMbSongs.Add(thisSong);
            }
            return(allMbSongs);
        }
Example #3
0
 public PostPlayAlbum()
 {
     Post["/play-album"] = _ =>
     {
         Plugin.MusicBeeApiInterface mbApi = MbApiInstance.Instance.MusicBeeApiInterface;
         string[] album = null;
         mbApi.Library_QueryFilesEx($"Artist={Request.Query.artist}\0Album={Request.Query.album}", ref album);
         mbApi.NowPlayingList_Clear();
         mbApi.NowPlayingList_QueueFilesNext(album);
         mbApi.Player_PlayNextTrack();
         return(album);
     };
 }
Example #4
0
        public GetArtwork()
        {
            Get["/artwork"] = _ =>
            {
                Plugin.MusicBeeApiInterface mbApi            = MbApiInstance.Instance.MusicBeeApiInterface;
                PictureLocations            pictureLocations = PictureLocations.None;
                string[] album = null;
                mbApi.Library_QueryFilesEx($"Artist={Request.Query.artist}\0Album={Request.Query.album}", ref album);
                string pictureUrl = null;
                byte[] image      = null;
                mbApi.Library_GetArtworkEx(album[0], 0, true, ref pictureLocations, ref pictureUrl, ref image);

                if (Request.Query.thumbnail)
                {
                    try
                    {
                        byte[] thumbnail = new ThumbnailCreator().CreateThumbnailBytes(thumbnailSize: 400, imageBytes: image, imageFormat: Format.Jpeg);
                        string color     = GetColor(thumbnail);
                        return(WriteJson(Convert.ToBase64String(thumbnail), false, color));
                    }
                    catch (Exception e)
                    {
                        if (e.Message == "Thumbnail size must be less than image's size")
                        {
                            string color = GetColor(image);
                            return(WriteJson(Convert.ToBase64String(image), false, color));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    return(Convert.ToBase64String(image));
                }
            };
        }