Bloodsucker
This commit is contained in:
parent
6cdd924613
commit
f03d13f7db
8 changed files with 140 additions and 811 deletions
|
@ -15,7 +15,7 @@ log = logging.getLogger()
|
|||
|
||||
# Constants
|
||||
SOURCE_FOLDER = os.path.join(os.path.expanduser("~"), "Musiques")
|
||||
OUTPUT_FOLDER = os.path.join(os.path.expanduser("~"), ".musicCompressed")
|
||||
OUTPUT_FOLDER = os.path.join(os.path.expanduser("~"), ".MusiqueCompressed")
|
||||
CONVERSIONS = {"flac": "opus"}
|
||||
FORBIDDEN_EXTENSIONS = ["jpg", "png", "pdf", "ffs_db"]
|
||||
FORGIVEN_FILENAMES = ["cover.jpg", "front.jpg", "folder.jpg",
|
||||
|
@ -24,6 +24,7 @@ IGNORED_EMPTY_FOLDER = [".stfolder"]
|
|||
RESTRICT_CHARACTERS = '[\0\\/:*"<>|]' # FAT32, NTFS
|
||||
# RESTRICT_CHARACTERS = '[:/]' # HFS, HFS+
|
||||
# RESTRICT_CHARACTERS = '[\0/]' # ext2-4, linux-based?
|
||||
act = True
|
||||
|
||||
# TODO FEAT Make the directory structure the same as the base one and
|
||||
# remove IGNORED_EMPTY_FOLDER variable
|
||||
|
@ -96,13 +97,14 @@ for sourceFile in remainingConversions:
|
|||
# Creating folder if it doesn't exists
|
||||
fullOutputFile = os.path.join(OUTPUT_FOLDER, outputFile)
|
||||
fullOutputDir = os.path.dirname(fullOutputFile)
|
||||
os.makedirs(fullOutputDir, exist_ok=True)
|
||||
if act:
|
||||
os.makedirs(fullOutputDir, exist_ok=True)
|
||||
|
||||
# Converting
|
||||
fullSourceFile = os.path.join(SOURCE_FOLDER, sourceFile)
|
||||
if sourceFile == outputFile:
|
||||
log.debug('%s → %s', fullSourceFile, fullOutputFile)
|
||||
if os.path.isfile(fullOutputFile):
|
||||
if act and os.path.isfile(fullOutputFile):
|
||||
os.remove(fullOutputFile)
|
||||
os.link(fullSourceFile, fullOutputFile)
|
||||
else:
|
||||
|
@ -112,7 +114,8 @@ log.info("Removing extra files")
|
|||
for extraFile in extraFiles:
|
||||
fullExtraFile = os.path.join(OUTPUT_FOLDER, extraFile)
|
||||
log.debug('× %s', fullExtraFile)
|
||||
os.remove(fullExtraFile)
|
||||
if act:
|
||||
os.remove(fullExtraFile)
|
||||
|
||||
log.info("Listing files that will be converted")
|
||||
for fullSourceFile, fullOutputFile in conversions:
|
||||
|
@ -123,11 +126,14 @@ for fullSourceFile, fullOutputFile in progressbar.progressbar(conversions):
|
|||
cmd = ["ffmpeg", "-y", "-i", fullSourceFile, "-c:a", "libopus",
|
||||
"-movflags", "+faststart", "-b:a", "128k", "-vbr", "on",
|
||||
"-compression_level", "10", fullOutputFile]
|
||||
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
if act:
|
||||
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
else:
|
||||
print(cmd)
|
||||
|
||||
# Removing empty dirs
|
||||
for root, dirs, files in os.walk(OUTPUT_FOLDER):
|
||||
if not dirs and not files:
|
||||
dirBasename = os.path.basename(root)
|
||||
if dirBasename not in IGNORED_EMPTY_FOLDER:
|
||||
if act and dirBasename not in IGNORED_EMPTY_FOLDER:
|
||||
os.rmdir(root)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue