]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/eighttracks.py
fb5dbbe2b0c7d9bd15b87426e446ce73f903a6eb
2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
17 class EightTracksIE(InfoExtractor
):
19 _VALID_URL
= r
'https?://8tracks\.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
21 "name": "EightTracks",
22 "url": "http://8tracks.com/ytdl/youtube-dl-test-tracks-a",
25 'display_id': 'youtube-dl-test-tracks-a',
26 "description": "test chars: \"'/\\ä↭",
27 "title": "youtube-dl test tracks \"'/\\ä↭<>",
31 "md5": "96ce57f24389fc8734ce47f4c1abcc55",
35 "title": "youtue-dl project<>\"' - youtube-dl test track 1 \"'/\\\u00e4\u21ad",
40 "md5": "4ab26f05c1f7291ea460a3920be8021f",
44 "title": "youtube-dl project - youtube-dl test track 2 \"'/\\\u00e4\u21ad",
49 "md5": "d30b5b5f74217410f4689605c35d1fd7",
53 "title": "youtube-dl project as well - youtube-dl test track 3 \"'/\\\u00e4\u21ad",
58 "md5": "4eb0a669317cd725f6bbd336a29f923a",
62 "title": "youtube-dl project as well - youtube-dl test track 4 \"'/\\\u00e4\u21ad",
67 "md5": "1893e872e263a2705558d1d319ad19e8",
71 "title": "PH - youtube-dl test track 5 \"'/\\\u00e4\u21ad",
76 "md5": "b673c46f47a216ab1741ae8836af5899",
80 "title": "PH - youtube-dl test track 6 \"'/\\\u00e4\u21ad",
85 "md5": "1d74534e95df54986da7f5abf7d842b7",
89 "title": "phihag - youtube-dl test track 7 \"'/\\\u00e4\u21ad",
94 "md5": "f081f47af8f6ae782ed131d38b9cd1c0",
98 "title": "phihag - youtube-dl test track 8 \"'/\\\u00e4\u21ad",
105 def _real_extract(self
, url
):
106 mobj
= re
.match(self
._VALID
_URL
, url
)
107 playlist_id
= mobj
.group('id')
109 webpage
= self
._download
_webpage
(url
, playlist_id
)
111 json_like
= self
._search
_regex
(
112 r
"(?s)PAGE.mix = (.*?);\n", webpage
, 'trax information')
113 data
= json
.loads(json_like
)
115 session
= str(random
.randint(0, 1000000000))
117 track_count
= data
['tracks_count']
118 duration
= data
['duration']
119 avg_song_duration
= float(duration
) / track_count
120 first_url
= 'http://8tracks.com/sets/%s/play?player=sm&mix_id=%s&format=jsonh' % (session
, mix_id
)
124 for i
in range(track_count
):
128 while api_json
is None:
130 api_json
= self
._download
_webpage
(
131 next_url
, playlist_id
,
132 note
='Downloading song information %d/%d' % (i
+ 1, track_count
),
133 errnote
='Failed to download song information')
134 except ExtractorError
:
135 if download_tries
> 3:
139 self
._sleep
(avg_song_duration
, playlist_id
)
141 api_data
= json
.loads(api_json
)
142 track_data
= api_data
['set']['track']
144 'id': compat_str(track_data
['id']),
145 'url': track_data
['track_file_stream_url'],
146 'title': track_data
['performer'] + ' - ' + track_data
['name'],
147 'raw_title': track_data
['name'],
148 'uploader_id': data
['user']['login'],
153 next_url
= 'http://8tracks.com/sets/%s/next?player=sm&mix_id=%s&format=jsonh&track_id=%s' % (
154 session
, mix_id
, track_data
['id'])
158 'id': compat_str(mix_id
),
159 'display_id': playlist_id
,
160 'title': data
.get('name'),
161 'description': data
.get('description'),