Skip to content

Instantly share code, notes, and snippets.

@EntranceJew
Created July 18, 2023 22:31
Show Gist options
  • Save EntranceJew/bda682decded62e1b7a220e65457c85a to your computer and use it in GitHub Desktop.
Save EntranceJew/bda682decded62e1b7a220e65457c85a to your computer and use it in GitHub Desktop.
a script that can organize your output from bandcamp-downloader.py
$in_dir = (Get-Item .).FullName
$out_dir = (Get-Item .).FullName + "\__sorted__"
Get-ChildItem ((Get-Item $in_dir).FullPath) |
Foreach-Object {
$name = $_.Name
$artist = ''
$found = $false
foreach ($char in $name.ToCharArray()) {
$artist += $char;
$cond = $artist + '-' + $artist + ' - ';
$ext = ($_.Extension).ToLowerInvariant()
$album = "_singles"
try {
if (-not $found -and $name.StartsWith($cond)) {
$filename = $artist + ' - ' + $name.Replace($cond, '', 1)
$fullout = "$($out_dir)\$($artist)"
if (-not (Test-Path "$($fullout)")){
$null = New-Item -ItemType Directory -Force -Path "$($fullout)"
}
if ($ext -eq ".zip") {
if (-not (Test-Path "$($fullout)")){
$null = New-Item -ItemType Directory -Force -Path "$($fullout)"
}
$album = $_.BaseName.Replace($cond, '', 1)
$fullout = "$($out_dir)\$($artist)\$($album)"
Expand-Archive -LiteralPath "$($_.FullName)" -DestinationPath "$($fullout)" -Force
Remove-Item -LiteralPath "$($_.FullName)" -Force
} else {
$fullout = "$($out_dir)\$($artist)\$($album)"
if (-not (Test-Path "$($fullout)")){
$null = New-Item -ItemType Directory -Force -Path "$($fullout)"
}
Move-Item -LiteralPath "$($in_dir)\$($name)" -Destination "$($fullout)\$($filename)"
}
$found = $true;
}
}
catch {
Write-Host "ERROR processing $($name)"
}
}
if(!$found){
Write-Host "nothing in $($name)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment