Browse Source

Minor cosmetic refactorings

master
Gwendal 7 years ago
parent
commit
f7ad737181
3 changed files with 20 additions and 24 deletions
  1. +10
    -9
      src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt
  2. +9
    -15
      src/main/kotlin/bandcampcollectiondownloader/Main.kt
  3. +1
    -0
      src/main/kotlin/bandcampcollectiondownloader/Util.kt

+ 10
- 9
src/main/kotlin/bandcampcollectiondownloader/BandcampCollectionDownloader.kt View File

@ -56,7 +56,6 @@ fun parsedCookiesToMap(parsedCookies: Array<ParsedCookie>): Map<String, String>
return result
}
const val BUFFER_SIZE = 4096
/**
* Core function called from the main
@ -143,14 +142,16 @@ private fun retrieveFirefoxCookies(): HashMap<String, String> {
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")


+ 9
- 15
src/main/kotlin/bandcampcollectiondownloader/Main.kt View File

@ -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: <pathToDownloadFolder>/<artist>/<year> - <album>.",
"(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: <pathToDownloadFolder>/<artist>/<year> - <album>.", "(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<String>) {
val downloadFolder = parsedArgs.pathToDownloadFolder
try {
downloadAll(cookiesFile, bandcampUser, downloadFormat, downloadFolder)
} catch (e : BandCampDownloaderError) {
} catch (e: BandCampDownloaderError) {
System.err.println("ERROR: ${e.message}")
}


+ 1
- 0
src/main/kotlin/bandcampcollectiondownloader/Util.kt View File

@ -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


Loading…
Cancel
Save