4 from .common
import InfoExtractor
10 class EightTracksIE(InfoExtractor
):
12 _VALID_URL
= r
'https?://8tracks\.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
14 'name': 'EightTracks',
15 'url': 'http://8tracks.com/ytdl/youtube-dl-test-tracks-a',
18 'display_id': 'youtube-dl-test-tracks-a',
19 'description': "test chars: \"'/\\ä↭",
20 'title': "youtube-dl test tracks \"'/\\ä↭<>",
24 'md5': '96ce57f24389fc8734ce47f4c1abcc55',
28 'title': "youtue-dl project<>\"' - youtube-dl test track 1 \"'/\\\u00e4\u21ad",
29 'uploader_id': 'ytdl',
33 'md5': '4ab26f05c1f7291ea460a3920be8021f',
37 'title': "youtube-dl project - youtube-dl test track 2 \"'/\\\u00e4\u21ad",
38 'uploader_id': 'ytdl',
42 'md5': 'd30b5b5f74217410f4689605c35d1fd7',
46 'title': "youtube-dl project as well - youtube-dl test track 3 \"'/\\\u00e4\u21ad",
47 'uploader_id': 'ytdl',
51 'md5': '4eb0a669317cd725f6bbd336a29f923a',
55 'title': "youtube-dl project as well - youtube-dl test track 4 \"'/\\\u00e4\u21ad",
56 'uploader_id': 'ytdl',
60 'md5': '1893e872e263a2705558d1d319ad19e8',
64 'title': "PH - youtube-dl test track 5 \"'/\\\u00e4\u21ad",
65 'uploader_id': 'ytdl',
69 'md5': 'b673c46f47a216ab1741ae8836af5899',
73 'title': "PH - youtube-dl test track 6 \"'/\\\u00e4\u21ad",
74 'uploader_id': 'ytdl',
78 'md5': '1d74534e95df54986da7f5abf7d842b7',
82 'title': "phihag - youtube-dl test track 7 \"'/\\\u00e4\u21ad",
83 'uploader_id': 'ytdl',
87 'md5': 'f081f47af8f6ae782ed131d38b9cd1c0',
91 'title': "phihag - youtube-dl test track 8 \"'/\\\u00e4\u21ad",
92 'uploader_id': 'ytdl',
98 def _real_extract(self
, url
):
99 playlist_id
= self
._match
_id
(url
)
101 webpage
= self
._download
_webpage
(url
, playlist_id
)
103 data
= self
._parse
_json
(
105 r
'(?s)PAGE\.mix\s*=\s*({.+?});\n', webpage
, 'trax information'),
108 session
= str(random
.randint(0, 1000000000))
110 track_count
= data
['tracks_count']
111 duration
= data
['duration']
112 avg_song_duration
= float(duration
) / track_count
113 # duration is sometimes negative, use predefined avg duration
114 if avg_song_duration
<= 0:
115 avg_song_duration
= 300
116 first_url
= f
'http://8tracks.com/sets/{session}/play?player=sm&mix_id={mix_id}&format=jsonh'
120 for i
in range(track_count
):
124 while api_json
is None:
126 api_json
= self
._download
_webpage
(
127 next_url
, playlist_id
,
128 note
='Downloading song information %d/%d' % (i
+ 1, track_count
),
129 errnote
='Failed to download song information')
130 except ExtractorError
:
131 if download_tries
> 3:
135 self
._sleep
(avg_song_duration
, playlist_id
)
137 api_data
= json
.loads(api_json
)
138 track_data
= api_data
['set']['track']
140 'id': str(track_data
['id']),
141 'url': track_data
['track_file_stream_url'],
142 'title': track_data
['performer'] + ' - ' + track_data
['name'],
143 'raw_title': track_data
['name'],
144 'uploader_id': data
['user']['login'],
149 next_url
= 'http://8tracks.com/sets/{}/next?player=sm&mix_id={}&format=jsonh&track_id={}'.format(
150 session
, mix_id
, track_data
['id'])
155 'display_id': playlist_id
,
156 'title': data
.get('name'),
157 'description': data
.get('description'),