コード例 #1
0
        public TrackViewItem(Track track)
        {
            Track = track;

            Text = track.User.Username;
            SubItems.Add(track.Title);
        }
コード例 #2
0
        public async Task<byte[]> DownloadTrack(Track track)
        {
            if (track.Streamable.GetValueOrDefault(true))
                return await DownloadTrackSecondary(track);

            var url = string.Format("tracks/{0}/stream?client_id={1}",
                track.Id, _clientId);

            return await _client.GetByteArrayAsync(url);
        }
コード例 #3
0
        public async Task<byte[]> DownloadTrackSecondary(Track track)
        {
            await Task.Delay(2000);

            var postData = new FormUrlEncodedContent(new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>("url", track.PermalinkUrl)
            });

            var downloadRequest = await _client.PostAsync(Config.SecondaryDownloadProvider, postData);
            var downloadContent = await downloadRequest.Content.ReadAsStringAsync();
            var url = Config.DownloaderRegex.Match(downloadContent).Groups[1].Value;

            return await _client.GetByteArrayAsync(url);
        }
コード例 #4
0
        private static string GetTrackPath(Track track, string downloadLocation, bool splitArtists)
        {
            var sanitizedArtist = track.User.Username.SanitizeForPath();
            var sanitizedName = track.Title.SanitizeForFile();

            var directoryPath = !splitArtists
                ? downloadLocation
                : Path.Combine(downloadLocation, sanitizedArtist);

            Directory.CreateDirectory(directoryPath);
            return Path.Combine(directoryPath, sanitizedName + ".mp3");
        }
コード例 #5
0
 private void SetID3Tags(Track track, string path)
 {
     try
     {
         var tagger = new UltraID3();
         tagger.Read(path);
         tagger.Title = track.Title;
         tagger.Artist = track.User.Username;
         tagger.Genre = track.Genre;
         tagger.Write();
     }
     catch (Exception ex)
     {
         LogSpecial("Error tagging ", string.Empty, ".", track.Title, string.Empty);
         Log(ex.Message);
     }
 }
コード例 #6
0
        private async Task DownloadTrack(Track track)
        {
            var path = GetTrackPath(track, downloadFolderTextBox.Text,
                splitArtistsCheckBox.Checked);

            if (!overwriteCheckBox.Checked && File.Exists(path))
                return;

            for (var i = 0; i < 2; i++)
            {
                var service = i == 0 ? "SoundCloud" : "secondary";

                try
                {
                    LogSpecial("Downloading ", " from ", ".", track.Title, service);
                    var trackBytes = i == 0
                        ? await _provider.DownloadTrack(track)
                        : await _provider.DownloadTrackSecondary(track);

                    File.WriteAllBytes(path, trackBytes);

                    if (setID3TagCheckBox.Checked)
                        SetID3Tags(track, path);

                    break;
                }
                catch (Exception ex)
                {
                    LogSpecial("Error downloading ", " from ", ".", track.Title, service);
                    Log(ex.Message);
                }
            }
        }