Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # Removes unwanted tags from mp3s
- import mutagen, os, re, sys
- from mutagen.easyid3 import EasyID3
- # Path to recursively walk
- inputPath = "/media/Brick/Music/Pub/"
- # List to be populated by dirWalk function
- fileList = []
- # File type
- fileType = '.mp3'
- # Tags to save
- validKeys = ['artist', 'album', 'title', 'genre', 'organization', 'date', 'tracknumber']
- # Looks for a certain type of file and adds the dir/filename to fileList
- def dirWalk(inputPath):
- # Make sure path is a directory . . .
- if os.path.isdir(inputPath) == 0:
- print "%s is not a directory" % inputPath
- # . . . if so, continue!
- else:
- walkList = os.listdir(inputPath)
- for item in walkList:
- # if the item is a directory send it to dirWalk function to walk . . .
- if os.path.isdir(os.path.join(inputPath, item)) == 1:
- #print "%s is a directory..." % item
- dirWalk(os.path.join(inputPath, item))
- # if the item is a file, check to make sure it is an mp3
- elif item.endswith(fileType):
- fileList.append([inputPath, item])
- def updateTag(pathName, fileName):
- pathName = pathName.decode('utf8')
- fileName = fileName.decode('utf8')
- trackTags = dict()
- # open file with EasyID3
- track = EasyID3(os.path.join(pathName, fileName))
- # Copy tags we want to keep to trackTags dict
- for key, value in track.iteritems():
- if key in validKeys:
- trackTags[key] = value
- # Delete all tags
- track.delete()
- print track
- # Copy saved tags from trackTags dict back to file
- track.update(trackTags)
- track.save()
- dirWalk(inputPath)
- print fileList
- for item in fileList:
- updateTag(item[0], item[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement