12345678910111213141516171819202122232425262728293031323334353637 |
- 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"covers/{artist_name}.jpg"
- if not os.path.isfile(cover_path):
- cover_path = "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)
- if __name__ == '__main__':
- track_info = {
- 'song_name': 'mfghghfgh title',
- 'album_name': 'my albdfsadcxumb name',
- 'artist_name': 'Юга Аватара дас'
- }
- modified_id3('Брахмотсава. Юга Аватар дас. 27.05.22 [bpZDLB1dVB8].mp3', track_info['artist_name'], track_info['song_name'])
|