Пример #1
0
        public PassArguments GetSpotifyName(string query)//Uptaded to use new API
        {
            string getData = null;
            while (true)
            {
                try
                {
                    WebClient c = new WebClient();
                    getData = c.DownloadString("https://api.spotify.com/v1/tracks/" + query);
                    break;
                }
                catch (Exception)
                {
                    Thread.Sleep(500);
                }
            }
            
            JObject o = JObject.Parse(getData);
            string name = o["name"].ToString();
            string artist = o["artists"][0]["name"].ToString();
            string albumId = o["artists"][0]["id"].ToString();
            string album = o["album"]["name"].ToString();
            string imageURL = o["album"]["images"][0]["url"].ToString();
            double lengthMs = double.Parse(o["duration_ms"].ToString());
            double length = MillisecondsTimeSpanToHms(double.Parse(o["duration_ms"].ToString()));

            name = Encoding.UTF8.GetString(Encoding.Default.GetBytes(name));
            artist = Encoding.UTF8.GetString(Encoding.Default.GetBytes(artist));
            album = Encoding.UTF8.GetString(Encoding.Default.GetBytes(album));

            PassArguments pass = new PassArguments
            {
                PassedSong = name,
                PassedArtist = artist,
                PassedAlbum = album,
                PassedAlbumId = albumId,
                PassedFileName = name + " - " + artist,
                PassedLength = length,
                PassedLengthMs = lengthMs,
                PassedimageURL = imageURL
            };
            return pass;
        }
Пример #2
0
 private void listView1_DragDrop(object sender, DragEventArgs e)
 {
     try
     {
         if (e.Data.GetDataPresent(DataFormats.StringFormat))
         {
             _current++;
             songArray[_current] = new PassArguments[10000];
             string data = (string)e.Data.GetData(DataFormats.StringFormat);
             data = data.Replace("http://open.spotify.com/track/", "");
             string[] strArrays = data.Split(new char[] { '\n' });
             _songs = _songs + strArrays.Length;
             songsArray[_current] = strArrays.Length;
             Log("Loading " + strArrays.Length + " songs...");
             foreach (string str in strArrays)
             {
                 if (str.Length > 1)
                 {
                     BackgroundWorker backgroundWorkerStart = new BackgroundWorker();
                     backgroundWorkerStart.DoWork += backgroundWorkerStart_DoWork;
                     backgroundWorkerStart.RunWorkerAsync(new PassArguments
                     {
                         PassedSpotCode = str,
                         PassedSession = _current
                     });
                 }
             }
         }
     }
     catch (Exception ex) { MessageBox.Show(this, ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); }
 }