]> git.bitcoin.ninja Git - youtube-dl/commitdiff
Add BandcampIE (closes #568)
authorJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Wed, 1 May 2013 13:55:46 +0000 (15:55 +0200)
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Wed, 1 May 2013 13:55:46 +0000 (15:55 +0200)
test/tests.json
youtube_dl/InfoExtractors.py

index 4735373a83078b900434fe3835eaea60ddf9fdd0..4eba27846c9a7085406ab884c8494aab863b228f 100644 (file)
         }
       }
     ]
+  },
+  {
+    "name":"Bandcamp",
+    "url":"http://youtube-dl.bandcamp.com/track/youtube-dl-test-song",
+    "file":"1812978515.mp3",
+    "md5":"cdeb30cdae1921719a3cbcab696ef53c",
+    "info_dict": {
+      "title":"youtube-dl test song \"'/\\ä↭"
+    }
   }
 
 ]
index e430069d5b7915cf31ae8c427d2222042729395c..110ec834cfe34c060ab7a6163fc3108862070172 100755 (executable)
@@ -4277,6 +4277,52 @@ class TumblrIE(InfoExtractor):
                  'ext': ext
                  }]
 
+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:
+            self._downloader.report_error('No free songs founded')
+            return
+        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]
+
 
 def gen_extractors():
     """ Return a list of an instance of every supported extractor.
@@ -4332,6 +4378,7 @@ def gen_extractors():
         LiveLeakIE(),
         ARDIE(),
         TumblrIE(),
+        BandcampIE(),
         GenericIE()
     ]