Browse Source

Manage error when provided bandcamp user does not exist

master
Gwendal 7 years ago
parent
commit
752a095dde
3 changed files with 23 additions and 3 deletions
  1. +12
    -3
      src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt
  2. +7
    -0
      src/test/kotlin/bandcampcollectiodownloader/test/BandcampCollectionDownloaderTests.kt
  3. +4
    -0
      test-data/wellformedcookies.json

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

@ -3,6 +3,7 @@ package bandcampcollectiondownloader
import com.google.gson.Gson import com.google.gson.Gson
import com.google.gson.JsonSyntaxException import com.google.gson.JsonSyntaxException
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
import org.jsoup.HttpStatusException
import org.jsoup.Jsoup import org.jsoup.Jsoup
import org.zeroturnaround.zip.ZipUtil import org.zeroturnaround.zip.ZipUtil
import java.io.FileOutputStream import java.io.FileOutputStream
@ -125,9 +126,17 @@ fun downloadAll(cookiesFile: Path, bandcampUser: String, downloadFormat: String,
val cookies = parsedCookiesToMap(parsedCookies) val cookies = parsedCookiesToMap(parsedCookies)
// Get collection page with cookies, hence with download links // Get collection page with cookies, hence with download links
val doc = Jsoup.connect("https://bandcamp.com/$bandcampUser")
.cookies(cookies)
.get()
val doc = try {
Jsoup.connect("https://bandcamp.com/$bandcampUser")
.cookies(cookies)
.get()
} catch (e: HttpStatusException) {
if (e.statusCode == 404) {
throw BandCampDownloaderError("The bandcamp user '$bandcampUser' does not exist.")
} else {
throw Exception("TODO")
}
}
println("""Found collection page: "${doc.title()}"""") println("""Found collection page: "${doc.title()}"""")
if (!doc.toString().contains("buy-now")) { if (!doc.toString().contains("buy-now")) {
println("Provided cookies appear to be working!") println("Provided cookies appear to be working!")


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

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

+ 4
- 0
test-data/wellformedcookies.json View File

@ -0,0 +1,4 @@
[{
"Name raw" : "bli",
"Content raw" : "bli"
}]

Loading…
Cancel
Save