From f47a6342fd702ca909575bb9db4d900d340fa580 Mon Sep 17 00:00:00 2001 From: Erin Moon Date: Wed, 3 Jul 2019 02:40:59 -0500 Subject: [PATCH] don't NPE if package_release_date isn't in a datablob gson is happy to push nulls into non-nullable fields because we're handing it a ::class.java. package_release_date sometimes doesn't exist when release_date still does, so make package_release_date properly nullable and fall back to release_date. --- .../bandcampcollectiondownloader/BandcampCollectionDownloader.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt b/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt index eeec17b..76d0240 100644 --- a/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt +++ b/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt @@ -20,7 +20,8 @@ data class ParsedBandcampData( data class DigitalItem( val downloads: Map>, - val package_release_date: String, + val package_release_date: String?, + val release_date: String, val title: String, val artist: String, val download_type: String, @@ -80,7 +81,7 @@ fun downloadAll(cookiesFile: Path?, bandcampUser: String, downloadFormat: String val digitalItem = downloadPageJsonParsed.digital_items[0] var albumtitle = digitalItem.title var artist = digitalItem.artist - val releaseDate = digitalItem.package_release_date + val releaseDate = digitalItem.package_release_date ?: digitalItem.release_date val releaseYear = releaseDate.subSequence(7, 11) val isSingleTrack: Boolean = digitalItem.download_type == "t" val url = digitalItem.downloads[downloadFormat]?.get("url").orEmpty() @@ -207,4 +208,4 @@ fun prepareDownload(albumtitle: String, url: String, cookies: Map