Skip to content

Commit

Permalink
Merge pull request #152 from Nebula-Mechanica/master
Browse files Browse the repository at this point in the history
Attempt to fix discog downloads (#150)
  • Loading branch information
Otiel authored Oct 30, 2020
2 parents 13afd01 + 19b9eb0 commit 42971c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
12 changes: 5 additions & 7 deletions src/BandcampDownloader/Core/DownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,10 @@ private async Task<List<string>> GetArtistDiscographyAsync(List<string> urls) {
}

// 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";

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 }) {
Expand All @@ -467,7 +465,7 @@ private async Task<List<string>> GetArtistDiscographyAsync(List<string> urls) {

int count = albumsUrls.Count;
try {
albumsUrls.AddRange(BandcampHelper.GetAlbumsUrl(htmlCode));
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));
}
Expand Down
10 changes: 2 additions & 8 deletions src/BandcampDownloader/Helpers/BandcampHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,10 @@ public static Album GetAlbum(string htmlCode) {
/// </summary>
/// <param name="htmlCode">The HTML source code of a Bandcamp page.</param>
/// <returns>The albums URL existing on the specified Bandcamp page.</returns>
public static List<string> GetAlbumsUrl(string htmlCode) {
// Get artist bandcamp page
var regex = new Regex("band_url = \"(?<url>.*)\"");
if (!regex.IsMatch(htmlCode)) {
throw new NoAlbumFoundException();
}
string artistPage = regex.Match(htmlCode).Groups["url"].Value;
public static List<string> GetAlbumsUrl(string htmlCode, string artistPage) {

// Get albums ("real" albums or track-only pages) relative urls
regex = new Regex("href=\"(?<url>/(album|track)/.*)\"");
var regex = new Regex("href=\"(?<url>/(album|track)/.*)\"");
if (!regex.IsMatch(htmlCode)) {
throw new NoAlbumFoundException();
}
Expand Down

0 comments on commit 42971c1

Please sign in to comment.