diff options
| author | Philipp Hagemeister <phihag@phihag.de> | 2013-06-23 22:24:58 +0200 | 
|---|---|---|
| committer | Philipp Hagemeister <phihag@phihag.de> | 2013-06-23 22:24:58 +0200 | 
| commit | 45aef472817b33194a4b59f345dbaf08701f65d3 (patch) | |
| tree | 55b7bbf318b6d9088d7a7a302925411b7ad69e46 | |
| parent | ae287755b7a0c22d061cea1b04f2fb1d1cdffacb (diff) | |
[Bandcamp] move into own file
| -rwxr-xr-x | youtube_dl/InfoExtractors.py | 46 | ||||
| -rw-r--r-- | youtube_dl/extractor/bandcamp.py | 54 | 
2 files changed, 55 insertions, 45 deletions
| diff --git a/youtube_dl/InfoExtractors.py b/youtube_dl/InfoExtractors.py index 2b8e6e6c6..801fbff5e 100755 --- a/youtube_dl/InfoExtractors.py +++ b/youtube_dl/InfoExtractors.py @@ -20,6 +20,7 @@ from .extractor.common import InfoExtractor, SearchInfoExtractor  from .extractor.ard import ARDIE  from .extractor.arte import ArteTvIE +from .extractor.bandcamp import BandcampIE  from .extractor.bliptv import BlipTVIE, BlipTVUserIE  from .extractor.comedycentral import ComedyCentralIE  from .extractor.collegehumor import CollegeHumorIE @@ -98,51 +99,6 @@ from .extractor.zdf import ZDFIE -class BandcampIE(InfoExtractor): -    _VALID_URL = r'http://.*?\.bandcamp\.com/track/(?P<title>.*)' - -    def _real_extract(self, url): -        mobj = re.match(self._VALID_URL, url) -        title = mobj.group('title') -        webpage = self._download_webpage(url, title) -        # We get the link to the free download page -        m_download = re.search(r'freeDownloadPage: "(.*?)"', webpage) -        if m_download is None: -            raise ExtractorError(u'No free songs found') - -        download_link = m_download.group(1) -        id = re.search(r'var TralbumData = {(.*?)id: (?P<id>\d*?)$',  -                       webpage, re.MULTILINE|re.DOTALL).group('id') - -        download_webpage = self._download_webpage(download_link, id, -                                                  'Downloading free downloads page') -        # We get the dictionary of the track from some javascrip code -        info = re.search(r'items: (.*?),$', -                         download_webpage, re.MULTILINE).group(1) -        info = json.loads(info)[0] -        # We pick mp3-320 for now, until format selection can be easily implemented. -        mp3_info = info[u'downloads'][u'mp3-320'] -        # If we try to use this url it says the link has expired -        initial_url = mp3_info[u'url'] -        re_url = r'(?P<server>http://(.*?)\.bandcamp\.com)/download/track\?enc=mp3-320&fsig=(?P<fsig>.*?)&id=(?P<id>.*?)&ts=(?P<ts>.*)$' -        m_url = re.match(re_url, initial_url) -        #We build the url we will use to get the final track url -        # This url is build in Bandcamp in the script download_bunde_*.js -        request_url = '%s/statdownload/track?enc=mp3-320&fsig=%s&id=%s&ts=%s&.rand=665028774616&.vrs=1' % (m_url.group('server'), m_url.group('fsig'), id, m_url.group('ts')) -        final_url_webpage = self._download_webpage(request_url, id, 'Requesting download url') -        # If we could correctly generate the .rand field the url would be -        #in the "download_url" key -        final_url = re.search(r'"retry_url":"(.*?)"', final_url_webpage).group(1) - -        track_info = {'id':id, -                      'title' : info[u'title'], -                      'ext' :   'mp3', -                      'url' :   final_url, -                      'thumbnail' : info[u'thumb_url'], -                      'uploader' :  info[u'artist'] -                      } - -        return [track_info]  class RedTubeIE(InfoExtractor):      """Information Extractor for redtube""" diff --git a/youtube_dl/extractor/bandcamp.py b/youtube_dl/extractor/bandcamp.py new file mode 100644 index 000000000..dcf6721ee --- /dev/null +++ b/youtube_dl/extractor/bandcamp.py @@ -0,0 +1,54 @@ +import json +import re + +from .common import InfoExtractor +from ..utils import ( +    ExtractorError, +) + + +class BandcampIE(InfoExtractor): +    _VALID_URL = r'http://.*?\.bandcamp\.com/track/(?P<title>.*)' + +    def _real_extract(self, url): +        mobj = re.match(self._VALID_URL, url) +        title = mobj.group('title') +        webpage = self._download_webpage(url, title) +        # We get the link to the free download page +        m_download = re.search(r'freeDownloadPage: "(.*?)"', webpage) +        if m_download is None: +            raise ExtractorError(u'No free songs found') + +        download_link = m_download.group(1) +        id = re.search(r'var TralbumData = {(.*?)id: (?P<id>\d*?)$',  +                       webpage, re.MULTILINE|re.DOTALL).group('id') + +        download_webpage = self._download_webpage(download_link, id, +                                                  'Downloading free downloads page') +        # We get the dictionary of the track from some javascrip code +        info = re.search(r'items: (.*?),$', +                         download_webpage, re.MULTILINE).group(1) +        info = json.loads(info)[0] +        # We pick mp3-320 for now, until format selection can be easily implemented. +        mp3_info = info[u'downloads'][u'mp3-320'] +        # If we try to use this url it says the link has expired +        initial_url = mp3_info[u'url'] +        re_url = r'(?P<server>http://(.*?)\.bandcamp\.com)/download/track\?enc=mp3-320&fsig=(?P<fsig>.*?)&id=(?P<id>.*?)&ts=(?P<ts>.*)$' +        m_url = re.match(re_url, initial_url) +        #We build the url we will use to get the final track url +        # This url is build in Bandcamp in the script download_bunde_*.js +        request_url = '%s/statdownload/track?enc=mp3-320&fsig=%s&id=%s&ts=%s&.rand=665028774616&.vrs=1' % (m_url.group('server'), m_url.group('fsig'), id, m_url.group('ts')) +        final_url_webpage = self._download_webpage(request_url, id, 'Requesting download url') +        # If we could correctly generate the .rand field the url would be +        #in the "download_url" key +        final_url = re.search(r'"retry_url":"(.*?)"', final_url_webpage).group(1) + +        track_info = {'id':id, +                      'title' : info[u'title'], +                      'ext' :   'mp3', +                      'url' :   final_url, +                      'thumbnail' : info[u'thumb_url'], +                      'uploader' :  info[u'artist'] +                      } + +        return [track_info] | 
