projects
/
youtube-dl
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
21fbf0f
)
[pornhub] Improve extraction and style (closes #12515)
author
Sergey M․
<dstftw@gmail.com>
Tue, 21 Mar 2017 18:59:27 +0000
(
01:59
+0700)
committer
Sergey M․
<dstftw@gmail.com>
Tue, 21 Mar 2017 18:59:27 +0000
(
01:59
+0700)
youtube_dl/extractor/pornhub.py
patch
|
blob
|
history
diff --git
a/youtube_dl/extractor/pornhub.py
b/youtube_dl/extractor/pornhub.py
index eb316ad1413985f2bd3e6fd6ac94323f71c554f5..b25f1f193fc7b1590d57966e7c819d16a4b43cd0 100644
(file)
--- a/
youtube_dl/extractor/pornhub.py
+++ b/
youtube_dl/extractor/pornhub.py
@@
-20,6
+20,7
@@
from ..utils import (
js_to_json,
orderedSet,
# sanitized_Request,
js_to_json,
orderedSet,
# sanitized_Request,
+ remove_quotes,
str_to_int,
)
# from ..aes import (
str_to_int,
)
# 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>',
- tv_webpage, 'encoded url')
- assignments = encoded_url.split(";")
+ assignments = self._search_regex(
+ r'(var.+?mediastring.+?)</script>', tv_webpage,
+ 'encoded url').split(';')
+
js_vars = {}
def parse_js_value(inp):
js_vars = {}
def parse_js_value(inp):
- inp = re.sub(r'/\*[^*]*\*/', "", inp)
-
- if "+" in inp:
- inps = inp.split("+")
- return functools.reduce(operator.concat, map(parse_js_value, inps))
-
+ inp = re.sub(r'/\*(?:(?!\*/).)*?\*/', '', inp)
+ if '+' in inp:
+ inps = inp.split('+')
+ return functools.reduce(
+ operator.concat, map(parse_js_value, inps))
inp = inp.strip()
if inp in js_vars:
return js_vars[inp]
inp = inp.strip()
if inp in js_vars:
return js_vars[inp]
-
- # Hope it's a string!
- assert inp.startswith('"') and inp.endswith('"')
- return inp[1:-1]
+ return remove_quotes(inp)
for assn in assignments:
assn = assn.strip()
for assn in assignments:
assn = assn.strip()
- if
len(assn) == 0
:
+ if
not assn
:
continue
continue
-
- assert assn.startswith("var ")
- assn = assn[4:]
- vname, value = assn.split("=", 1)
-
+ assn = re.sub(r'var\s+', '', assn)
+ 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(
r'<h1>([^>]+)</h1>', tv_webpage, 'title', default=None)
title = self._search_regex(
r'<h1>([^>]+)</h1>', tv_webpage, 'title', default=None)