[pornhub] Improve extraction and style (closes #12515)
This commit is contained in:
parent
21fbf0f955
commit
e1e35d1ac6
1 changed files with 15 additions and 20 deletions
|
@ -20,6 +20,7 @@ from ..utils import (
|
||||||
js_to_json,
|
js_to_json,
|
||||||
orderedSet,
|
orderedSet,
|
||||||
# sanitized_Request,
|
# sanitized_Request,
|
||||||
|
remove_quotes,
|
||||||
str_to_int,
|
str_to_int,
|
||||||
)
|
)
|
||||||
# from ..aes import (
|
# from ..aes import (
|
||||||
|
@ -131,38 +132,32 @@ class PornHubIE(InfoExtractor):
|
||||||
|
|
||||||
tv_webpage = dl_webpage('tv')
|
tv_webpage = dl_webpage('tv')
|
||||||
|
|
||||||
encoded_url = self._search_regex(r'(var.*mediastring.*)</script>',
|
assignments = self._search_regex(
|
||||||
tv_webpage, 'encoded url')
|
r'(var.+?mediastring.+?)</script>', tv_webpage,
|
||||||
assignments = encoded_url.split(";")
|
'encoded url').split(';')
|
||||||
|
|
||||||
js_vars = {}
|
js_vars = {}
|
||||||
|
|
||||||
def parse_js_value(inp):
|
def parse_js_value(inp):
|
||||||
inp = re.sub(r'/\*[^*]*\*/', "", inp)
|
inp = re.sub(r'/\*(?:(?!\*/).)*?\*/', '', inp)
|
||||||
|
if '+' in inp:
|
||||||
if "+" in inp:
|
inps = inp.split('+')
|
||||||
inps = inp.split("+")
|
return functools.reduce(
|
||||||
return functools.reduce(operator.concat, map(parse_js_value, inps))
|
operator.concat, map(parse_js_value, inps))
|
||||||
|
|
||||||
inp = inp.strip()
|
inp = inp.strip()
|
||||||
if inp in js_vars:
|
if inp in js_vars:
|
||||||
return js_vars[inp]
|
return js_vars[inp]
|
||||||
|
return remove_quotes(inp)
|
||||||
# Hope it's a string!
|
|
||||||
assert inp.startswith('"') and inp.endswith('"')
|
|
||||||
return inp[1:-1]
|
|
||||||
|
|
||||||
for assn in assignments:
|
for assn in assignments:
|
||||||
assn = assn.strip()
|
assn = assn.strip()
|
||||||
if len(assn) == 0:
|
if not assn:
|
||||||
continue
|
continue
|
||||||
|
assn = re.sub(r'var\s+', '', assn)
|
||||||
assert assn.startswith("var ")
|
vname, value = assn.split('=', 1)
|
||||||
assn = assn[4:]
|
|
||||||
vname, value = assn.split("=", 1)
|
|
||||||
|
|
||||||
js_vars[vname] = parse_js_value(value)
|
js_vars[vname] = parse_js_value(value)
|
||||||
|
|
||||||
video_url = js_vars["mediastring"]
|
video_url = js_vars['mediastring']
|
||||||
|
|
||||||
title = self._search_regex(
|
title = self._search_regex(
|
||||||
r'<h1>([^>]+)</h1>', tv_webpage, 'title', default=None)
|
r'<h1>([^>]+)</h1>', tv_webpage, 'title', default=None)
|
||||||
|
|
Loading…
Reference in a new issue