Wie verhindern Sie [Winerror 3] mit Shutil.move auf .mp3 -Dateien, deren Künstler -Tags '&' oder '(' enthalten?Python

Python-Programme
Anonymous
 Wie verhindern Sie [Winerror 3] mit Shutil.move auf .mp3 -Dateien, deren Künstler -Tags '&' oder '(' enthalten?

Post by Anonymous »

Ich schreibe ein Python-Skript, dass: < /p>

Alle Dateien im Arbeitsverzeichnis < /li>
liest das Künstler-Tag mit der Mutagen-Bibliothek < /li> < /> , um Regex zu erfassen, um den ersten Direktorium zu erstellen. /> verwendet Shutil, um das .mp3 in dieses Verzeichnis zu verschieben. Ich habe dies bestätigt, indem das Tag geändert wird und es ohne Fehler bewegt wird. Es wird abgeholt und durch einen Regex ausgeführt, um sicherzustellen

Code: Select all

import mutagen
import os
import re
import shutil

current_dir = os.getcwd()
files = [f for f in os.listdir('.') if os.path.isfile(f)]

# for each file in the dir
for f in files:
#grab the artist (use first listed artist in the case of colabs) as a new directory name or UKNOWN if not listed
try:
audio = mutagen.File(f, easy=True)
if audio is not None and "artist" in audio:
artist = re.split(r";|,|&|\(|\/|\sfeat\.|\sFeat\.|\sft|\sFt|\sx\s",audio['artist'][0])[0].upper()
else:
artist = "UNKNOWN"
except Exception as e:
artist = "UNKNOWN"

artist_path = os.path.join(current_dir,artist)
item_path = os.path.join(current_dir,f)

#make sure all the artist paths are unique
os.makedirs(artist,exist_ok=True)

#don't move the actual python script...
if item_path[-2:] != 'py':
try:
shutil.move(item_path, artist_path)
print("moved ",item_path," to ",artist_path)
except Exception as e:
print("Error on: ",f," -> ",e)
print(item_path, os.path.exists(item_path))
print(artist_path, os.path.exists(artist_path))
Warum sollte die Metadaten -Tag in diesem Fall eine Rolle spielen?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post