/// <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 URLs referred in the specified URLs.
        /// </summary>
        /// <param name="urls">The URLs.</param>
        private List <String> GetAlbumsUrls(List <String> urls)
        {
            var albumsUrls = new List <String>();

            foreach (String url in urls)
            {
                Log("Retrieving albums referred on " + 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 <String>());
                    }

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

                // Get albums referred on the page
                try {
                    albumsUrls.AddRange(BandcampHelper.GetAlbumsUrl(htmlCode));
                } catch (NoAlbumFoundException) {
                    Log("No referred album could be found on " + url + ". Try to uncheck the \"Force download of all albums\" option",
                        LogType.Error);
                    continue;
                }
            }

            return(albumsUrls);
        }
Пример #4
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);
        }
        /// <summary>
        /// Returns the artists discography from any URL (artist, album, track).
        /// </summary>
        /// <param name="urls">The URLs.</param>
        private async Task <List <string> > GetArtistDiscographyAsync(List <string> urls)
        {
            var albumsUrls = new List <string>();

            foreach (string url in urls)
            {
                LogAdded(this, new LogArgs($"Retrieving artist discography from {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 <string>());
                    }

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

                // Get artist "music" bandcamp page (http://artist.bandcamp.com/music)
                var regex = new Regex("band_url = \"(?<url>.*)\"");
                if (!regex.IsMatch(htmlCode))
                {
                    LogAdded(this, new LogArgs($"No discography could be found on {url}. Try to uncheck the \"Download artist discography\" option", LogType.Error));
                    continue;
                }
                string artistMusicPage = regex.Match(htmlCode).Groups["url"].Value + "/music";

                // Retrieve artist "music" page HTML source code
                using (var webClient = new WebClient()
                {
                    Encoding = Encoding.UTF8
                }) {
                    ProxyHelper.SetProxy(webClient);

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

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

                // Get albums referred on the page
                regex = new Regex("TralbumData.*\n.*url:.*'/music'\n");
                if (!regex.IsMatch(htmlCode))
                {
                    // This seem to be a one-album artist with no "music" page => URL redirects to the unique album URL
                    albumsUrls.Add(url);
                }
                else
                {
                    // We are on a real "music" page
                    try {
                        albumsUrls.AddRange(BandcampHelper.GetAlbumsUrl(htmlCode));
                    } catch (NoAlbumFoundException) {
                        LogAdded(this, new LogArgs($"No referred album could be found on {artistMusicPage}. Try to uncheck the \"Download artist discography\" option", LogType.Error));
                        continue;
                    }
                }
            }

            return(albumsUrls.Distinct().ToList());
        }
        /// <summary>
        /// Returns the artists discography from any URL (artist, album, track).
        /// </summary>
        /// <param name="urls">The URLs.</param>
        private List <String> GetArtistDiscography(List <String> urls)
        {
            var albumsUrls = new List <String>();

            foreach (String url in urls)
            {
                Log($"Retrieving artist discography from {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 <String>());
                    }

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

                // Get artist "music" bandcamp page (http://artist.bandcamp.com/music)
                var regex = new Regex("band_url = \"(?<url>.*)\"");
                if (!regex.IsMatch(htmlCode))
                {
                    Log($"No discography could be found on {url}. Try to uncheck the \"Download artist discography\" option", LogType.Error);
                    continue;
                }
                String artistMusicPage = regex.Match(htmlCode).Groups["url"].Value + "/music";

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

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

                // Get albums referred on the page
                try {
                    albumsUrls.AddRange(BandcampHelper.GetAlbumsUrl(htmlCode));
                } catch (NoAlbumFoundException) {
                    Log($"No referred album could be found on {artistMusicPage}. Try to uncheck the \"Download artist discography\" option", LogType.Error);
                    continue;
                }
            }

            return(albumsUrls);
        }
Пример #7
0
        /// <summary>
        /// Returns the artists discography from any URL (artist, album, track).
        /// </summary>
        /// <param name="urls">The URLs.</param>
        private List <String> GetArtistDiscography(List <String> urls)
        {
            var albumsUrls = new List <String>();

            foreach (String url in urls)
            {
                Log($"Retrieving artist discography from {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 <String>());
                    }

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

                // Get artist "music" bandcamp page (http://artist.bandcamp.com/music)
                var regex = new Regex("band_url = \"(?<url>.*)\"");
                if (!regex.IsMatch(htmlCode))
                {
                    Log($"No discography could be found on {url}. Try to uncheck the \"Download artist discography\" option", LogType.Error);
                    continue;
                }
                String artistMusicPage = regex.Match(htmlCode).Groups["url"].Value + "/music";

                // Retrieve artist "music" page HTML source code
                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 <String>());
                    }

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

                // Get albums referred on the page
                regex = new Regex("TralbumData.*\n.*url:.*'/music'\n");
                if (!regex.IsMatch(htmlCode))
                {
                    // This seem to be a one-album artist with no "music" page => URL redirects to the unique album URL
                    albumsUrls.Add(url);
                }
                else
                {
                    // We are on a real "music" page
                    try {
                        albumsUrls.AddRange(BandcampHelper.GetAlbumsUrl(htmlCode));
                    } catch (NoAlbumFoundException) {
                        Log($"No referred album could be found on {artistMusicPage}. Try to uncheck the \"Download artist discography\" option", LogType.Error);
                        continue;
                    }
                }
            }

            return(albumsUrls);
        }
        /// <summary>
        /// Returns the artists discography from any URL (artist, album, track).
        /// </summary>
        /// <param name="urls">The URLs.</param>
        private async Task <List <string> > GetArtistDiscographyAsync(List <string> urls)
        {
            var albumsUrls = new List <string>();

            foreach (string url in urls)
            {
                LogAdded(this, new LogArgs($"Retrieving artist discography from {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 <string>());
                    }

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

                // Get artist "music" bandcamp page (http://artist.bandcamp.com/music)

                var    regex           = new Regex("https?://[^/]*");
                string artistPage      = regex.Match(url).ToString();
                string artistMusicPage = artistPage + "/music";

                // Retrieve artist "music" page HTML source code
                using (var webClient = new WebClient()
                {
                    Encoding = Encoding.UTF8
                }) {
                    ProxyHelper.SetProxy(webClient);

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

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

                int count = albumsUrls.Count;
                try {
                    albumsUrls.AddRange(BandcampHelper.GetAlbumsUrl(htmlCode, artistPage));
                } catch (NoAlbumFoundException) {
                    LogAdded(this, new LogArgs($"No referred album could be found on {artistMusicPage}. Try to uncheck the \"Download artist discography\" option", LogType.Error));
                }
                if (albumsUrls.Count - count == 0)
                {
                    // This seem to be a one-album artist with no "music" page => URL redirects to the unique album URL
                    albumsUrls.Add(url);
                }
            }

            return(albumsUrls.Distinct().ToList());
        }