Run black on all Python scripts!
This commit is contained in:
parent
fb6cfce656
commit
cd9cbcaa28
30 changed files with 1027 additions and 704 deletions
|
@ -10,7 +10,7 @@ import re
|
|||
import coloredlogs
|
||||
import progressbar
|
||||
|
||||
coloredlogs.install(level='DEBUG', fmt='%(levelname)s %(message)s')
|
||||
coloredlogs.install(level="DEBUG", fmt="%(levelname)s %(message)s")
|
||||
log = logging.getLogger()
|
||||
|
||||
# Constants
|
||||
|
@ -18,8 +18,14 @@ SOURCE_FOLDER = os.path.join(os.path.expanduser("~"), "Musiques")
|
|||
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",
|
||||
"cover.png", "front.png", "folder.png"]
|
||||
FORGIVEN_FILENAMES = [
|
||||
"cover.jpg",
|
||||
"front.jpg",
|
||||
"folder.jpg",
|
||||
"cover.png",
|
||||
"front.png",
|
||||
"folder.png",
|
||||
]
|
||||
IGNORED_EMPTY_FOLDER = [".stfolder"]
|
||||
RESTRICT_CHARACTERS = '[\0\\/:*"<>|]' # FAT32, NTFS
|
||||
# RESTRICT_CHARACTERS = '[:/]' # HFS, HFS+
|
||||
|
@ -55,7 +61,7 @@ def convertPath(path: str) -> typing.Optional[str]:
|
|||
extension = extension[1:].lower()
|
||||
# Remove unwanted characters from filename
|
||||
filename_parts = os.path.normpath(filename).split(os.path.sep)
|
||||
filename_parts = [re.sub(RESTRICT_CHARACTERS, '_', part) for part in filename_parts]
|
||||
filename_parts = [re.sub(RESTRICT_CHARACTERS, "_", part) for part in filename_parts]
|
||||
filename = os.path.sep.join(filename_parts)
|
||||
# If the extension isn't allowed
|
||||
if extension in FORBIDDEN_EXTENSIONS:
|
||||
|
@ -103,7 +109,7 @@ for sourceFile in remainingConversions:
|
|||
# Converting
|
||||
fullSourceFile = os.path.join(SOURCE_FOLDER, sourceFile)
|
||||
if sourceFile == outputFile:
|
||||
log.debug('%s → %s', fullSourceFile, fullOutputFile)
|
||||
log.debug("%s → %s", fullSourceFile, fullOutputFile)
|
||||
if act and os.path.isfile(fullOutputFile):
|
||||
os.remove(fullOutputFile)
|
||||
os.link(fullSourceFile, fullOutputFile)
|
||||
|
@ -113,19 +119,33 @@ for sourceFile in remainingConversions:
|
|||
log.info("Removing extra files")
|
||||
for extraFile in extraFiles:
|
||||
fullExtraFile = os.path.join(OUTPUT_FOLDER, extraFile)
|
||||
log.debug('× %s', fullExtraFile)
|
||||
log.debug("× %s", fullExtraFile)
|
||||
if act:
|
||||
os.remove(fullExtraFile)
|
||||
|
||||
log.info("Listing files that will be converted")
|
||||
for fullSourceFile, fullOutputFile in conversions:
|
||||
log.debug('%s ⇒ %s', fullSourceFile, fullOutputFile)
|
||||
log.debug("%s ⇒ %s", fullSourceFile, fullOutputFile)
|
||||
|
||||
log.info("Converting files")
|
||||
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]
|
||||
cmd = [
|
||||
"ffmpeg",
|
||||
"-y",
|
||||
"-i",
|
||||
fullSourceFile,
|
||||
"-c:a",
|
||||
"libopus",
|
||||
"-movflags",
|
||||
"+faststart",
|
||||
"-b:a",
|
||||
"128k",
|
||||
"-vbr",
|
||||
"on",
|
||||
"-compression_level",
|
||||
"10",
|
||||
fullOutputFile,
|
||||
]
|
||||
if act:
|
||||
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue