]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/eighttracks.py
   2 from __future__ 
import unicode_literals
 
   7 from .common 
import InfoExtractor
 
  16 class EightTracksIE(InfoExtractor
): 
  18     _VALID_URL 
= r
'https?://8tracks\.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$' 
  20         'name': 'EightTracks', 
  21         'url': 'http://8tracks.com/ytdl/youtube-dl-test-tracks-a', 
  24             'display_id': 'youtube-dl-test-tracks-a', 
  25             'description': "test chars:  \"'/\\ä↭", 
  26             'title': "youtube-dl test tracks \"'/\\ä↭<>", 
  30                 'md5': '96ce57f24389fc8734ce47f4c1abcc55', 
  34                     'title': "youtue-dl project<>\"' - youtube-dl test track 1 \"'/\\\u00e4\u21ad", 
  39                 'md5': '4ab26f05c1f7291ea460a3920be8021f', 
  43                     'title': "youtube-dl project - youtube-dl test track 2 \"'/\\\u00e4\u21ad", 
  48                 'md5': 'd30b5b5f74217410f4689605c35d1fd7', 
  52                     'title': "youtube-dl project as well - youtube-dl test track 3 \"'/\\\u00e4\u21ad", 
  57                 'md5': '4eb0a669317cd725f6bbd336a29f923a', 
  61                     'title': "youtube-dl project as well - youtube-dl test track 4 \"'/\\\u00e4\u21ad", 
  66                 'md5': '1893e872e263a2705558d1d319ad19e8', 
  70                     'title': "PH - youtube-dl test track 5 \"'/\\\u00e4\u21ad", 
  75                 'md5': 'b673c46f47a216ab1741ae8836af5899', 
  79                     'title': "PH - youtube-dl test track 6 \"'/\\\u00e4\u21ad", 
  84                 'md5': '1d74534e95df54986da7f5abf7d842b7', 
  88                     'title': "phihag - youtube-dl test track 7 \"'/\\\u00e4\u21ad", 
  93                 'md5': 'f081f47af8f6ae782ed131d38b9cd1c0', 
  97                     'title': "phihag - youtube-dl test track 8 \"'/\\\u00e4\u21ad", 
 104     def _real_extract(self
, url
): 
 105         playlist_id 
= self
._match
_id
(url
) 
 107         webpage 
= self
._download
_webpage
(url
, playlist_id
) 
 109         data 
= self
._parse
_json
( 
 111                 r
"(?s)PAGE\.mix\s*=\s*({.+?});\n", webpage
, 'trax information'), 
 114         session 
= str(random
.randint(0, 1000000000)) 
 116         track_count 
= data
['tracks_count'] 
 117         duration 
= data
['duration'] 
 118         avg_song_duration 
= float(duration
) / track_count
 
 119         # duration is sometimes negative, use predefined avg duration 
 120         if avg_song_duration 
<= 0: 
 121             avg_song_duration 
= 300 
 122         first_url 
= 'http://8tracks.com/sets/%s/play?player=sm&mix_id=%s&format=jsonh' % (session
, mix_id
) 
 126         for i 
in range(track_count
): 
 130             while api_json 
is None: 
 132                     api_json 
= self
._download
_webpage
( 
 133                         next_url
, playlist_id
, 
 134                         note
='Downloading song information %d/%d' % (i 
+ 1, track_count
), 
 135                         errnote
='Failed to download song information') 
 136                 except ExtractorError
: 
 137                     if download_tries 
> 3: 
 141                         self
._sleep
(avg_song_duration
, playlist_id
) 
 143             api_data 
= json
.loads(api_json
) 
 144             track_data 
= api_data
['set']['track'] 
 146                 'id': compat_str(track_data
['id']), 
 147                 'url': track_data
['track_file_stream_url'], 
 148                 'title': track_data
['performer'] + ' - ' + track_data
['name'], 
 149                 'raw_title': track_data
['name'], 
 150                 'uploader_id': data
['user']['login'], 
 155             next_url 
= 'http://8tracks.com/sets/%s/next?player=sm&mix_id=%s&format=jsonh&track_id=%s' % ( 
 156                 session
, mix_id
, track_data
['id']) 
 160             'id': compat_str(mix_id
), 
 161             'display_id': playlist_id
, 
 162             'title': data
.get('name'), 
 163             'description': data
.get('description'),