encode_audio.py: v1.0.7
Make it PEP8 compliant (as per flake8 standards)
This commit is contained in:
parent
c6ab4b134b
commit
b8b3d3643d
|
@ -18,17 +18,18 @@ import tempfile
|
|||
|
||||
__author__ = "LightArrowsEXE"
|
||||
__license__ = 'MIT'
|
||||
__version__ = '1.0.6'
|
||||
__version__ = '1.0.7'
|
||||
|
||||
|
||||
ignored_formats = ["audio/opus", "audio/aac"]
|
||||
|
||||
|
||||
def main():
|
||||
filelist = glob.glob('**/*', recursive=True) if args.recursive else glob.glob('*')
|
||||
filelist = (glob.glob('**/*', recursive=True)
|
||||
if args.recursive else glob.glob('*'))
|
||||
|
||||
for f in filelist:
|
||||
mime = mimetypes.types_map.get(os.path.splitext(f)[-1], "")
|
||||
mime = mimetypes.types_map.get(os.pathsplitext(f)[-1], "")
|
||||
if f.endswith('.m2ts'):
|
||||
encode(f, wav_only=True)
|
||||
elif mime.startswith("audio/") or mime.startswith("video/"):
|
||||
|
@ -37,22 +38,26 @@ def main():
|
|||
|
||||
|
||||
def encode_flac(f):
|
||||
subprocess.run(["eac3to", f, "-log=NUL", f"{os.path.splitext(f)[0]}.flac"])
|
||||
subprocess.run(["eac3to", f, "-log=NUL", f"{os.pathsplitext(f)[0]}.flac"])
|
||||
|
||||
|
||||
def encode_aac(f):
|
||||
temp = tempfile.mkstemp(prefix=f"{os.path.splitext(f)[0]}_")
|
||||
subprocess.run(["ffmpeg", "-i", f, "-loglevel", "panic", "-stats", f"{temp[1]}.wav"])
|
||||
subprocess.run(["qaac", f"{temp[1]}.wav", "-V 127", "--no-delay", "-o", f"{os.path.splitext(f)[0]}.m4a"])
|
||||
temp = tempfile.mkstemp(prefix=f"{os.pathsplitext(f)[0]}_")
|
||||
subprocess.run(["ffmpeg", "-i", f, "-loglevel", "panic",
|
||||
"-stats", f"{temp[1]}.wav"])
|
||||
subprocess.run(["qaac", f"{temp[1]}.wav", "-V 127",
|
||||
"--no-delay", "-o", f"{os.pathsplitext(f)[0]}.m4a"])
|
||||
|
||||
|
||||
def encode(f, wav_only: bool = False):
|
||||
print(f"\n{f}\n")
|
||||
if wav_only:
|
||||
if args.track:
|
||||
subprocess.run(["eac3to", f, "-log=NUL", f"{args.track}:", f"{os.path.splitext(f)[0]}_Track0{args.track}.wav"])
|
||||
subprocess.run(["eac3to", f, "-log=NUL", f"{args.track}:",
|
||||
f"{os.pathsplitext(f)[0]}_Track0{args.track}.wav"])
|
||||
else:
|
||||
subprocess.run(["eac3to", f, "-log=NUL", f"{os.path.splitext(f)[0]}.wav"])
|
||||
subprocess.run(["eac3to", f, "-log=NUL",
|
||||
f"{os.pathsplitext(f)[0]}.wav"])
|
||||
else:
|
||||
if not args.noflac:
|
||||
encode_flac(f)
|
||||
|
@ -69,10 +74,12 @@ if __name__ == "__main__":
|
|||
help="Encode files recursively (default: %(default)s)")
|
||||
parser.add_argument("-K", "--keep",
|
||||
action="store_true", default=False,
|
||||
help="Do not delete source file after re-encoding (default: %(default)s)")
|
||||
help="Do not delete source file"
|
||||
+ " after re-encoding (default: %(default)s)")
|
||||
parser.add_argument("-T", "--track",
|
||||
action="store", type=int, default=None,
|
||||
help="Track to encode using eac3to. If none; first audio track (default: %(default)s)")
|
||||
help="Track to encode using eac3to."
|
||||
+ " If none; first audio track (default: %(default)s)")
|
||||
parser.add_argument("--noflac",
|
||||
action="store_true", default=False,
|
||||
help="Disable FLAC encoding (default: %(default)s)")
|
||||
|
@ -81,4 +88,5 @@ if __name__ == "__main__":
|
|||
help="Disable AAC encoding (default: %(default)s)")
|
||||
parser.parse_args()
|
||||
args = parser.parse_args()
|
||||
|
||||
main()
|
||||
|
|
Loading…
Reference in a new issue