formatting the code

This commit is contained in:
lifegpc 2020-08-04 16:49:38 +08:00
parent f3f8c649c9
commit 5c5c58243b

View File

@ -1,26 +1,21 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import hashlib
import re import re
import json import json
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import ( from ..compat import (
compat_parse_qs,
compat_urlparse, compat_urlparse,
) )
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
int_or_none, int_or_none,
float_or_none,
parse_iso8601, parse_iso8601,
smuggle_url, smuggle_url,
str_or_none, str_or_none,
strip_jsonp, strip_jsonp,
unified_timestamp,
unsmuggle_url, unsmuggle_url,
urlencode_postdata,
) )
@ -126,7 +121,7 @@ class BiliBiliIE(InfoExtractor):
return int(s) return int(s)
else: else:
r = re.search(r"([0-9]+)/([0-9]+)", s) r = re.search(r"([0-9]+)/([0-9]+)", s)
if r!=None : if r is not None:
r = r.groups() r = r.groups()
return int(r[0]) / int(r[1]) return int(r[0]) / int(r[1])
else: else:
@ -158,7 +153,7 @@ class BiliBiliIE(InfoExtractor):
webpage = self._download_webpage(url, video_id) webpage = self._download_webpage(url, video_id)
video_info = re.search(r"window\.__INITIAL_STATE__=([^;]+)", webpage, re.I) video_info = re.search(r"window\.__INITIAL_STATE__=([^;]+)", webpage, re.I)
if video_info != None : if video_info is not None:
video_info = json.loads(video_info.groups()[0]) video_info = json.loads(video_info.groups()[0])
else: else:
self._report_error("") # TODO Should redirect to Bangumi episode ID. self._report_error("") # TODO Should redirect to Bangumi episode ID.
@ -215,7 +210,7 @@ class BiliBiliIE(InfoExtractor):
entries = [] entries = []
for part_info in video_data['pages']: for part_info in video_data['pages']:
if part != None and part_info["page"]!=part : if part is not None and part_info["page"] != part:
continue continue
uri = f'https://www.bilibili.com/video/av{aid}?p={part_info["page"]}' uri = f'https://www.bilibili.com/video/av{aid}?p={part_info["page"]}'
if first: if first:
@ -225,7 +220,7 @@ class BiliBiliIE(InfoExtractor):
headers = {'referer': uri} headers = {'referer': uri}
if new_api: if new_api:
play_info = re.search(r"window\.__playinfo__=([^<]+)", webpage, re.I) # Get video links from webpage. play_info = re.search(r"window\.__playinfo__=([^<]+)", webpage, re.I) # Get video links from webpage.
if play_info != None : if play_info is not None:
play_info = json.loads(play_info.groups()[0]) play_info = json.loads(play_info.groups()[0])
if play_info['code'] != 0: if play_info['code'] != 0:
self._report_error(play_info) self._report_error(play_info)
@ -250,7 +245,7 @@ class BiliBiliIE(InfoExtractor):
self._report_error(play_info) self._report_error(play_info)
play_info = play_info['data'] play_info = play_info['data']
if 'durl' in play_info: # Stream for flv player if 'durl' in play_info: # Stream for flv player
if video_count > 1 and len(play_info['durl']) > 1 and part==None : if video_count > 1 and len(play_info['durl']) > 1 and part is None:
self.report_warning( self.report_warning(
f"There are multiply FLV files in this part. Please input \"{uri}\" to extract it.", f"There are multiply FLV files in this part. Please input \"{uri}\" to extract it.",
f"{video_id} Part{part_info['page']}") f"{video_id} Part{part_info['page']}")
@ -281,7 +276,7 @@ class BiliBiliIE(InfoExtractor):
f"Geting video links for format id : {video_q}.", f"Geting video links for format id : {video_q}.",
f"Unable to get video links for format id : {video_q}.") f"Unable to get video links for format id : {video_q}.")
play_info = re.search(r"window\.__playinfo__=([^<]+)", webpage, re.I) # Get video links from webpage. play_info = re.search(r"window\.__playinfo__=([^<]+)", webpage, re.I) # Get video links from webpage.
if play_info != None : if play_info is not None:
play_info = json.loads(play_info.groups()[0]) play_info = json.loads(play_info.groups()[0])
if play_info['code'] != 0: if play_info['code'] != 0:
self._report_error(play_info) self._report_error(play_info)
@ -363,7 +358,7 @@ class BiliBiliIE(InfoExtractor):
f"Geting video links for format id : {video_q}.", f"Geting video links for format id : {video_q}.",
f"Unable to get video links for format id : {video_q}.") f"Unable to get video links for format id : {video_q}.")
play_info = re.search(r"window\.__playinfo__=([^<]+)", webpage, re.I) # Get video links from webpage. play_info = re.search(r"window\.__playinfo__=([^<]+)", webpage, re.I) # Get video links from webpage.
if play_info != None : if play_info is not None:
play_info = json.loads(play_info.groups()[0]) play_info = json.loads(play_info.groups()[0])
if play_info['code'] != 0: if play_info['code'] != 0:
self._report_error(play_info) self._report_error(play_info)
@ -414,7 +409,7 @@ class BiliBiliIE(InfoExtractor):
"height": video_format['height'], "height": video_format['height'],
"http_headers": headers "http_headers": headers
}) })
if 'audio' in dash and dash['audio']!=None : if 'audio' in dash and dash['audio'] is not None:
for audio_format in dash['audio']: for audio_format in dash['audio']:
accept_audio_quality.append(audio_format['id']) accept_audio_quality.append(audio_format['id'])
video_formats[audio_format['id']] = audio_format video_formats[audio_format['id']] = audio_format