From f2347ed1ccd368fbd0682543b091abf528c18df4 Mon Sep 17 00:00:00 2001 From: Gwendal Date: Sat, 18 Aug 2018 13:11:41 +0200 Subject: [PATCH] Add error management for when no download links are available --- .../bandcampcollectiondownloader/BandcampCollectionDownloader.kt | 7 ++++--- .../test/BandcampCollectionDownloaderTests.kt | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt b/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt index f68f32b..52141dd 100644 --- a/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt +++ b/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt @@ -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") diff --git a/src/test/kotlin/bandcampcollectiodownloader/test/BandcampCollectionDownloaderTests.kt b/src/test/kotlin/bandcampcollectiodownloader/test/BandcampCollectionDownloaderTests.kt index bb6c6ac..135413c 100644 --- a/src/test/kotlin/bandcampcollectiodownloader/test/BandcampCollectionDownloaderTests.kt +++ b/src/test/kotlin/bandcampcollectiodownloader/test/BandcampCollectionDownloaderTests.kt @@ -46,4 +46,11 @@ class BandcampCollectionDownloaderTests { downloadAll(Paths.get("./test-data/wellformedcookies.json"), "zerz1e3687dfs3df7", "bli", Paths.get("bli")) } } + + @Test + fun testErrorCookiesUselessForBandcampUser() { + assertThrows { + downloadAll(Paths.get("./test-data/wellformedcookies.json"), "bli", "bli", Paths.get("bli")) + } + } } \ No newline at end of file