From 8b0712d5d2512fa9efd8ed14caa105324470e667 Mon Sep 17 00:00:00 2001 From: boyska Date: Sun, 18 Mar 2018 00:58:56 +0100 Subject: [PATCH] add support for lyrics and release date --- bandcavall/download.py | 9 +++++++++ bandcavall/visit.py | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/bandcavall/download.py b/bandcavall/download.py index 1fff75c..467a302 100644 --- a/bandcavall/download.py +++ b/bandcavall/download.py @@ -2,6 +2,7 @@ import os from os.path import join, exists import requests import mutagen.mp3 +from mutagen.id3 import ID3, USLT, TDOR import logging import unicodedata log = logging.getLogger(__name__) @@ -45,4 +46,12 @@ def download_track(track, args): if 'album' in track: audio['album'] = track['album'] 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) diff --git a/bandcavall/visit.py b/bandcavall/visit.py index 62aa69b..e0582ff 100644 --- a/bandcavall/visit.py +++ b/bandcavall/visit.py @@ -22,11 +22,21 @@ def visit_track(b, url): info['lyrics'] = b.find_by_css('.lyricsText').first.value except ElementDoesNotExist: 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 time.sleep(0.2) # how nice! b.find_by_css('.playbutton').first.click() info['url'] = b.find_by_css('audio').first['src'] b.visit('data:,') + log.debug('Track info: %s' % str(info)) return info