diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2013-01-27 03:01:23 +0100 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2013-01-27 03:01:23 +0100 |
commit | ccf65f9deee0edb007222aa957f4da6516478ae3 (patch) | |
tree | 2b7a1bffb058611c0d16d02f6708907a6df3b6e1 /youtube_dl/InfoExtractors.py | |
parent | b954070d7064f37ee9f3feae8a60c90c42e30b11 (diff) |
8tracks IE (Closes #652)
Diffstat (limited to 'youtube_dl/InfoExtractors.py')
-rwxr-xr-x | youtube_dl/InfoExtractors.py | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/youtube_dl/InfoExtractors.py b/youtube_dl/InfoExtractors.py index a708cc750..50a5a5cfb 100755 --- a/youtube_dl/InfoExtractors.py +++ b/youtube_dl/InfoExtractors.py @@ -5,6 +5,7 @@ from __future__ import absolute_import import base64 import datetime +import itertools import netrc import os import re @@ -3812,8 +3813,6 @@ class PornotubeIE(InfoExtractor): return [info] - - class YouJizzIE(InfoExtractor): """Information extractor for youjizz.com.""" _VALID_URL = r'^(?:https?://)?(?:\w+\.)?youjizz\.com/videos/(?P<videoid>[^.]+).html$' @@ -3860,6 +3859,47 @@ class YouJizzIE(InfoExtractor): return [info] +class EightTracksIE(InfoExtractor): + IE_NAME = '8tracks' + _VALID_URL = r'https?://8tracks.com/(?P<user>[^/]+)/(?P<id>[^/]+)' + + def _real_extract(self, url): + mobj = re.match(self._VALID_URL, url) + if mobj is None: + raise ExtractorError(u'Invalid URL: %s' % url) + playlist_id = mobj.group('id') + + webpage = self._download_webpage(url, playlist_id) + + m = re.search(r"new TRAX.Mix\((.*?)\);\n*\s*TRAX.initSearchAutocomplete\('#search'\);", webpage, flags=re.DOTALL) + if not m: + raise ExtractorError(u'Cannot find trax information') + json_like = m.group(1) + data = json.loads(json_like) + + session = str(random.randint(0, 1000000000)) + mix_id = data['id'] + track_count = data['tracks_count'] + first_url = 'http://8tracks.com/sets/%s/play?player=sm&mix_id=%s&format=jsonh' % (session, mix_id) + next_url = first_url + res = [] + for i in itertools.count(): + api_json = self._download_webpage(next_url, playlist_id, + note=u'Downloading song information %s/%s' % (str(i+1), track_count), + errnote=u'Failed to download song information') + api_data = json.loads(api_json) + track_data = api_data[u'set']['track'] + info = { + 'id': track_data['id'], + 'url': track_data['track_file_stream_url'], + 'title': track_data['name'], + 'ext': 'm4a', + } + res.append(info) + if api_data['set']['at_last_track']: + break + next_url = 'http://8tracks.com/sets/%s/next?player=sm&mix_id=%s&format=jsonh&track_id=%s' % (session, mix_id, track_data['id']) + return res def gen_extractors(): """ Return a list of an instance of every supported extractor. @@ -3906,6 +3946,7 @@ def gen_extractors(): SteamIE(), UstreamIE(), RBMARadioIE(), + EightTracksIE(), GenericIE() ] |