mp3.py 754 B

123456789101112131415161718192021222324252627282930
  1. from pathlib import Path
  2. import aiofiles
  3. from genius.type import Track
  4. import eyed3
  5. from utils import download_image
  6. async def set_track(path: Path, track: Track):
  7. audiofile = eyed3.load(path)
  8. if track.album is not None:
  9. audiofile.tag.album = track.album.title
  10. audiofile.tag.album_artist = track.album.artist
  11. audiofile.tag.artist = track.artist
  12. audiofile.tag.title = track.title
  13. audiofile.tag.track_num = track.number
  14. audiofile.tag.lyrics.set(track.lyrics)
  15. if track.cover:
  16. cover = await download_image(track.cover)
  17. async with aiofiles.open(cover, "rb") as f:
  18. content = await f.read()
  19. audiofile.tag.images.set(3, content, "image/jpeg", u"")
  20. audiofile.tag.save()