add support for lyrics and release date

This commit is contained in:
boyska 2018-03-18 00:58:56 +01:00
parent c9c4ffc683
commit 8b0712d5d2
2 changed files with 19 additions and 0 deletions

View file

@ -2,6 +2,7 @@ import os
from os.path import join, exists from os.path import join, exists
import requests import requests
import mutagen.mp3 import mutagen.mp3
from mutagen.id3 import ID3, USLT, TDOR
import logging import logging
import unicodedata import unicodedata
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -45,4 +46,12 @@ def download_track(track, args):
if 'album' in track: if 'album' in track:
audio['album'] = track['album'] audio['album'] = track['album']
audio.save() audio.save()
if 'lyrics' in track:
tags = ID3(fpath)
tags['USLT'] = USLT(text=track['lyrics'])
tags.save()
if 'datePublished' in track:
tags = ID3(fpath)
tags['TDOR'] = TDOR(text=track['datePublished'])
tags.save()
log.info('track %(title)s downloaded' % track) log.info('track %(title)s downloaded' % track)

View file

@ -22,11 +22,21 @@ def visit_track(b, url):
info['lyrics'] = b.find_by_css('.lyricsText').first.value info['lyrics'] = b.find_by_css('.lyricsText').first.value
except ElementDoesNotExist: except ElementDoesNotExist:
pass pass
try:
ymd = b.find_by_xpath('//meta[@itemprop="datePublished"]').\
first['content']
if len(ymd) == 8:
info['datePublished'] = ymd[:4] + '-' + ymd[4:6] + '-' + ymd[-2:]
elif len(ymd) == 4:
info['datePublished'] = ymd
except ElementDoesNotExist:
pass
info['title'] = b.find_by_css('#name-section h2.trackTitle').first.value info['title'] = b.find_by_css('#name-section h2.trackTitle').first.value
time.sleep(0.2) # how nice! time.sleep(0.2) # how nice!
b.find_by_css('.playbutton').first.click() b.find_by_css('.playbutton').first.click()
info['url'] = b.find_by_css('audio').first['src'] info['url'] = b.find_by_css('audio').first['src']
b.visit('data:,') b.visit('data:,')
log.debug('Track info: %s' % str(info))
return info return info