Created
May 23, 2021 12:41
-
-
Save bennyyip/de51ee5365a82f20b81b31612a64db69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from os.path import getsize, join | |
from pathlib import Path | |
from subprocess import DEVNULL, PIPE, Popen | |
rootpath = sys.argv[1] | |
audio_suffices = [".mp3", ".flac", ".m4a", ".aac"] | |
for root, dirs, files in os.walk(rootpath): | |
if len(files) == 0: | |
continue | |
if "cover.jpg" in files: | |
continue | |
thefile = None | |
for x in files: | |
if Path(x).suffix in audio_suffices: | |
thefile = x | |
break | |
if thefile is None: | |
continue | |
ffmpeg_args = [ | |
"ffmpeg", | |
"-i", | |
os.path.join(root, thefile), | |
"-an", | |
"-vcodec", | |
"copy", | |
os.path.join(root, "cover.jpg"), | |
] | |
process = Popen(ffmpeg_args, stdout=DEVNULL, stderr=DEVNULL) | |
(output, err) = process.communicate() | |
exit_code = process.wait() | |
if exit_code != 0: | |
print(f"{root} extract album art failed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment