Guest User

Untitled

a guest
Jun 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. from mutagen.easyid3 import EasyID3
  2. import os
  3. import re
  4.  
  5. def mp3list():
  6. for root, dirs, files in os.walk('.'):
  7. for filename in files:
  8. if os.path.splitext(filename)[1] == '.mp3':
  9. yield filename
  10.  
  11. def manual_check(filename, field):
  12. pattern = '[a-zA-Z0-9\(\)\.\s]{1,}'
  13.  
  14. if not re.match(pattern, field):
  15. print('File: {0}'.format(filename))
  16. print('[{0}]'.format(field))
  17. new = input()
  18. if new == '':
  19. return field
  20. else:
  21. return new
  22. else:
  23. return field
  24.  
  25. for mp3file in mp3list():
  26. split = mp3file.split('-')
  27. artist = split[0].strip()
  28. title = split[1].strip()
  29.  
  30. title = manual_check(mp3file, title)
  31. title = title.replace('w_', 'w/')
  32. artist = manual_check(mp3file, artist)
  33.  
  34. print('Doing', title, artist)
  35.  
  36. audio = EasyID3(mp3file)
  37. audio['title'] = title
  38. audio['artist'] = artist
  39.  
  40. audio.save()
Add Comment
Please, Sign In to add comment