ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/MusicUtilities/AddCoverArt.py
Revision: 752
Committed: Thu Apr 22 02:49:58 2021 UTC (4 years, 11 months ago) by nino.borges
Content type: text/x-python
File size: 2263 byte(s)
Log Message:
A simple program that will add the cover art to a folder of flac files but only ever on the thumb drive dir on the NAS. In this version I was trying to have the function call a subprocess on an entire dir, which didnt work. I'll switch to doing it file level instead.

File Contents

# User Rev Content
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()