def id3(audio, episode, title, image): """ Update ID3 tags with episode info. """ if not episode: # Try to detect episode from audio filename match = re.search(r'e(\d{2,})', audio) if not match: raise click.UsageError('Could not be detected episode. Use --episode option.') episode = int(match.group(1)) id3 = eyed3.load(audio) id3.initTag(version=ID3_V2_3) id3.tag.title = title id3.tag.artist = 'Henrique Bastos' id3.tag.album = 'Curto Circuito Podcast' id3.tag.track_num = episode id3.tag.genre = 'Podcast' if image: image = Path(image) data = image.read_file('rb') mime = 'image/' + image.ext[1:] # HACK to make APIC header readable on iTunes # EYED3 sets v2.3 encoding to UTF-16, but iTunes only reads LATIN-1 from eyed3.id3 import frames def force_latin1(self): self.encoding = eyed3.id3.LATIN1_ENCODING setattr(frames.ImageFrame, '_initEncoding', force_latin1) # force mime as str because eyeD3 uses it to compose the binary header # PUBLISHER_LOGO == 0x14 id3.tag.images.set(0x14, data, str(mime)) id3.tag.save(version=ID3_V2_3) # Print id3 shell(['eyeD3', audio])