]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/eighttracks.py
6 from .common
import InfoExtractor
12 class EightTracksIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://8tracks.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
16 def _real_extract(self
, url
):
17 mobj
= re
.match(self
._VALID
_URL
, url
)
19 raise ExtractorError(u
'Invalid URL: %s' % url
)
20 playlist_id
= mobj
.group('id')
22 webpage
= self
._download
_webpage
(url
, playlist_id
)
24 json_like
= self
._search
_regex
(r
"PAGE.mix = (.*?);\n", webpage
, u
'trax information', flags
=re
.DOTALL
)
25 data
= json
.loads(json_like
)
27 session
= str(random
.randint(0, 1000000000))
29 track_count
= data
['tracks_count']
30 first_url
= 'http://8tracks.com/sets/%s/play?player=sm&mix_id=%s&format=jsonh' % (session
, mix_id
)
33 for i
in itertools
.count():
34 api_json
= self
._download
_webpage
(next_url
, playlist_id
,
35 note
=u
'Downloading song information %s/%s' % (str(i
+1), track_count
),
36 errnote
=u
'Failed to download song information')
37 api_data
= json
.loads(api_json
)
38 track_data
= api_data
[u
'set']['track']
40 'id': track_data
['id'],
41 'url': track_data
['track_file_stream_url'],
42 'title': track_data
['performer'] + u
' - ' + track_data
['name'],
43 'raw_title': track_data
['name'],
44 'uploader_id': data
['user']['login'],
48 if api_data
['set']['at_last_track']:
50 next_url
= 'http://8tracks.com/sets/%s/next?player=sm&mix_id=%s&format=jsonh&track_id=%s' % (session
, mix_id
, track_data
['id'])