diff --git a/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt b/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt index 05f0860..bf8d626 100644 --- a/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt +++ b/src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt @@ -56,7 +56,6 @@ fun parsedCookiesToMap(parsedCookies: Array): Map return result } -const val BUFFER_SIZE = 4096 /** * Core function called from the main @@ -143,14 +142,16 @@ private fun retrieveFirefoxCookies(): HashMap { val firefoxConfDirPath: Path? - firefoxConfDirPath = if (isUnix()) { - val homeDir = Paths.get(System.getenv()["HOME"]) - homeDir.resolve(".mozilla/firefox") - } else if (isWindows()) { - val appdata = Paths.get(System.getenv("APPDATA")) - appdata.resolve("mozilla/firefox") - } else { - throw BandCampDownloaderError("No available cookies or not supported OS!") + firefoxConfDirPath = when { + isUnix() -> { + val homeDir = Paths.get(System.getenv()["HOME"]) + homeDir.resolve(".mozilla/firefox") + } + isWindows() -> { + val appdata = Paths.get(System.getenv("APPDATA")) + appdata.resolve("mozilla/firefox") + } + else -> throw BandCampDownloaderError("OS not supported, cannot find Firefox cookies!") } val profilesListPath = firefoxConfDirPath.resolve("profiles.ini") diff --git a/src/main/kotlin/bandcampcollectiondownloader/Main.kt b/src/main/kotlin/bandcampcollectiondownloader/Main.kt index 7dcb832..edacf69 100644 --- a/src/main/kotlin/bandcampcollectiondownloader/Main.kt +++ b/src/main/kotlin/bandcampcollectiondownloader/Main.kt @@ -7,28 +7,22 @@ import java.nio.file.Paths data class Args( @CommandLine.Parameters(arity = "1..1", - description = arrayOf("The bandcamp user account from which all albums must be downloaded.")) + description = ["The bandcamp user account from which all albums must be downloaded."]) var bandcampUser: String = "", - @CommandLine.Option(names = arrayOf("--cookies-file", "-c"), required = false, - description = arrayOf("A JSON file with valid bandcamp credential cookies.", - """"Cookie Quick Manager" can be used to obtain this file after logging into bandcamp.""", - "(visit https://addons.mozilla.org/en-US/firefox/addon/cookie-quick-manager/).", - "If no cookies file is provided, cookies from the local Firefox installation are used (Windows and Linux only).")) + @CommandLine.Option(names = ["--cookies-file", "-c"], required = false, + description = ["A JSON file with valid bandcamp credential cookies.", """"Cookie Quick Manager" can be used to obtain this file after logging into bandcamp.""", "(visit https://addons.mozilla.org/en-US/firefox/addon/cookie-quick-manager/).", "If no cookies file is provided, cookies from the local Firefox installation are used (Windows and Linux only)."]) var pathToCookiesFile: Path? = null, - @CommandLine.Option(names = arrayOf("--audio-format", "-f"), required = false, - description = arrayOf("The chosen audio format of the files to download (default: \${DEFAULT-VALUE}).", - "Possible values: flac, wav, aac-hi, mp3-320, aiff-lossless, vorbis, mp3-v0, alac.")) + @CommandLine.Option(names = ["--audio-format", "-f"], required = false, + description = ["The chosen audio format of the files to download (default: \${DEFAULT-VALUE}).", "Possible values: flac, wav, aac-hi, mp3-320, aiff-lossless, vorbis, mp3-v0, alac."]) var audioFormat: String = "vorbis", - @CommandLine.Option(names = arrayOf("--download-folder", "-d"), required = false, - description = arrayOf("The folder in which downloaded albums must be extracted.", - "The following structure is considered: // - .", - "(default: current folder)")) + @CommandLine.Option(names = ["--download-folder", "-d"], required = false, + description = ["The folder in which downloaded albums must be extracted.", "The following structure is considered: // - .", "(default: current folder)"]) var pathToDownloadFolder: Path = Paths.get("."), - @CommandLine.Option(names = arrayOf("-h", "--help"), usageHelp = true, description = arrayOf("Display this help message.")) + @CommandLine.Option(names = ["-h", "--help"], usageHelp = true, description = ["Display this help message."]) var help: Boolean = false ) @@ -63,7 +57,7 @@ fun main(args: Array) { val downloadFolder = parsedArgs.pathToDownloadFolder try { downloadAll(cookiesFile, bandcampUser, downloadFormat, downloadFolder) - } catch (e : BandCampDownloaderError) { + } catch (e: BandCampDownloaderError) { System.err.println("ERROR: ${e.message}") } diff --git a/src/main/kotlin/bandcampcollectiondownloader/Util.kt b/src/main/kotlin/bandcampcollectiondownloader/Util.kt index 193ee45..148cef3 100644 --- a/src/main/kotlin/bandcampcollectiondownloader/Util.kt +++ b/src/main/kotlin/bandcampcollectiondownloader/Util.kt @@ -7,6 +7,7 @@ import java.nio.file.Path import java.nio.file.Paths import javax.mail.internet.ContentDisposition +const val BUFFER_SIZE = 4096 /** * From http://www.codejava.net/java-se/networking/use-httpurlconnection-to-download-file-from-an-http-url