2025-05-10 13:58:58 +01:00
|
|
|
import os
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
import requests
|
|
|
|
import json
|
2025-07-15 15:45:17 +01:00
|
|
|
from typing import List
|
2025-05-10 13:58:58 +01:00
|
|
|
load_dotenv()
|
|
|
|
|
|
|
|
|
2025-07-15 15:45:17 +01:00
|
|
|
def get_latest_urls_from_dns() -> List[str]:
|
|
|
|
"""Retrieves the latest stream URLs from DNS and extra URL files.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A list of unique stream URLs.
|
|
|
|
"""
|
|
|
|
with open("./ktvmanager/lib/DNS_list.txt") as f:
|
|
|
|
lines = [line.rstrip("\n") for line in f]
|
|
|
|
with open("./ktvmanager/lib/extra_urls.txt") as urls:
|
|
|
|
extra_urls = [line.rstrip("\n") for line in urls]
|
2025-05-10 13:58:58 +01:00
|
|
|
# print(lines)
|
|
|
|
|
|
|
|
complete_list_of_urls = []
|
|
|
|
|
|
|
|
for url in lines:
|
|
|
|
data = requests.get(url)
|
|
|
|
try:
|
|
|
|
content = json.loads(data.text)
|
|
|
|
except Exception:
|
|
|
|
pass
|
2025-07-13 19:40:04 +01:00
|
|
|
try:
|
2025-07-15 15:45:17 +01:00
|
|
|
list_of_urls = content["su"].split(",")
|
2025-07-13 19:40:04 +01:00
|
|
|
except KeyError:
|
2025-07-15 15:45:17 +01:00
|
|
|
list_of_urls = content["fu"].split(",")
|
2025-05-10 13:58:58 +01:00
|
|
|
for url in list_of_urls:
|
|
|
|
complete_list_of_urls.append(url)
|
|
|
|
complete_list_of_urls = list(set(complete_list_of_urls))
|
|
|
|
for url in extra_urls:
|
|
|
|
complete_list_of_urls.append(url)
|
2025-07-13 19:40:04 +01:00
|
|
|
return list(dict.fromkeys(complete_list_of_urls))
|
2025-07-15 15:45:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
def generate_urls_for_user(username: str, password: str) -> List[str]:
|
|
|
|
"""Generates a list of full stream URLs for a specific user.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
username: The username of the user.
|
|
|
|
password: The password of the user.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
A list of fully constructed stream URLs for the user.
|
|
|
|
"""
|
2025-05-10 13:58:58 +01:00
|
|
|
new_urls = []
|
|
|
|
for url in get_latest_urls_from_dns():
|
2025-07-15 15:45:17 +01:00
|
|
|
hard_url = (
|
|
|
|
f"/player_api.php?password={password}&username={username}&action=user&sub=info"
|
|
|
|
)
|
2025-05-10 13:58:58 +01:00
|
|
|
new_url = url + hard_url
|
|
|
|
new_urls.append(new_url)
|
|
|
|
return new_urls
|
|
|
|
|
2025-07-15 11:38:59 +01:00
|
|
|
|