aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2015-01-10 05:47:05 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2015-01-10 05:47:05 +0100
commitc24dfef63c55ef1a5424d11b485c3b76245448a4 (patch)
tree27eebd825cee0566c5347b11ef25d63e0e1fb2d4
parent6271f1cad9331cbdb274906d8330736fb888bda2 (diff)
parent754f0008ec6b87316ce3e4807f150726ff2af3c5 (diff)
downloadyoutube-dl-c24dfef63c55ef1a5424d11b485c3b76245448a4.tar.xz
Merge remote-tracking branch 'lenaten/8tracks'
-rw-r--r--youtube_dl/extractor/eighttracks.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/youtube_dl/extractor/eighttracks.py b/youtube_dl/extractor/eighttracks.py
index a30a1f330..9df2141c3 100644
--- a/youtube_dl/extractor/eighttracks.py
+++ b/youtube_dl/extractor/eighttracks.py
@@ -4,10 +4,12 @@ from __future__ import unicode_literals
import json
import random
import re
+import time
from .common import InfoExtractor
from ..compat import (
compat_str,
+ ExtractorError,
)
@@ -112,14 +114,30 @@ class EightTracksIE(InfoExtractor):
session = str(random.randint(0, 1000000000))
mix_id = data['id']
track_count = data['tracks_count']
+ duration = data['duration']
+ avg_song_duration = 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
+ time.sleep(avg_song_duration)
+
api_data = json.loads(api_json)
track_data = api_data['set']['track']
info = {
@@ -131,6 +149,7 @@ class EightTracksIE(InfoExtractor):
'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 {