Browse Source

Add error management for when no download links are available

master
Gwendal 7 years ago
parent
commit
f2347ed1cc
2 changed files with 11 additions and 3 deletions
  1. +4
    -3
      src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt
  2. +7
    -0
      src/test/kotlin/bandcampcollectiodownloader/test/BandcampCollectionDownloaderTests.kt

+ 4
- 3
src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt View File

@ -138,13 +138,14 @@ fun downloadAll(cookiesFile: Path, bandcampUser: String, downloadFormat: String,
}
}
println("""Found collection page: "${doc.title()}"""")
if (!doc.toString().contains("buy-now")) {
println("Provided cookies appear to be working!")
}
// Get download pages
val collection = doc.select("span.redownload-item a")
if (collection.isEmpty()) {
throw BandCampDownloaderError("No download links could by found in the collection page. This can be caused by an outdated or invalid cookies file.")
}
// For each download page
for (item in collection) {
val downloadPageURL = item.attr("href")


+ 7
- 0
src/test/kotlin/bandcampcollectiodownloader/test/BandcampCollectionDownloaderTests.kt View File

@ -46,4 +46,11 @@ class BandcampCollectionDownloaderTests {
downloadAll(Paths.get("./test-data/wellformedcookies.json"), "zerz1e3687dfs3df7", "bli", Paths.get("bli"))
}
}
@Test
fun testErrorCookiesUselessForBandcampUser() {
assertThrows<BandCampDownloaderError> {
downloadAll(Paths.get("./test-data/wellformedcookies.json"), "bli", "bli", Paths.get("bli"))
}
}
}

Loading…
Cancel
Save