Hello
my code works most of the time, but the other time I get this:
Traceback (most recent call last): File "getMetadata.py", line 72, in <module> flac.append(pyflacmeta.FLAC(file)) File "/usr/lib/python3.7/site-packages/pyflacmeta/pyflacmeta.py", line 79, in __init__ self.read(fp) File "/usr/lib/python3.7/site-packages/pyflacmeta/pyflacmeta.py", line 84, in read raise InvalidFLACError pyflacmeta.pyflacmeta.InvalidFLACError
import pyflacmeta
import glob
import random
import os
import os.path
import shutil
import json
import codecs
from os import listdir
from os.path import isfile, join
from shutil import copyfile
relativePath = '../../../../home/user/Music/'
albumList = os.listdir(relativePath)
albumName = random.sample(albumList,1)
albumPath = relativePath+albumName[0]
files = [f for f in listdir(albumPath) if isfile(join(albumPath, f))]
websitePath = '/srv/http/OneAlbumAWeek/album/'
if os.path.exists(websitePath):
shutil.rmtree(websitePath, ignore_errors=True)
if not os.path.exists(websitePath):
os.makedirs(websitePath)
for dirpath, dirnames, filenames in os.walk(albumPath):
for filename in [f for f in filenames]:
shutil.copy2(os.path.join(dirpath, filename),websitePath)
print(filename,"copied to",websitePath)
jsonPath = '/srv/http/OneAlbumAWeek/json'
if os.path.exists(jsonPath):
shutil.rmtree(jsonPath, ignore_errors=True)
if not os.path.exists(jsonPath):
os.makedirs(jsonPath)
jsonfile = open(jsonPath+'/album.json', 'w').close()
albumMusic = []
albumImage = []
for path in glob.glob("../album/*.flac"):
albumMusic.append(path)
for path in glob.glob("../album/*.jpg"):
albumImage.append(path)
for path in glob.glob("../album/*.png"):
albumImage.append(path)
for path in glob.glob("../album/*.jpeg"):
albumImage.append(path)
for path in glob.glob("../album/*.gif"):
albumImage.append(path)
albumMusic.sort()
flac = []
for file in albumMusic:
flac.append(pyflacmeta.FLAC(file))
albumMetadata = []
i = 0
for fix in flac:
metadata = dict(flac[i])
track = {}
for data in metadata.keys():
track[data.upper()] = metadata[data]
if metadata[data] == "":
track.pop(data)
track.setdefault('ARTIST',"Unknown artist")
track.setdefault('ALBUM',"Unknown album")
track.setdefault('GENRE',"Unknown genre")
track.setdefault('DATE',"Unknown year")
albumMetadata.append(track)
i+=1
with codecs.open('../json/album.json', 'w+', encoding='utf-8') as album:
json.dump(albumMetadata,album,indent=4)
print("json created")
imgPath = "/srv/http/OneAlbumAWeek/img/"
if os.path.exists(imgPath):
shutil.rmtree(websitePath, ignore_errors=True)
if not os.path.exists(imgPath):
os.makedirs(imgPath)
for image in albumImage:
shutil.copy2(image, "imgPath")
print(image,"copied to ",imgPath)
Thanks a lot
Hello
my code works most of the time, but the other time I get this:
Traceback (most recent call last): File "getMetadata.py", line 72, in <module> flac.append(pyflacmeta.FLAC(file)) File "/usr/lib/python3.7/site-packages/pyflacmeta/pyflacmeta.py", line 79, in __init__ self.read(fp) File "/usr/lib/python3.7/site-packages/pyflacmeta/pyflacmeta.py", line 84, in read raise InvalidFLACError pyflacmeta.pyflacmeta.InvalidFLACErrorThanks a lot