mp3tag.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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. def modified_id3(file_name, artist_name, title):
  6. id3 = ID3()
  7. id3.add(TIT2(encoding=3, text=title))
  8. id3.add(TALB(encoding=3, text=ALBUM_NAME))
  9. id3.add(TPE1(encoding=3, text=artist_name))
  10. id3.add(TDRC(encoding=3, text=str(date.today())))
  11. id3.add(TCON(encoding=3, text=GENRE))
  12. cover_path = f"img/{artist_name}.jpg"
  13. print(cover_path)
  14. if not os.path.isfile(cover_path):
  15. cover_path = "img/cover.jpg"
  16. id3.add(
  17. APIC(encoding=3,
  18. mime=u'image/jpg',
  19. type=3,
  20. desc=u'Cover',
  21. data=open(cover_path, 'rb').read()))
  22. id3.save(file_name)
  23. track_info = {
  24. 'song_name': 'mfghghfgh title',
  25. 'album_name': 'my albdfsadcxumb name',
  26. 'artist_name': 'Амала Кришна дас'
  27. }
  28. # modified_id3('file.mp3', track_info['artist_name'], track_info['song_name'])