forked from konanda-sg/DrewLive-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamsu.py
More file actions
211 lines (176 loc) · 7.9 KB
/
streamsu.py
File metadata and controls
211 lines (176 loc) · 7.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import asyncio
from playwright.async_api import async_playwright, TimeoutError as PlaywrightTimeoutError
from datetime import datetime
import aiohttp
import os
def fix_url(url):
return url.replace("streamed.su", "streamed.pk")
async def safe_request_with_retry(request, url, retries=3, delay=5, headers=None):
for attempt in range(retries):
try:
resp = await request.get(url, timeout=60000, headers=headers)
return await resp.json()
except Exception as e:
print(f"[!] Error fetching {url} (attempt {attempt + 1}/{retries}): {e}")
if attempt < retries - 1:
await asyncio.sleep(delay)
return []
ALLOWED_CATEGORIES = {
"Basketball": {
"tvg-id": "Basketball.Dummy.us",
"logo": "http://drewlive24.duckdns.org:9000/Logos/Basketball.png"
},
"Football": {
"tvg-id": "Soccer.Dummy.us",
"logo": "http://drewlive24.duckdns.org:9000/Logos/Football2.png"
},
"American Football": {
"tvg-id": "Football.Dummy.us",
"logo": "http://drewlive24.duckdns.org:9000/Logos/Am-Football.png"
},
"Baseball": {
"tvg-id": "Baseball.Dummy.us",
"logo": "http://drewlive24.duckdns.org:9000/Logos/Baseball.png"
},
"Motor Sports": {
"tvg-id": "Racing.Dummy.us",
"logo": "http://drewlive24.duckdns.org:9000/Logos/Motorsports2.png"
},
"Fight (UFC, Boxing)": {
"tvg-id": "PPV.EVENTS.Dummy.us",
"logo": "http://drewlive24.duckdns.org:9000/Logos/CombatSports2.png"
},
"Other": {
"tvg-id": "PPV.EVENTS.Dummy.us",
"logo": "http://drewlive24.duckdns.org:9000/Logos/PPV.png"
}
}
async def check_m3u8_url(url):
try:
async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=7) as resp:
return resp.status == 200
except Exception:
return False
async def main():
m3u_path = "StreamedSU.m3u8"
if os.path.exists(m3u_path):
os.remove(m3u_path)
async with async_playwright() as p:
browser = await p.firefox.launch(headless=True)
context = await browser.new_context(user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/122.0.0.0 Safari/537.36")
page = await context.new_page()
request = context.request
m3u = ["#EXTM3U"]
# Shared capture variable
m3u8_url = None
# Capture all .m3u8 from any frame/page
def capture_request(req):
nonlocal m3u8_url
if ".m3u8" in req.url and not m3u8_url:
m3u8_url = req.url
print(f"[🎯] Captured M3U8: {m3u8_url}")
context.on("request", capture_request)
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/122.0.0.0 Safari/537.36"
}
sports = await safe_request_with_retry(request, fix_url("https://streamed.su/api/sports"), headers=headers)
if not sports:
print("[✖] No sports data fetched. Aborting.")
return
for sport in sports:
sport_name = sport.get("name")
if sport_name not in ALLOWED_CATEGORIES:
continue
sport_id = sport.get("id")
tvg_id = ALLOWED_CATEGORIES[sport_name]["tvg-id"]
fallback_logo = ALLOWED_CATEGORIES[sport_name]["logo"]
group_title = f"StreamedSU - {sport_name}"
print(f"\n=== {sport_name} ===")
matches = await safe_request_with_retry(request, fix_url(f"https://streamed.su/api/matches/{sport_id}"), headers=headers)
if not matches:
print(f"[!] No matches for {sport_name}")
continue
for match in matches:
title = match.get("title", "No Title")
date_ts = match.get("date", 0)
date = datetime.fromtimestamp(date_ts / 1000).strftime("%Y-%m-%d %H:%M")
sources = match.get("sources", [])
if not sources:
continue
m3u8_url = None
language = "Unknown"
quality = "SD"
for source in sources:
source_id = source.get("id")
source_type = source.get("source")
stream_data = await safe_request_with_retry(
request,
fix_url(f"https://streamed.su/api/stream/{source_type}/{source_id}"),
headers=headers
)
for stream_info in stream_data:
embed_url = stream_info.get("embedUrl")
if not embed_url:
continue
language = stream_info.get("language", "Unknown")
quality = "HD" if stream_info.get("hd") else "SD"
m3u8_url = None
try:
print(f"\nVisiting: {title} (source: {source_type})")
await page.goto(embed_url, timeout=15000)
await page.wait_for_timeout(2000)
# Check for iframe
iframe_el = await page.query_selector("iframe")
if iframe_el:
iframe_src = await iframe_el.get_attribute("src")
if iframe_src:
print(f"[🔍] Found iframe: {iframe_src}")
await page.goto(iframe_src, timeout=15000)
await page.wait_for_timeout(4000)
# Click to trigger playback
for _ in range(6):
await page.mouse.click(400, 300)
await page.wait_for_timeout(2000)
if m3u8_url:
break
if m3u8_url:
valid = await check_m3u8_url(m3u8_url)
if valid:
break
else:
print(f"[!] Invalid stream URL (not 200): {m3u8_url}")
m3u8_url = None
else:
print(f"[✖] No m3u8 found for: {embed_url}")
except PlaywrightTimeoutError:
print(f"[!] Timeout while loading: {embed_url}")
except Exception as e:
print(f"[!] Error visiting embed for {title}: {e}")
if m3u8_url:
break
if not m3u8_url:
print(f"[✖] Failed: No valid stream found for {title}")
continue
logo = fallback_logo
teams = match.get("teams")
if teams:
home = teams.get("home")
if home and home.get("badge"):
logo = f"https://streamed.pk/api/images/badge/{home['badge']}.webp"
extinf = f'#EXTINF:-1 tvg-id="{tvg_id}" tvg-logo="{logo}" group-title="{group_title}",{title} ({language} - {quality})'
m3u.append(extinf)
m3u.append(m3u8_url)
print(f"[✔] Success: {title} ({language} - {quality})")
playlist = "\n".join(m3u)
with open(m3u_path, "w", encoding="utf-8") as f:
f.write(playlist)
print("\n✅ Done. Playlist written to StreamedSU.m3u8")
await browser.close()
if __name__ == "__main__":
try:
asyncio.run(main())
except Exception as e:
print(f"[!] Fatal error in main: {e}")