本文整理汇总了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); }
}