1234567891011121314151617181920212223242526272829 |
- from datetime import date
- import os
- from mutagen.id3 import ID3, TDRC, TIT2, TALB, TPE1, TCON, APIC
- from config import ALBUM_NAME, GENRE
- if not os.path.isdir('covers'):
- os.mkdir('covers')
- def modified_id3(file_name: str, artist_name: str, title: str) -> None:
- id3 = ID3()
- id3.add(TIT2(encoding=3, text=title))
- id3.add(TALB(encoding=3, text=ALBUM_NAME))
- id3.add(TPE1(encoding=3, text=artist_name))
- id3.add(TDRC(encoding=3, text=str(date.today())))
- id3.add(TCON(encoding=3, text=GENRE))
- cover_path = f"{os.getcwd()}/covers/{artist_name}.jpg"
- if not os.path.isfile(cover_path):
- cover_path = f"{os.getcwd()}/covers/cover.jpg"
- id3.add(
- APIC(encoding=3,
- mime=u'image/jpg',
- type=3,
- desc=u'Cover',
- data=open(cover_path, 'rb').read()))
-
- id3.save(file_name)
|