mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-06 19:45:24 +00:00
Update hdplayer.py
This commit is contained in:
parent
75ba0b1cc1
commit
347e3cfb64
@ -2,14 +2,13 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
# External library
|
# External library
|
||||||
import httpx
|
import httpx
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
# Internal utilities
|
# Internal utilities
|
||||||
from StreamingCommunity.Util.headers import get_headers
|
from StreamingCommunity.Util.headers import get_userAgent
|
||||||
from StreamingCommunity.Util.config_json import config_manager
|
from StreamingCommunity.Util.config_json import config_manager
|
||||||
|
|
||||||
|
|
||||||
@ -19,7 +18,7 @@ MAX_TIMEOUT = config_manager.get_int("REQUESTS", "timeout")
|
|||||||
|
|
||||||
class VideoSource:
|
class VideoSource:
|
||||||
def __init__(self, proxy=None):
|
def __init__(self, proxy=None):
|
||||||
self.client = httpx.Client(headers=get_headers(), timeout=MAX_TIMEOUT, proxy=proxy)
|
self.client = httpx.Client(headers={'user-agent': get_userAgent()}, timeout=MAX_TIMEOUT, proxy=proxy)
|
||||||
|
|
||||||
def extractLinkHdPlayer(self, response):
|
def extractLinkHdPlayer(self, response):
|
||||||
"""Extract iframe source from the page."""
|
"""Extract iframe source from the page."""
|
||||||
@ -34,6 +33,9 @@ class VideoSource:
|
|||||||
Extract m3u8 URL from hdPlayer page.
|
Extract m3u8 URL from hdPlayer page.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
base_domain = re.match(r'https?://(?:www\.)?([^/]+)', page_url).group(0)
|
||||||
|
self.client.headers.update({'referer': base_domain})
|
||||||
|
|
||||||
# Get the page content
|
# Get the page content
|
||||||
response = self.client.get(page_url)
|
response = self.client.get(page_url)
|
||||||
|
|
||||||
@ -47,13 +49,11 @@ class VideoSource:
|
|||||||
if response_hdplayer.status_code != 200:
|
if response_hdplayer.status_code != 200:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
soup = BeautifulSoup(response_hdplayer.text, 'html.parser')
|
sources_pattern = r'file:"([^"]+)"'
|
||||||
|
match = re.search(sources_pattern, response_hdplayer.text)
|
||||||
|
|
||||||
# Find m3u8 URL in scripts
|
if match:
|
||||||
for script in soup.find_all("script"):
|
return match.group(1)
|
||||||
match = re.search(r'sources:\s*\[\{\s*file:\s*"([^"]+)"', script.text)
|
|
||||||
if match:
|
|
||||||
return match.group(1)
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user