]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/eighttracks.py
4 from .common
import InfoExtractor
13 class EightTracksIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://8tracks\.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
17 'name': 'EightTracks',
18 'url': 'http://8tracks.com/ytdl/youtube-dl-test-tracks-a',
21 'display_id': 'youtube-dl-test-tracks-a',
22 'description': "test chars: \"'/\\ä↭",
23 'title': "youtube-dl test tracks \"'/\\ä↭<>",
27 'md5': '96ce57f24389fc8734ce47f4c1abcc55',
31 'title': "youtue-dl project<>\"' - youtube-dl test track 1 \"'/\\\u00e4\u21ad",
36 'md5': '4ab26f05c1f7291ea460a3920be8021f',
40 'title': "youtube-dl project - youtube-dl test track 2 \"'/\\\u00e4\u21ad",
45 'md5': 'd30b5b5f74217410f4689605c35d1fd7',
49 'title': "youtube-dl project as well - youtube-dl test track 3 \"'/\\\u00e4\u21ad",
54 'md5': '4eb0a669317cd725f6bbd336a29f923a',
58 'title': "youtube-dl project as well - youtube-dl test track 4 \"'/\\\u00e4\u21ad",
63 'md5': '1893e872e263a2705558d1d319ad19e8',
67 'title': "PH - youtube-dl test track 5 \"'/\\\u00e4\u21ad",
72 'md5': 'b673c46f47a216ab1741ae8836af5899',
76 'title': "PH - youtube-dl test track 6 \"'/\\\u00e4\u21ad",
81 'md5': '1d74534e95df54986da7f5abf7d842b7',
85 'title': "phihag - youtube-dl test track 7 \"'/\\\u00e4\u21ad",
90 'md5': 'f081f47af8f6ae782ed131d38b9cd1c0',
94 'title': "phihag - youtube-dl test track 8 \"'/\\\u00e4\u21ad",
101 def _real_extract(self
, url
):
102 playlist_id
= self
._match
_id
(url
)
104 webpage
= self
._download
_webpage
(url
, playlist_id
)
106 data
= self
._parse
_json
(
108 r
"(?s)PAGE\.mix\s*=\s*({.+?});\n", webpage
, 'trax information'),
111 session
= str(random
.randint(0, 1000000000))
113 track_count
= data
['tracks_count']
114 duration
= data
['duration']
115 avg_song_duration
= float(duration
) / track_count
116 # duration is sometimes negative, use predefined avg duration
117 if avg_song_duration
<= 0:
118 avg_song_duration
= 300
119 first_url
= 'http://8tracks.com/sets/%s/play?player=sm&mix_id=%s&format=jsonh' % (session
, mix_id
)
123 for i
in range(track_count
):
127 while api_json
is None:
129 api_json
= self
._download
_webpage
(
130 next_url
, playlist_id
,
131 note
='Downloading song information %d/%d' % (i
+ 1, track_count
),
132 errnote
='Failed to download song information')
133 except ExtractorError
:
134 if download_tries
> 3:
138 self
._sleep
(avg_song_duration
, playlist_id
)
140 api_data
= json
.loads(api_json
)
141 track_data
= api_data
['set']['track']
143 'id': compat_str(track_data
['id']),
144 'url': track_data
['track_file_stream_url'],
145 'title': track_data
['performer'] + ' - ' + track_data
['name'],
146 'raw_title': track_data
['name'],
147 'uploader_id': data
['user']['login'],
152 next_url
= 'http://8tracks.com/sets/%s/next?player=sm&mix_id=%s&format=jsonh&track_id=%s' % (
153 session
, mix_id
, track_data
['id'])
157 'id': compat_str(mix_id
),
158 'display_id': playlist_id
,
159 'title': data
.get('name'),
160 'description': data
.get('description'),