mirror of
https://github.com/adef17286-sudo/NPO_start_DL.git
synced 2025-12-19 12:42:15 +00:00
Refactor get_stream_url for new URL structure
Update to url Handling
This commit is contained in:
parent
06dc46fccb
commit
610d81055b
30
NPO.py
30
NPO.py
@ -15,11 +15,9 @@ def load_cookies(cookie_file):
|
|||||||
parts = line.strip().split('\t')
|
parts = line.strip().split('\t')
|
||||||
if len(parts) >= 7:
|
if len(parts) >= 7:
|
||||||
domain = parts[0]
|
domain = parts[0]
|
||||||
# Ensure the domain is valid before creating the cookie string
|
|
||||||
if domain.startswith('.'):
|
if domain.startswith('.'):
|
||||||
domain = domain[1:] # Remove leading dot for correct formatting
|
domain = domain[1:] # Remove leading dot
|
||||||
|
|
||||||
# Collecting the cookie name and value
|
|
||||||
cookie_name = parts[5]
|
cookie_name = parts[5]
|
||||||
cookie_value = parts[6]
|
cookie_value = parts[6]
|
||||||
cookie_header.append(f"{cookie_name}={cookie_value}")
|
cookie_header.append(f"{cookie_name}={cookie_value}")
|
||||||
@ -28,7 +26,8 @@ def load_cookies(cookie_file):
|
|||||||
return '; '.join(cookie_header)
|
return '; '.join(cookie_header)
|
||||||
|
|
||||||
def get_stream_url(url):
|
def get_stream_url(url):
|
||||||
if url.startswith("https://npo.nl/start/serie/") and url.endswith("/afspelen"):
|
# Validate the new URL structure
|
||||||
|
if url.startswith("https://npo.nl/start/afspelen/"):
|
||||||
try:
|
try:
|
||||||
# Load cookies from cookies.txt if it exists
|
# Load cookies from cookies.txt if it exists
|
||||||
cookie_file = 'cookies.txt'
|
cookie_file = 'cookies.txt'
|
||||||
@ -46,16 +45,19 @@ def get_stream_url(url):
|
|||||||
data = json.loads(json_data)
|
data = json.loads(json_data)
|
||||||
|
|
||||||
product_info = None
|
product_info = None
|
||||||
|
slug = url.split('/')[-1]
|
||||||
|
|
||||||
for item in data.get('props', {}).get('pageProps', {}).get('dehydratedState', {}).get('queries', []):
|
for item in data.get('props', {}).get('pageProps', {}).get('dehydratedState', {}).get('queries', []):
|
||||||
for episode_data in item.get('state', {}).get('data', []):
|
state = item.get('state', {})
|
||||||
if isinstance(episode_data, dict) and episode_data.get('slug') == url.split('/')[-2]:
|
if state:
|
||||||
product_info = {
|
episode_data = state.get('data', {})
|
||||||
'productId': episode_data.get('productId'),
|
if isinstance(episode_data, dict):
|
||||||
'guid': episode_data.get('guid')
|
if episode_data.get('slug') == slug:
|
||||||
}
|
product_info = {
|
||||||
break
|
'productId': episode_data.get('productId'),
|
||||||
if product_info:
|
'guid': episode_data.get('guid')
|
||||||
break
|
}
|
||||||
|
break
|
||||||
|
|
||||||
if product_info:
|
if product_info:
|
||||||
# Step 2: Get JWT using the same cookies
|
# Step 2: Get JWT using the same cookies
|
||||||
@ -103,7 +105,7 @@ def get_stream_url(url):
|
|||||||
return f"An error occurred while making the request: {str(e)}"
|
return f"An error occurred while making the request: {str(e)}"
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
return "Failed to decode JSON data."
|
return "Failed to decode JSON data."
|
||||||
return "Invalid URL. Please provide a URL that starts with 'https://npo.nl/start/serie/' and ends with '/afspelen'."
|
return "Invalid URL. Please provide a URL that starts with 'https://npo.nl/start/afspelen/'."
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description="Get the streaming URL from an NPO series page.")
|
parser = argparse.ArgumentParser(description="Get the streaming URL from an NPO series page.")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user