Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def file_list():
payload = {}
# p = subprocess.Popen("ls", stdout=subprocess.PIPE, shell=True, cwd="static/audio")
# p.wait()
# files = p.stdout.readlines()
# files = [x.strip() for x in files]
i = 0
for r, d, f in os.walk("static/audio"):
for f2 in f:
try:
file = f2
f = TinyTag.get("static/audio/" + file, image=True)
if not f.title:
f.title = file
img_exists = os.path.isfile("static/img/" + file.split(".")[0] + ".png")
if img_exists:
img_path = file.split(".")[0] + ".png"
else:
img_path = None
payload[i] = {
"filename": file,
"name": f.title,
"length": f.duration,
"author": f.artist,
"img": img_path
}
i += 1
except:
def get_tag(self, filename):
try:
return tinytag.TinyTag.get(filename)
except tinytag.TinyTagException as x:
print("Tag error:", x)
print("Occurred when processing file: ", filename.location.encode("ascii", errors="replace"))
return tinytag.TinyTag.get(filename, duration=False)