mp3tag.py 936 B

1234567891011121314151617181920212223242526272829
  1. from datetime import date
  2. import os
  3. from mutagen.id3 import ID3, TDRC, TIT2, TALB, TPE1, TCON, APIC
  4. from config import ALBUM_NAME, GENRE
  5. if not os.path.isdir('covers'):
  6. os.mkdir('covers')
  7. def modified_id3(file_name: str, artist_name: str, title: str) -> None:
  8. id3 = ID3()
  9. id3.add(TIT2(encoding=3, text=title))
  10. id3.add(TALB(encoding=3, text=ALBUM_NAME))
  11. id3.add(TPE1(encoding=3, text=artist_name))
  12. id3.add(TDRC(encoding=3, text=str(date.today())))
  13. id3.add(TCON(encoding=3, text=GENRE))
  14. cover_path = f"{os.getcwd()}/covers/{artist_name}.jpg"
  15. if not os.path.isfile(cover_path):
  16. cover_path = f"{os.getcwd()}/covers/cover.jpg"
  17. id3.add(
  18. APIC(encoding=3,
  19. mime=u'image/jpg',
  20. type=3,
  21. desc=u'Cover',
  22. data=open(cover_path, 'rb').read()))
  23. id3.save(file_name)