/// <summary>
        /// Returns the albums located at the specified URLs.
        /// </summary>
        /// <param name="urls">The URLs.</param>
        private async Task <List <Album> > GetAlbumsAsync(List <string> urls)
        {
            var albums = new List <Album>();

            foreach (string url in urls)
            {
                LogAdded(this, new LogArgs($"Retrieving album data for {url}", LogType.Info));

                // Retrieve URL HTML source code
                string htmlCode = "";
                using (var webClient = new WebClient()
                {
                    Encoding = Encoding.UTF8
                }) {
                    ProxyHelper.SetProxy(webClient);

                    if (_cancelDownloads)
                    {
                        // Abort
                        return(new List <Album>());
                    }

                    try {
                        htmlCode = await webClient.DownloadStringTaskAsync(url);
                    } catch {
                        LogAdded(this, new LogArgs($"Could not retrieve data for {url}", LogType.Error));
                        continue;
                    }
                }

                // Get info on album
                try {
                    Album album = BandcampHelper.GetAlbum(htmlCode);

                    if (album.Tracks.Count > 0)
                    {
                        albums.Add(album);
                    }
                    else
                    {
                        LogAdded(this, new LogArgs($"No tracks found for {url}, album will not be downloaded", LogType.Warning));
                    }
                } catch {
                    LogAdded(this, new LogArgs($"Could not retrieve album info for {url}", LogType.Error));
                    continue;
                }
            }

            return(albums);
        }
示例#2
0
        /// <summary>
        /// Returns the albums located at the specified URLs.
        /// </summary>
        /// <param name="urls">The URLs.</param>
        private List <Album> GetAlbums(List <String> urls)
        {
            var albums = new List <Album>();

            foreach (String url in urls)
            {
                Log($"Retrieving album data for {url}", LogType.Info);

                // Retrieve URL HTML source code
                String htmlCode = "";
                using (var webClient = new WebClient()
                {
                    Encoding = Encoding.UTF8
                }) {
                    if (webClient.Proxy != null)
                    {
                        webClient.Proxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
                    }

                    if (this.userCancelled)
                    {
                        // Abort
                        return(new List <Album>());
                    }

                    try {
                        htmlCode = webClient.DownloadString(url);
                    } catch {
                        Log($"Could not retrieve data for {url}", LogType.Error);
                        continue;
                    }
                }

                // Get info on album
                try {
                    albums.Add(BandcampHelper.GetAlbum(htmlCode));
                } catch {
                    Log($"Could not retrieve album info for {url}", LogType.Error);
                    continue;
                }
            }

            return(albums);
        }
示例#3
0
        /// <summary>
        /// Returns the albums located at the specified URLs.
        /// </summary>
        /// <param name="urls">The URLs.</param>
        private List <Album> GetAlbums(List <String> urls)
        {
            var albums = new List <Album>();

            foreach (String url in urls)
            {
                Log("Retrieving album data for " + url, LogType.Info);

                // Retrieve URL HTML source code
                String htmlCode = "";
                using (var webClient = new WebClient()
                {
                    Encoding = Encoding.UTF8
                }) {
                    if (this.userCancelled)
                    {
                        // Abort
                        return(new List <Album>());
                    }

                    try {
                        htmlCode = webClient.DownloadString(url);
                    } catch {
                        Log("Could not retrieve data for " + url, LogType.Error);
                        continue;
                    }
                }

                // Get info on album
                try {
                    albums.Add(BandcampHelper.GetAlbum(htmlCode));
                } catch {
                    Log("Could not retrieve album info for " + url, LogType.Error);
                    continue;
                }
            }

            return(albums);
        }