| 1 |
nino.borges |
752 |
"""
|
| 2 |
|
|
|
| 3 |
|
|
AddCoverArt
|
| 4 |
|
|
|
| 5 |
|
|
Created by
|
| 6 |
|
|
Emanuel Borges
|
| 7 |
|
|
04.20.2021
|
| 8 |
|
|
|
| 9 |
|
|
A simple program that will add cover art (either cover.jpg/png or folder.jpg/Copying
|
| 10 |
|
|
to any flac file it finds. Will run over all dirs, only allowing the thumb dir,
|
| 11 |
|
|
or a single dir, also only allowing the thumb dir. I dont want this to run anywhere else.
|
| 12 |
|
|
|
| 13 |
|
|
It will also log any changes to a text file at the root.
|
| 14 |
|
|
|
| 15 |
|
|
"""
|
| 16 |
|
|
|
| 17 |
|
|
import os, subprocess
|
| 18 |
|
|
from datetime import datetime
|
| 19 |
|
|
|
| 20 |
|
|
def AddArtToSingleDirOfFiles (dirOfFlacs, coverArtFileName, logFile):
|
| 21 |
|
|
"""This function adds the cover art to a single dir of flac files, updating the log."""
|
| 22 |
|
|
now = datetime.now()
|
| 23 |
|
|
print ("Adding coverart to all flac files in this dir...")
|
| 24 |
|
|
#subprocess.call(["metaflac", "--import-picture-from=%s"%coverArtFileName, "*.flac"])
|
| 25 |
|
|
subprocess.run('metaflac --import-picture-from="%s" "%s/*.flac"'%(os.path.join(dirOfFlacs,coverArtFileName),dirOfFlacs),shell=True)
|
| 26 |
|
|
logFile.write("Flac files in dir %s ammended with art file %s. %s\n"%(dirOfFlacs, coverArtFileName, now.strftime("%Y.%m.%d %H:%M:%S")
|
| 27 |
|
|
))
|
| 28 |
|
|
print("All flac files ammended.")
|
| 29 |
|
|
|
| 30 |
|
|
if __name__ == '__main__':
|
| 31 |
|
|
rootTextFilePath = r"/home/nino/Documents/CoverArtLogFile.txt"
|
| 32 |
|
|
logOutPutFile = open(rootTextFilePath,'a')
|
| 33 |
|
|
## Never do this on anyhing but the thumbdir on your share.
|
| 34 |
|
|
startingDir = r"/home/nino/Documents"
|
| 35 |
|
|
|
| 36 |
|
|
for root, dirs, files in os.walk(startingDir):
|
| 37 |
|
|
print ("Now inspecting %s" %root)
|
| 38 |
|
|
if "cover.jpg" in files:
|
| 39 |
|
|
print("Cover Art found in this dir as cover.jpg. Adding...")
|
| 40 |
|
|
AddArtToSingleDirOfFiles (root, "cover.jpg", logOutPutFile)
|
| 41 |
|
|
elif "folder.jpg" in files:
|
| 42 |
|
|
print("Cover Art found in this dir as folder.jpg. Adding...")
|
| 43 |
|
|
AddArtToSingleDirOfFiles (root, "folder.jpg", logOutPutFile)
|
| 44 |
|
|
elif "cover.png" in files:
|
| 45 |
|
|
print("Cover Art found in this dir as cover.png. Adding...")
|
| 46 |
|
|
AddArtToSingleDirOfFiles (root, "cover.png", logOutPutFile)
|
| 47 |
|
|
elif "folder.png" in files:
|
| 48 |
|
|
print("Cover Art found in this dir as folder.png. Adding...")
|
| 49 |
|
|
AddArtToSingleDirOfFiles (root, "folder.png", logOutPutFile)
|
| 50 |
|
|
else:
|
| 51 |
|
|
print("There is no cover art in this dir. skipping.")
|
| 52 |
|
|
|
| 53 |
|
|
logOutPutFile.close()
|