当前位置: 首页>>代码示例>>C#>>正文


C# Track.GetCover方法代码示例

本文整理汇总了C#中Track.GetCover方法的典型用法代码示例。如果您正苦于以下问题:C# Track.GetCover方法的具体用法?C# Track.GetCover怎么用?C# Track.GetCover使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Track的用法示例。


在下文中一共展示了Track.GetCover方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        /*[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); }
        }
开发者ID:jpmckearin,项目名称:SoundStreamer,代码行数:54,代码来源:Program.cs


注:本文中的Track.GetCover方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。