Skip to content

Instantly share code, notes, and snippets.

@larryhou
Created September 19, 2017 12:27
Show Gist options
  • Select an option

  • Save larryhou/6c551de34915e09fc1b3107e931721f4 to your computer and use it in GitHub Desktop.

Select an option

Save larryhou/6c551de34915e09fc1b3107e931721f4 to your computer and use it in GitHub Desktop.
Manipulate mp3 tags
#!/usr/bin/env python
#encoding:utf-8
from mutagen.mp3 import MP3
from mutagen.id3 import TIT2, TALB, TPE1
import os, re
def main():
import os.path as p
os.chdir(p.dirname(p.abspath(__file__)))
for file_name in os.listdir('.'):
if file_name[-3:] != 'mp3':
continue
song = MP3(file_name)
song.delete()
title = re.sub(r'\.mp3$', '', file_name.split('-')[-1]).decode('utf-8')
print title
song['TIT2'] = TIT2(encoding=3, text=title)
song['TALB'] = TALB(encoding=3, text=u'袁腾飞讲近现代史')
song['TPE1'] = TPE1(encoding=3, text=u'袁腾飞')
print song
song.save()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment