fail play fix2
This commit is contained in:
+24
-6
@@ -255,6 +255,7 @@ class LogicLinkkf(object):
|
||||
except Exception as e:
|
||||
logger.error("Exception:%s", e)
|
||||
logger.error(traceback.format_exc())
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
def get_html_requests(url, cached=False, referer=None, reset_session=False):
|
||||
@@ -463,9 +464,15 @@ class LogicLinkkf(object):
|
||||
# sess=LogicLinkkf.session,
|
||||
# delay=10,
|
||||
# )
|
||||
# scraper = cloudscraper.create_scraper(sess=re_sess)
|
||||
last_exception = None
|
||||
for attempt in range(3):
|
||||
try:
|
||||
if attempt > 0:
|
||||
LogicLinkkf._reset_http_state()
|
||||
LogicLinkkf.session = requests.Session()
|
||||
headers["User-Agent"] = random.choice(user_agents_list)
|
||||
|
||||
scraper = cloudscraper.create_scraper(
|
||||
# debug=True,
|
||||
delay=10,
|
||||
sess=LogicLinkkf.session,
|
||||
browser={
|
||||
@@ -473,15 +480,20 @@ class LogicLinkkf(object):
|
||||
},
|
||||
)
|
||||
|
||||
# print(scraper.get(url, headers=LogicLinkkf.headers).content)
|
||||
# print(scraper.get(url).content)
|
||||
# return scraper.get(url, headers=LogicLinkkf.headers).content
|
||||
# logger.debug(LogicLinkkf.headers)
|
||||
return scraper.get(
|
||||
url,
|
||||
headers=headers,
|
||||
timeout=10,
|
||||
).content.decode("utf8", errors="replace")
|
||||
except requests.exceptions.RequestException as e:
|
||||
last_exception = e
|
||||
if attempt < 2:
|
||||
time.sleep(0.4 * (attempt + 1))
|
||||
continue
|
||||
|
||||
if last_exception is not None:
|
||||
raise last_exception
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
def get_video_url_from_url(url, url2):
|
||||
@@ -1274,6 +1286,12 @@ class LogicLinkkf(object):
|
||||
|
||||
@staticmethod
|
||||
def _extract_stream_config(player_html, base_url):
|
||||
if player_html in [None, b"", ""]:
|
||||
return None, None
|
||||
if isinstance(player_html, bytes):
|
||||
player_html = player_html.decode("utf8", errors="replace")
|
||||
player_html = str(player_html)
|
||||
|
||||
video_url = None
|
||||
vtt_url = None
|
||||
|
||||
|
||||
@@ -46,6 +46,20 @@ class ModuleBasic(PluginModuleBase):
|
||||
+ urllib.parse.urlsplit(referer or P.ModelSetting.get("linkkf_url")).netloc,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _is_optional_proxy_target(target):
|
||||
lower = str(target or "").lower()
|
||||
optional_exts = [
|
||||
".vtt",
|
||||
".srt",
|
||||
".jpg",
|
||||
".jpeg",
|
||||
".png",
|
||||
".webp",
|
||||
".gif",
|
||||
]
|
||||
return any(lower.endswith(ext) for ext in optional_exts)
|
||||
|
||||
@staticmethod
|
||||
def _rewrite_m3u8(content, target_url, referer):
|
||||
def replace_uri_attr(line):
|
||||
@@ -262,10 +276,25 @@ class ModuleBasic(PluginModuleBase):
|
||||
headers = self._get_proxy_headers(referer)
|
||||
if req.headers.get("Range") is not None:
|
||||
headers["Range"] = req.headers.get("Range")
|
||||
upstream = None
|
||||
last_exception = None
|
||||
for attempt in range(3):
|
||||
try:
|
||||
upstream = requests.get(target, headers=headers, stream=True, timeout=30)
|
||||
break
|
||||
except requests.exceptions.RequestException as e:
|
||||
last_exception = e
|
||||
if attempt < 2:
|
||||
continue
|
||||
if upstream is None:
|
||||
if self._is_optional_proxy_target(target):
|
||||
return Response(status=204)
|
||||
raise last_exception
|
||||
content_type = upstream.headers.get("content-type", "")
|
||||
|
||||
if upstream.status_code >= 400:
|
||||
if self._is_optional_proxy_target(target):
|
||||
return Response(status=204)
|
||||
return Response(
|
||||
upstream.content,
|
||||
status=upstream.status_code,
|
||||
|
||||
Reference in New Issue
Block a user