minor reformatting, configurable output dir

This commit is contained in:
Lynne Megido 2020-10-16 16:59:39 +10:00
parent 0ff526b5ca
commit 8cc483bfa8
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90

29
bcao.py
View file

@ -1,9 +1,9 @@
#!/usr/bin/env python3
#BCAO - BandCamp Automatic Organiser
#copyright 2018-2019 @LynnearSoftware@fedi.lynnesbian.space
#Licensed under the GPLv3: https://www.gnu.org/licenses/gpl-3.0.html#content
#input: a .zip from bandcamp
#output: it organises it, adds cover art, puts it in the right place...
# BCAO - BandCamp Automatic Organiser
# copyright 2018-2019 @LynnearSoftware@fedi.lynnesbian.space
# Licensed under the GPLv3: https://www.gnu.org/licenses/gpl-3.0.html#content
# input: a .zip from bandcamp
# output: it organises it, adds cover art, puts it in the right place...
import subprocess, argparse, sys, os, re, base64
@ -32,9 +32,10 @@ except:
parser = argparse.ArgumentParser(description = "BandCamp Automatic Organiser. Extracts the given zip file downloaded from Bandcamp and organises it.")
parser.add_argument('zip', help='The zip file to use')
#KEEP THESE IN ALPHABETICAL ORDER!
parser.add_argument('-q','--quiet', dest='quiet', action='store_true', help='Disable non-error output')
parser.add_argument('-t','--threshold', dest='threshold', nargs=1, default=300, help="Maximum acceptable cover art file size in kilobytes. Default: 300")
# KEEP THESE IN ALPHABETICAL ORDER!
parser.add_argument('-d', '--destination', dest='destination', default='/home/lynne/Music/Music/', help="The directory to organise the music into. Default: /home/lynne/Music/Music/")
parser.add_argument('-q', '--quiet', dest='quiet', action='store_true', help='Disable non-error output')
parser.add_argument('-t', '--threshold', dest='threshold', nargs=1, default=300, help="Maximum acceptable cover art file size in kilobytes. Default: 300")
args=parser.parse_args()
@ -65,19 +66,19 @@ bannedCharacters = ["?", "\\", "/", ":", "|", "*", "\"", "<", ">"] #characters t
trackCount = 0
print("Processing... please wait.")
#use "01 Song.ogg" instead of "1 Song.ogg". Also works for albums with more than 99 tracks if that ever happens
# use "01 Song.ogg" instead of "1 Song.ogg". Also works for albums with more than 99 tracks if that ever happens
trackNumberLength = len(str(len(files)))
if trackNumberLength < 2:
trackNumberLength = 2
for file in files:
if os.path.basename(file).lower() in ["cover.png", "cover.jpg", "cover.gif"]:
#we've found our cover art
# we've found our cover art
cover = file
ext = re.search(fileExtensionRegex, file.lower()).group(0)
if ext in musicExts:
if re.search(probablyASongRegex, file) != None:
#this is definitely a song and probably not a bonus sound file or whatever
# this is definitely a song and probably not a bonus sound file or whatever
if ext == "ogg":
f = OggVorbis(file)
name = "{0} {1}.{2}".format(f["TRACKNUMBER"][0].zfill(trackNumberLength), f["TITLE"][0], ext)
@ -98,7 +99,7 @@ if len(artists) > 1:
artists.append("Various Artists")
if cover == "":
#TODO: HANDLE THIS PROPERLY
# TODO: HANDLE THIS PROPERLY
print("couldn't find the cover art :)))))")
sys.exit(1)
@ -154,7 +155,7 @@ if choice == "Custom...":
# print("Setting artist to {0}".format(choice))
artist = choice
mPath = "/home/lynne/Music/Music/{}/{}".format(artist, album) #todo: don't hardcode this
mPath = "{}/{}/{}".format(args.destination, artist, album)
subprocess.check_output(["mkdir", "-p", mPath])
for root, dirs, filez in os.walk(tmp):
@ -164,4 +165,4 @@ for root, dirs, filez in os.walk(tmp):
print("Deleting {}...".format(tmp))
subprocess.check_output(["rm", "-rf", tmp])
print("Done!")
print("Done!")