X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Fextractor%2Feighttracks.py;h=fb5dbbe2b0c7d9bd15b87426e446ce73f903a6eb;hb=9d22a7dfb07ad6ff23680e11238744b2bb1735aa;hp=c1b4c729ef5888da0bdcebf692cbddad30dee4df;hpb=0963f92f23552800b5897d9f5f43ba3670679bbf;p=youtube-dl diff --git a/youtube_dl/extractor/eighttracks.py b/youtube_dl/extractor/eighttracks.py index c1b4c729e..fb5dbbe2b 100644 --- a/youtube_dl/extractor/eighttracks.py +++ b/youtube_dl/extractor/eighttracks.py @@ -6,9 +6,12 @@ import random import re from .common import InfoExtractor -from ..utils import ( +from ..compat import ( compat_str, ) +from ..utils import ( + ExtractorError, +) class EightTracksIE(InfoExtractor): @@ -112,25 +115,41 @@ class EightTracksIE(InfoExtractor): session = str(random.randint(0, 1000000000)) mix_id = data['id'] track_count = data['tracks_count'] + duration = data['duration'] + avg_song_duration = float(duration) / track_count first_url = 'http://8tracks.com/sets/%s/play?player=sm&mix_id=%s&format=jsonh' % (session, mix_id) next_url = first_url entries = [] + for i in range(track_count): - api_json = self._download_webpage( - next_url, playlist_id, - note='Downloading song information %d/%d' % (i + 1, track_count), - errnote='Failed to download song information') + api_json = None + download_tries = 0 + + while api_json is None: + try: + api_json = self._download_webpage( + next_url, playlist_id, + note='Downloading song information %d/%d' % (i + 1, track_count), + errnote='Failed to download song information') + except ExtractorError: + if download_tries > 3: + raise + else: + download_tries += 1 + self._sleep(avg_song_duration, playlist_id) + api_data = json.loads(api_json) track_data = api_data['set']['track'] info = { 'id': compat_str(track_data['id']), 'url': track_data['track_file_stream_url'], - 'title': track_data['performer'] + u' - ' + track_data['name'], + 'title': track_data['performer'] + ' - ' + track_data['name'], 'raw_title': track_data['name'], 'uploader_id': data['user']['login'], 'ext': 'm4a', } entries.append(info) + next_url = 'http://8tracks.com/sets/%s/next?player=sm&mix_id=%s&format=jsonh&track_id=%s' % ( session, mix_id, track_data['id']) return {