__init__.py 672 B

123456789101112131415161718192021222324
  1. from eyed3 import load
  2. import os
  3. import re
  4. def no_translate(s):
  5. return re.sub(r" ?\(.+\)", "", s)
  6. def set_meta(filename, song, album):
  7. audiofile = load(filename)
  8. audiofile.tag.artist = no_translate(song["artist"])
  9. audiofile.tag.album = no_translate(album["title"])
  10. audiofile.tag.album_artist = no_translate(album["artist"])
  11. audiofile.tag.title = no_translate(song["title"])
  12. audiofile.tag.track_num = song["number"]
  13. audiofile.tag.lyrics.set(song["lyrics"])
  14. cover = "\\".join(filename.split("\\")[:-1]) + "\\cover.jpg"
  15. if os.path.exists(cover):
  16. with open(cover, "rb") as f:
  17. audiofile.tag.images.set(3, f.read() , "image/jpeg", u"")
  18. audiofile.tag.save()