improve id3 tagging
This commit is contained in:
parent
93df4ebd44
commit
d4d7d98764
1 changed files with 20 additions and 7 deletions
27
delojza.py
27
delojza.py
|
@ -79,6 +79,24 @@ class DelojzaBot:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def extract_tags(info):
|
||||||
|
title = None
|
||||||
|
artist = None
|
||||||
|
if 'track' in info:
|
||||||
|
title = info['track']
|
||||||
|
if 'artist' in info:
|
||||||
|
artist = info['artist']
|
||||||
|
if title is None and artist is None and '-' in info['title']:
|
||||||
|
split = info['title'].split("-")
|
||||||
|
artist = split[0]
|
||||||
|
title = split[1]
|
||||||
|
if title is None:
|
||||||
|
title = info['title']
|
||||||
|
if 'soundcloud' in info['extractor']:
|
||||||
|
artist = info['uploader']
|
||||||
|
return artist.strip() if artist is not None else None, title.strip() if title is not None else None
|
||||||
|
|
||||||
def download_ytdl(self, urls, subdir, date, message, extract=False, filename=None):
|
def download_ytdl(self, urls, subdir, date, message, extract=False, filename=None):
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'noplaylist': True,
|
'noplaylist': True,
|
||||||
|
@ -100,17 +118,12 @@ class DelojzaBot:
|
||||||
globbeds = glob(os.path.splitext(filename)[0] + '.*')
|
globbeds = glob(os.path.splitext(filename)[0] + '.*')
|
||||||
for globbed in globbeds:
|
for globbed in globbeds:
|
||||||
if globbed.endswith("mp3"):
|
if globbed.endswith("mp3"):
|
||||||
title = info['track'] or (info['title'].split("-")[1]
|
artist, title = self.extract_tags(info)
|
||||||
if "-" in info['title'] else info['title'])
|
|
||||||
title = title.strip()
|
|
||||||
artist = info['artist'] or (info['title'].split("-")[0]
|
|
||||||
if "-" in info['title'] else info['title'])
|
|
||||||
artist = artist.strip()
|
|
||||||
message.reply_text("Tagging as \"{}\" by \"{}\"".format(title, artist))
|
message.reply_text("Tagging as \"{}\" by \"{}\"".format(title, artist))
|
||||||
self.logger.info("Tagging %s w/ $s - $s...".format(globbed, title, artist))
|
self.logger.info("Tagging %s w/ $s - $s...".format(globbed, title, artist))
|
||||||
id3 = mutagen.id3.ID3(globbed)
|
id3 = mutagen.id3.ID3(globbed)
|
||||||
id3.add(mutagen.id3.TIT2(encoding=3, text=title))
|
id3.add(mutagen.id3.TIT2(encoding=3, text=title))
|
||||||
if artist and (not info['artist'] and artist != title):
|
if artist:
|
||||||
id3.add(mutagen.id3.TOPE(encoding=3, text=artist))
|
id3.add(mutagen.id3.TOPE(encoding=3, text=artist))
|
||||||
id3.add(mutagen.id3.TPE1(encoding=3, text=artist))
|
id3.add(mutagen.id3.TPE1(encoding=3, text=artist))
|
||||||
id3.save()
|
id3.save()
|
||||||
|
|
Loading…
Reference in a new issue