projects
/
youtube-dl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[pornhub] Fix view count extraction (#26621) (refs #26614)
[youtube-dl]
/
youtube_dl
/
extractor
/
eighttracks.py
diff --git
a/youtube_dl/extractor/eighttracks.py
b/youtube_dl/extractor/eighttracks.py
index 9df2141c3166be943c80718ddd5e40b4b2ee0b24..9a44f89f3fe801047ef283e9b1fa410c8b88cb37 100644
(file)
--- a/
youtube_dl/extractor/eighttracks.py
+++ b/
youtube_dl/extractor/eighttracks.py
@@
-3,12
+3,12
@@
from __future__ import unicode_literals
import json
import random
import json
import random
-import re
-import time
from .common import InfoExtractor
from ..compat import (
compat_str,
from .common import InfoExtractor
from ..compat import (
compat_str,
+)
+from ..utils import (
ExtractorError,
)
ExtractorError,
)
@@
-17,111
+17,113
@@
class EightTracksIE(InfoExtractor):
IE_NAME = '8tracks'
_VALID_URL = r'https?://8tracks\.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
_TEST = {
IE_NAME = '8tracks'
_VALID_URL = r'https?://8tracks\.com/(?P<user>[^/]+)/(?P<id>[^/#]+)(?:#.*)?$'
_TEST = {
-
"name": "EightTracks"
,
-
"url": "http://8tracks.com/ytdl/youtube-dl-test-tracks-a"
,
-
"info_dict"
: {
+
'name': 'EightTracks'
,
+
'url': 'http://8tracks.com/ytdl/youtube-dl-test-tracks-a'
,
+
'info_dict'
: {
'id': '1336550',
'display_id': 'youtube-dl-test-tracks-a',
'id': '1336550',
'display_id': 'youtube-dl-test-tracks-a',
-
"description"
: "test chars: \"'/\\ä↭",
-
"title"
: "youtube-dl test tracks \"'/\\ä↭<>",
+
'description'
: "test chars: \"'/\\ä↭",
+
'title'
: "youtube-dl test tracks \"'/\\ä↭<>",
},
},
-
"playlist"
: [
+
'playlist'
: [
{
{
-
"md5": "96ce57f24389fc8734ce47f4c1abcc55"
,
-
"info_dict"
: {
-
"id": "11885610"
,
-
"ext": "m4a"
,
-
"title"
: "youtue-dl project<>\"' - youtube-dl test track 1 \"'/\\\u00e4\u21ad",
- "uploader_id": "ytdl"
+
'md5': '96ce57f24389fc8734ce47f4c1abcc55'
,
+
'info_dict'
: {
+
'id': '11885610'
,
+
'ext': 'm4a'
,
+
'title'
: "youtue-dl project<>\"' - youtube-dl test track 1 \"'/\\\u00e4\u21ad",
+ 'uploader_id': 'ytdl'
}
},
{
}
},
{
-
"md5": "4ab26f05c1f7291ea460a3920be8021f"
,
-
"info_dict"
: {
-
"id": "11885608"
,
-
"ext": "m4a"
,
-
"title"
: "youtube-dl project - youtube-dl test track 2 \"'/\\\u00e4\u21ad",
- "uploader_id": "ytdl"
+
'md5': '4ab26f05c1f7291ea460a3920be8021f'
,
+
'info_dict'
: {
+
'id': '11885608'
,
+
'ext': 'm4a'
,
+
'title'
: "youtube-dl project - youtube-dl test track 2 \"'/\\\u00e4\u21ad",
+ 'uploader_id': 'ytdl'
}
},
{
}
},
{
-
"md5": "d30b5b5f74217410f4689605c35d1fd7"
,
-
"info_dict"
: {
-
"id": "11885679"
,
-
"ext": "m4a"
,
-
"title"
: "youtube-dl project as well - youtube-dl test track 3 \"'/\\\u00e4\u21ad",
- "uploader_id": "ytdl"
+
'md5': 'd30b5b5f74217410f4689605c35d1fd7'
,
+
'info_dict'
: {
+
'id': '11885679'
,
+
'ext': 'm4a'
,
+
'title'
: "youtube-dl project as well - youtube-dl test track 3 \"'/\\\u00e4\u21ad",
+ 'uploader_id': 'ytdl'
}
},
{
}
},
{
-
"md5": "4eb0a669317cd725f6bbd336a29f923a"
,
-
"info_dict"
: {
-
"id": "11885680"
,
-
"ext": "m4a"
,
-
"title"
: "youtube-dl project as well - youtube-dl test track 4 \"'/\\\u00e4\u21ad",
- "uploader_id": "ytdl"
+
'md5': '4eb0a669317cd725f6bbd336a29f923a'
,
+
'info_dict'
: {
+
'id': '11885680'
,
+
'ext': 'm4a'
,
+
'title'
: "youtube-dl project as well - youtube-dl test track 4 \"'/\\\u00e4\u21ad",
+ 'uploader_id': 'ytdl'
}
},
{
}
},
{
-
"md5": "1893e872e263a2705558d1d319ad19e8"
,
-
"info_dict"
: {
-
"id": "11885682"
,
-
"ext": "m4a"
,
-
"title"
: "PH - youtube-dl test track 5 \"'/\\\u00e4\u21ad",
- "uploader_id": "ytdl"
+
'md5': '1893e872e263a2705558d1d319ad19e8'
,
+
'info_dict'
: {
+
'id': '11885682'
,
+
'ext': 'm4a'
,
+
'title'
: "PH - youtube-dl test track 5 \"'/\\\u00e4\u21ad",
+ 'uploader_id': 'ytdl'
}
},
{
}
},
{
-
"md5": "b673c46f47a216ab1741ae8836af5899"
,
-
"info_dict"
: {
-
"id": "11885683"
,
-
"ext": "m4a"
,
-
"title"
: "PH - youtube-dl test track 6 \"'/\\\u00e4\u21ad",
- "uploader_id": "ytdl"
+
'md5': 'b673c46f47a216ab1741ae8836af5899'
,
+
'info_dict'
: {
+
'id': '11885683'
,
+
'ext': 'm4a'
,
+
'title'
: "PH - youtube-dl test track 6 \"'/\\\u00e4\u21ad",
+ 'uploader_id': 'ytdl'
}
},
{
}
},
{
-
"md5": "1d74534e95df54986da7f5abf7d842b7"
,
-
"info_dict"
: {
-
"id": "11885684"
,
-
"ext": "m4a"
,
-
"title"
: "phihag - youtube-dl test track 7 \"'/\\\u00e4\u21ad",
- "uploader_id": "ytdl"
+
'md5': '1d74534e95df54986da7f5abf7d842b7'
,
+
'info_dict'
: {
+
'id': '11885684'
,
+
'ext': 'm4a'
,
+
'title'
: "phihag - youtube-dl test track 7 \"'/\\\u00e4\u21ad",
+ 'uploader_id': 'ytdl'
}
},
{
}
},
{
-
"md5": "f081f47af8f6ae782ed131d38b9cd1c0"
,
-
"info_dict"
: {
-
"id": "11885685"
,
-
"ext": "m4a"
,
-
"title"
: "phihag - youtube-dl test track 8 \"'/\\\u00e4\u21ad",
- "uploader_id": "ytdl"
+
'md5': 'f081f47af8f6ae782ed131d38b9cd1c0'
,
+
'info_dict'
: {
+
'id': '11885685'
,
+
'ext': 'm4a'
,
+
'title'
: "phihag - youtube-dl test track 8 \"'/\\\u00e4\u21ad",
+ 'uploader_id': 'ytdl'
}
}
]
}
def _real_extract(self, url):
}
}
]
}
def _real_extract(self, url):
- mobj = re.match(self._VALID_URL, url)
- playlist_id = mobj.group('id')
+ playlist_id = self._match_id(url)
webpage = self._download_webpage(url, playlist_id)
webpage = self._download_webpage(url, playlist_id)
- json_like = self._search_regex(
- r"(?s)PAGE.mix = (.*?);\n", webpage, 'trax information')
- data = json.loads(json_like)
+ data = self._parse_json(
+ self._search_regex(
+ r"(?s)PAGE\.mix\s*=\s*({.+?});\n", webpage, 'trax information'),
+ playlist_id)
session = str(random.randint(0, 1000000000))
mix_id = data['id']
track_count = data['tracks_count']
duration = data['duration']
session = str(random.randint(0, 1000000000))
mix_id = data['id']
track_count = data['tracks_count']
duration = data['duration']
- avg_song_duration = duration / track_count
+ avg_song_duration = float(duration) / track_count
+ # duration is sometimes negative, use predefined avg duration
+ if avg_song_duration <= 0:
+ avg_song_duration = 300
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):
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 = None
download_tries = 0
api_json = None
download_tries = 0
@@
-136,7
+138,7
@@
class EightTracksIE(InfoExtractor):
raise
else:
download_tries += 1
raise
else:
download_tries += 1
-
time.sleep(avg_song_duration
)
+
self._sleep(avg_song_duration, playlist_id
)
api_data = json.loads(api_json)
track_data = api_data['set']['track']
api_data = json.loads(api_json)
track_data = api_data['set']['track']