示例#1
0
        private void btn_createPlaylist_Click(object sender, EventArgs e)
        {
            if (playlistsloaded && saveplaylistfilenamechoosen && useLocalDB)
            {
                string id = (cmb_selectPlaylist.SelectedItem as playlists.Item).id;
                // Get the tracks from the playlist
                // Get list of playlists
                // Create an api request
                var httpWebRequest1 = (HttpWebRequest)WebRequest.Create("https://api.spotify.com/v1/playlists/" + id + "/tracks?market=ES&limit=100&offset=0");
                httpWebRequest1.ContentType = "application/json";
                httpWebRequest1.Accept      = "application/json";
                httpWebRequest1.Method      = "GET";
                httpWebRequest1.Headers.Add("Authorization", "Bearer " + txt_accessToken.Text); // oAuthToken);

                try
                {
                    var httpResponse1 = (HttpWebResponse)httpWebRequest1.GetResponse();
                    using (var streamReader1 = new StreamReader(httpResponse1.GetResponseStream()))
                    {
                        // Parse the returned json to a c# object
                        string        response = streamReader1.ReadToEnd();
                        playlist      playlist = Newtonsoft.Json.JsonConvert.DeserializeObject <playlist>(response);
                        List <string> ids      = new List <string>();
                        foreach (playlist.Item item in playlist.items)
                        {
                            ids.Add(item.track.id);
                        }
                        List <song> songs = new List <song>();
                        foreach (string ID in ids)
                        {
                            song tmp = DB_Handler.get_song(ID);
                            if (tmp != null)
                            {
                                songs.Add(tmp);
                            }
                        }
                        foreach (var item in songs)
                        {
                            Console.WriteLine(item.local_Info.path);
                        }
                        m3u_Handler m3u = new m3u_Handler();
                        m3u.create_m3u(saveplaylistfilename, songs);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("You need to select a file to save to, you need to have a list of your playlists loaded and you need mongodb installed.");
            }
        }
示例#2
0
        // Inserts song into database
        public void insertSong(currentlyplaying currentlyplaying_, string path_, bool downloaded_, DateTime dateTime_)
        {
            var client   = new MongoClient("mongodb://localhost:27017");
            var db       = client.GetDatabase(database_name);
            var coll     = db.GetCollection <song>(collection_name);
            var document = new song();

            document.song_info             = currentlyplaying_;
            document.local_Info            = new song.Local_info();
            document.local_Info.path       = path_;
            document.local_Info.downloaded = downloaded_;
            document.local_Info.time       = dateTime_;
            coll.InsertOne(document);
        }