fail play fix2
This commit is contained in:
+36
-18
@@ -255,6 +255,7 @@ class LogicLinkkf(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Exception:%s", e)
|
logger.error("Exception:%s", e)
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
|
return ""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_html_requests(url, cached=False, referer=None, reset_session=False):
|
def get_html_requests(url, cached=False, referer=None, reset_session=False):
|
||||||
@@ -463,25 +464,36 @@ class LogicLinkkf(object):
|
|||||||
# sess=LogicLinkkf.session,
|
# sess=LogicLinkkf.session,
|
||||||
# delay=10,
|
# delay=10,
|
||||||
# )
|
# )
|
||||||
# scraper = cloudscraper.create_scraper(sess=re_sess)
|
last_exception = None
|
||||||
scraper = cloudscraper.create_scraper(
|
for attempt in range(3):
|
||||||
# debug=True,
|
try:
|
||||||
delay=10,
|
if attempt > 0:
|
||||||
sess=LogicLinkkf.session,
|
LogicLinkkf._reset_http_state()
|
||||||
browser={
|
LogicLinkkf.session = requests.Session()
|
||||||
"custom": "linkkf",
|
headers["User-Agent"] = random.choice(user_agents_list)
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
# print(scraper.get(url, headers=LogicLinkkf.headers).content)
|
scraper = cloudscraper.create_scraper(
|
||||||
# print(scraper.get(url).content)
|
delay=10,
|
||||||
# return scraper.get(url, headers=LogicLinkkf.headers).content
|
sess=LogicLinkkf.session,
|
||||||
# logger.debug(LogicLinkkf.headers)
|
browser={
|
||||||
return scraper.get(
|
"custom": "linkkf",
|
||||||
url,
|
},
|
||||||
headers=headers,
|
)
|
||||||
timeout=10,
|
|
||||||
).content.decode("utf8", errors="replace")
|
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
|
@staticmethod
|
||||||
def get_video_url_from_url(url, url2):
|
def get_video_url_from_url(url, url2):
|
||||||
@@ -1274,6 +1286,12 @@ class LogicLinkkf(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _extract_stream_config(player_html, base_url):
|
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
|
video_url = None
|
||||||
vtt_url = None
|
vtt_url = None
|
||||||
|
|
||||||
|
|||||||
+30
-1
@@ -46,6 +46,20 @@ class ModuleBasic(PluginModuleBase):
|
|||||||
+ urllib.parse.urlsplit(referer or P.ModelSetting.get("linkkf_url")).netloc,
|
+ 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
|
@staticmethod
|
||||||
def _rewrite_m3u8(content, target_url, referer):
|
def _rewrite_m3u8(content, target_url, referer):
|
||||||
def replace_uri_attr(line):
|
def replace_uri_attr(line):
|
||||||
@@ -262,10 +276,25 @@ class ModuleBasic(PluginModuleBase):
|
|||||||
headers = self._get_proxy_headers(referer)
|
headers = self._get_proxy_headers(referer)
|
||||||
if req.headers.get("Range") is not None:
|
if req.headers.get("Range") is not None:
|
||||||
headers["Range"] = req.headers.get("Range")
|
headers["Range"] = req.headers.get("Range")
|
||||||
upstream = requests.get(target, headers=headers, stream=True, timeout=30)
|
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", "")
|
content_type = upstream.headers.get("content-type", "")
|
||||||
|
|
||||||
if upstream.status_code >= 400:
|
if upstream.status_code >= 400:
|
||||||
|
if self._is_optional_proxy_target(target):
|
||||||
|
return Response(status=204)
|
||||||
return Response(
|
return Response(
|
||||||
upstream.content,
|
upstream.content,
|
||||||
status=upstream.status_code,
|
status=upstream.status_code,
|
||||||
|
|||||||
Reference in New Issue
Block a user