Skip to content

Commit

Permalink
Make artist and release folder case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Ezwen committed Dec 8, 2020
1 parent 9853ee6 commit 420b427
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.time.format.DateTimeFormatterBuilder
import java.time.temporal.ChronoField
import java.util.*
import java.util.concurrent.*
import java.util.stream.Collectors

object BandcampCollectionDownloader {

Expand Down Expand Up @@ -169,14 +170,29 @@ object BandcampCollectionDownloader {
artist = Util.replaceInvalidCharsByUnicode(artist)

// Prepare artist and release folder
val downloadFolderPath = Paths.get("${args.pathToDownloadFolder}")
val releaseFolderName = "$releaseYear - $releasetitle"
val artistFolderPath = Paths.get("${args.pathToDownloadFolder}").resolve(artist)
val releaseFolderPath = artistFolderPath.resolve(releaseFolderName)
val coverURL = connector.getCoverURL(saleItemId)
var artistFolderPath = downloadFolderPath.resolve(artist)
var releaseFolderPath = artistFolderPath.resolve(releaseFolderName)

// If artist folder exists with different case, use it
val candidateArtistFolders = Files.list(downloadFolderPath).filter { f -> f.fileName.toString().toLowerCase().endsWith(artist.toLowerCase()) }.collect(
Collectors.toList())
if (candidateArtistFolders.isNotEmpty()) {
artistFolderPath = candidateArtistFolders[0]
// If release folder exists with different case, use it
val candidateReleaseFolders = Files.list(artistFolderPath).filter { f -> f.fileName.toString().toLowerCase().endsWith(releaseFolderName.toLowerCase()) }.collect(
Collectors.toList())
if (candidateReleaseFolders.isNotEmpty()) {
releaseFolderPath = candidateReleaseFolders[0]
}
}

Util.log("Starting the download of $printableReleaseName.")
// Find cover URL
val coverURL = connector.getCoverURL(saleItemId)

// Download release, with as many retries as configured
Util.log("Starting the download of $printableReleaseName.")
Util.retry({
val downloadUrl = connector.retrieveRealDownloadURL(saleItemId, args.audioFormat)!!
val downloaded = downloadRelease(downloadUrl, artistFolderPath, releaseFolderPath, isSingleTrack, args.timeout, coverURL)
Expand Down

0 comments on commit 420b427

Please sign in to comment.