re-format code to pass flake8

pull/2/head
sprhawk 7 years ago
parent d2be5bb5af
commit 951043724f

@ -5,7 +5,6 @@ from .common import InfoExtractor
import json
import random as rnd
from os import path
import re
from ..compat import (
@ -17,6 +16,7 @@ from ..utils import (
js_to_json,
)
class WeiboIE(InfoExtractor):
_VALID_URL = r'https?://weibo\.com/[0-9]+/(?P<id>[a-zA-Z0-9]+)'
_TEST = {
@ -38,7 +38,7 @@ class WeiboIE(InfoExtractor):
'Upgrade-Insecure-Requests': '1',
}
# to get Referer url for genvisitor
webpage,urlh = self._download_webpage_handle(url, video_id, headers=headers, note="first visit the page")
webpage, urlh = self._download_webpage_handle(url, video_id, headers=headers, note="first visit the page")
visitor_url = urlh.geturl()
@ -54,16 +54,16 @@ class WeiboIE(InfoExtractor):
r_genvisitor = Request(
'https://passport.weibo.com/visitor/genvisitor',
data = data,
headers = headers,
method = 'POST'
data=data,
headers=headers,
method='POST'
)
webpage,urlh = self._download_webpage_handle(r_genvisitor, video_id, note="gen visitor")
webpage, urlh = self._download_webpage_handle(r_genvisitor, video_id, note="gen visitor")
p = webpage.split("&&")[1] # split "gen_callback && gen_callback(...)"
i1 = p.find('{')
i2 = p.rfind('}')
j = p[i1:i2+1] # get JSON object
j = p[i1:i2 + 1] # get JSON object
d = json.loads(j)
tid = d["data"]["tid"]
cnfd = "%03d" % d["data"]["confidence"]
@ -78,9 +78,9 @@ class WeiboIE(InfoExtractor):
'_rand': rnd.random()
})
gencallback_url = "https://passport.weibo.com/visitor/visitor?" + param
webpage,urlh = self._download_webpage_handle(gencallback_url, video_id, note="gen callback")
webpage, urlh = self._download_webpage_handle(gencallback_url, video_id, note="gen callback")
webpage,urlh = self._download_webpage_handle(url, video_id, headers=headers, note="retry to visit the page")
webpage, urlh = self._download_webpage_handle(url, video_id, headers=headers, note="retry to visit the page")
# TODO more code goes here, for example ...
title = self._html_search_regex(r'<title>(.+?)</title>', webpage, 'title')
@ -102,7 +102,7 @@ class WeiboIE(InfoExtractor):
'height': int(res),
})
self._sort_formats(formats)
uploader = self._og_search_property('nick-name', webpage, 'uploader', default = None)
uploader = self._og_search_property('nick-name', webpage, 'uploader', default=None)
return {
'id': video_id,
'title': title,
@ -111,6 +111,7 @@ class WeiboIE(InfoExtractor):
# TODO more properties (see youtube_dl/extractor/common.py)
}
class WeiboMobileIE(InfoExtractor):
_VALID_URL = r'https?://m.weibo.cn/status/(?P<id>[0-9]+)(\?.+)?'
_TEST = {
@ -132,8 +133,8 @@ class WeiboMobileIE(InfoExtractor):
'Upgrade-Insecure-Requests': '1',
}
# to get Referer url for genvisitor
webpage,urlh = self._download_webpage_handle(url, video_id, headers=headers, note="visit the page")
js_code = self._search_regex(r'var\s+\$render_data\s*=\s*\[({.*})\]\[0\] \|\| {};', webpage, 'js_code', flags = re.DOTALL)
webpage, urlh = self._download_webpage_handle(url, video_id, headers=headers, note="visit the page")
js_code = self._search_regex(r'var\s+\$render_data\s*=\s*\[({.*})\]\[0\] \|\| {};', webpage, 'js_code', flags=re.DOTALL)
weibo_info = self._parse_json(js_code, video_id, transform_source=js_to_json)
page_info = weibo_info['status']['page_info']
title = weibo_info['status']['status_title']

Loading…
Cancel
Save