예제 #1
0
        /*[STAThread]
        static void Main() {
            if(!SoundCloudCore.Connect(new Login(user, pass, ClientID, ClientSecret)))
                return;

            var list = new List<int>();
            for(var i = 0; i < Me.LikesCount; i += 10) {
                if(i >= Me.LikesCount)
                    break;
                list = list.Concat(Me.GetLikedTracks(i, 10)).ToList();
                Console.WriteLine("SEARCHING: " + i + "/" + Me.LikesCount);
            }
            Console.WriteLine("COMPLETED: " + list.Count + " / " + Me.LikesCount + "Track info was downloaded");

            // Download all tracks to folder
            foreach(var id in list)
                DownloadTrack(SoundCloudCore.Tracks[id]);
            Directory.Delete("Images", true);
            Console.ReadLine();
        }*/
        static void DownloadTrack(Track track)
        {
            var wc = new WebClient();
            if(!Directory.Exists("Tracks")) Directory.CreateDirectory("Tracks");
            if(!Directory.Exists("Images")) Directory.CreateDirectory("Images");

            var path = "Tracks\\" + track.Title + ".mp3";
            if(System.IO.File.Exists(path)) return;
            try {

                wc.DownloadFile(new Uri(track.StreamUrl), path);

                // Write tag
                if(!System.IO.File.Exists(path)) return;
                var tag = TagLib.File.Create(path);
                tag.Tag.Title = track.Title;
                tag.Tag.BeatsPerMinute = (uint)track.Bpm;
                tag.Tag.Year = (uint)track.Created.Year;
                // Get track cover

                var imgPath = "Images\\" + track.Title + ".jpg";
                wc.DownloadFile(new Uri(track.GetCover(AlbumSize.x300)), imgPath);
                if(System.IO.File.Exists(imgPath)) {
                    var pic = new IPicture[1];
                    pic[0] = new Picture(imgPath);
                    tag.Tag.Pictures = pic;
                }

                // Save tag info
                tag.Save();
                Console.WriteLine("Downloaded track: " + track.Title);
            }
            catch(Exception ex) { Console.WriteLine("Error downloading track: " + track.Title + "; Exception: " + ex.Message); }
        }