mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-21 20:46:36 -05:00
re-format code to pass flake8
This commit is contained in:
parent
d2be5bb5af
commit
951043724f
1 changed files with 52 additions and 51 deletions
|
@ -5,7 +5,6 @@
|
|||
|
||||
import json
|
||||
import random as rnd
|
||||
from os import path
|
||||
import re
|
||||
|
||||
from ..compat import (
|
||||
|
@ -17,16 +16,17 @@
|
|||
js_to_json,
|
||||
)
|
||||
|
||||
|
||||
class WeiboIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://weibo\.com/[0-9]+/(?P<id>[a-zA-Z0-9]+)'
|
||||
_TEST = {
|
||||
'url': 'https://weibo.com/6275294458/Fp6RGfbff?type=comment',
|
||||
'info_dict': {
|
||||
'id': 'Fp6RGfbff',
|
||||
'ext': 'mp4',
|
||||
'title': 'You should have servants to massage you,... 来自Hosico_猫 - 微博',
|
||||
}
|
||||
}
|
||||
'url': 'https://weibo.com/6275294458/Fp6RGfbff?type=comment',
|
||||
'info_dict': {
|
||||
'id': 'Fp6RGfbff',
|
||||
'ext': 'mp4',
|
||||
'title': 'You should have servants to massage you,... 来自Hosico_猫 - 微博',
|
||||
}
|
||||
}
|
||||
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url)
|
||||
|
@ -38,32 +38,32 @@ def _real_extract(self, url):
|
|||
'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()
|
||||
|
||||
data = urlencode({
|
||||
"cb": "gen_callback",
|
||||
"fp": '{"os":"2","browser":"Gecko57,0,0,0","fonts":"undefined","screenInfo":"1440*900*24","plugins":""}',
|
||||
}).encode()
|
||||
}).encode()
|
||||
headers = {
|
||||
'Accept-Encoding': 'gzip, deflate, br',
|
||||
'Accept': '*/*',
|
||||
'Referer': visitor_url,
|
||||
}
|
||||
'Accept-Encoding': 'gzip, deflate, br',
|
||||
'Accept': '*/*',
|
||||
'Referer': visitor_url,
|
||||
}
|
||||
|
||||
r_genvisitor = Request(
|
||||
'https://passport.weibo.com/visitor/genvisitor',
|
||||
data = data,
|
||||
headers = headers,
|
||||
method = 'POST'
|
||||
)
|
||||
webpage,urlh = self._download_webpage_handle(r_genvisitor, video_id, note="gen visitor")
|
||||
data=data,
|
||||
headers=headers,
|
||||
method='POST'
|
||||
)
|
||||
webpage, urlh = self._download_webpage_handle(r_genvisitor, video_id, note="gen visitor")
|
||||
|
||||
p = webpage.split("&&")[1] # split "gen_callback && gen_callback(...)"
|
||||
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"]
|
||||
|
@ -76,17 +76,17 @@ def _real_extract(self, url):
|
|||
'cb': 'cross_domain',
|
||||
'from': 'weibo',
|
||||
'_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')
|
||||
|
||||
video_sources_text = self._search_regex("video-sources=\\\\\"(.+?)\"", webpage, 'video_sources')
|
||||
|
||||
|
||||
video_formats = parse.parse_qs(video_sources_text)
|
||||
|
||||
formats = []
|
||||
|
@ -100,28 +100,29 @@ def _real_extract(self, url):
|
|||
'url': vid_url,
|
||||
'format': 'mp4',
|
||||
'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,
|
||||
'uploader': uploader,
|
||||
'formats': formats
|
||||
# TODO more properties (see youtube_dl/extractor/common.py)
|
||||
}
|
||||
'id': video_id,
|
||||
'title': title,
|
||||
'uploader': uploader,
|
||||
'formats': formats
|
||||
# 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 = {
|
||||
'url': 'https://m.weibo.cn/status/4189191225395228?wm=3333_2001&sourcetype=weixin&featurecode=newtitle&from=singlemessage&isappinstalled=0',
|
||||
'info_dict': {
|
||||
'id': '4189191225395228',
|
||||
'ext': 'mp4',
|
||||
'title': '午睡当然是要甜甜蜜蜜的啦',
|
||||
'uploader': '柴犬柴犬'
|
||||
}
|
||||
}
|
||||
'url': 'https://m.weibo.cn/status/4189191225395228?wm=3333_2001&sourcetype=weixin&featurecode=newtitle&from=singlemessage&isappinstalled=0',
|
||||
'info_dict': {
|
||||
'id': '4189191225395228',
|
||||
'ext': 'mp4',
|
||||
'title': '午睡当然是要甜甜蜜蜜的啦',
|
||||
'uploader': '柴犬柴犬'
|
||||
}
|
||||
}
|
||||
|
||||
def _real_extract(self, url):
|
||||
video_id = self._match_id(url)
|
||||
|
@ -132,22 +133,22 @@ def _real_extract(self, url):
|
|||
'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']
|
||||
format = {
|
||||
'url': page_info['media_info']['stream_url'],
|
||||
'format': 'mp4',
|
||||
}
|
||||
'format': 'mp4',
|
||||
}
|
||||
formats = [format]
|
||||
uploader = weibo_info['status']['user']['screen_name']
|
||||
|
||||
return {
|
||||
'id': video_id,
|
||||
'title': title,
|
||||
'uploader': uploader,
|
||||
'formats': formats
|
||||
# TODO more properties (see youtube_dl/extractor/common.py)
|
||||
}
|
||||
'id': video_id,
|
||||
'title': title,
|
||||
'uploader': uploader,
|
||||
'formats': formats
|
||||
# TODO more properties (see youtube_dl/extractor/common.py)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue