-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathppv.py
More file actions
332 lines (296 loc) · 14.2 KB
/
Copy pathppv.py
File metadata and controls
332 lines (296 loc) · 14.2 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
import asyncio
from playwright.async_api import async_playwright
import aiohttp
from datetime import datetime
API_URL = "https://ppv.to/api/streams"
CUSTOM_HEADERS = [
'#EXTVLCOPT:http-origin=https://ppv.to',
'#EXTVLCOPT:http-referrer=https://ppv.to/',
'#EXTVLCOPT:http-user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:143.0) Gecko/20100101 Firefox/143.0'
]
ALLOWED_CATEGORIES = {
"24/7 Streams", "Wrestling", "Football", "Basketball", "Baseball",
"Combat Sports", "American Football", "Darts", "Motorsports", "Ice Hockey"
}
CATEGORY_LOGOS = {
"24/7 Streams": "http://drewlive24.duckdns.org:9000/Logos/247.png",
"Wrestling": "http://drewlive24.duckdns.org:9000/Logos/Wrestling.png",
"Football": "http://drewlive24.duckdns.org:9000/Logos/Football.png",
"Basketball": "http://drewlive24.duckdns.org:9000/Logos/Basketball.png",
"Baseball": "http://drewlive24.duckdns.org:9000/Logos/Baseball.png",
"American Football": "http://drewlive24.duckdns.org:9000/Logos/NFL3.png",
"Combat Sports": "http://drewlive24.duckdns.org:9000/Logos/CombatSports2.png",
"Darts": "http://drewlive24.duckdns.org:9000/Logos/Darts.png",
"Motorsports": "http://drewlive24.duckdns.org:9000/Logos/Motorsports2.png",
"Live Now": "http://drewlive24.duckdns.org:9000/Logos/DrewLiveSports.png",
"Ice Hockey": "http://drewlive24.duckdns.org:9000/Logos/Hockey.png"
}
CATEGORY_TVG_IDS = {
"24/7 Streams": "24.7.Dummy.us",
"Wrestling": "PPV.EVENTS.Dummy.us",
"Football": "Soccer.Dummy.us",
"Basketball": "Basketball.Dummy.us",
"Baseball": "MLB.Baseball.Dummy.us",
"American Football": "NFL.Dummy.us",
"Combat Sports": "PPV.EVENTS.Dummy.us",
"Darts": "Darts.Dummy.us",
"Motorsports": "Racing.Dummy.us",
"Live Now": "24.7.Dummy.us",
"Ice Hockey": "NHL.Hockey.Dummy.us"
}
GROUP_RENAME_MAP = {
"24/7 Streams": "PPVLand - Live Channels 24/7",
"Wrestling": "PPVLand - Wrestling Events",
"Football": "PPVLand - Global Football Streams",
"Basketball": "PPVLand - Basketball Hub",
"Baseball": "PPVLand - MLB",
"American Football": "PPVLand - NFL Action",
"Combat Sports": "PPVLand - Combat Sports",
"Darts": "PPVLand - Darts",
"Motorsports": "PPVLand - Racing Action",
"Live Now": "PPVLand - Live Now",
"Ice Hockey": "PPVLand - NHL Action"
}
NFL_TEAMS = {
"arizona cardinals", "atlanta falcons", "baltimore ravens", "buffalo bills",
"carolina panthers", "chicago bears", "cincinnati bengals", "cleveland browns",
"dallas cowboys", "denver broncos", "detroit lions", "green bay packers",
"houston texans", "indianapolis colts", "jacksonville jaguars", "kansas city chiefs",
"las vegas raiders", "los angeles chargers", "los angeles rams", "miami dolphins",
"minnesota vikings", "new england patriots", "new orleans saints", "new york giants",
"new york jets", "philadelphia eagles", "pittsburgh steelers", "san francisco 49ers",
"seattle seahawks", "tampa bay buccaneers", "tennessee titans", "washington commanders"
}
COLLEGE_TEAMS = {
"alabama crimson tide", "auburn tigers", "arkansas razorbacks", "georgia bulldogs",
"florida gators", "lsu tigers", "ole miss rebels", "mississippi state bulldogs",
"tennessee volunteers", "texas longhorns", "oklahoma sooners", "oklahoma state cowboys",
"baylor bears", "tcu horned frogs", "kansas jayhawks", "kansas state wildcats",
"iowa state cyclones", "iowa hawkeyes", "michigan wolverines", "ohio state buckeyes",
"penn state nittany lions", "michigan state spartans", "wisconsin badgers",
"minnesota golden gophers", "illinois fighting illini", "northwestern wildcats",
"indiana hoosiers", "notre dame fighting irish", "usc trojans", "ucla bruins",
"oregon ducks", "oregon state beavers", "washington huskies", "washington state cougars",
"arizona wildcats", "stanford cardinal", "california golden bears", "colorado buffaloes",
"florida state seminoles", "miami hurricanes", "clemson tigers", "north carolina tar heels",
"duke blue devils", "nc state wolfpack", "wake forest demon deacons", "syracuse orange",
"virginia cavaliers", "virginia tech hokies", "louisville cardinals", "pittsburgh panthers",
"maryland terrapins", "rutgers scarlet knights", "nebraska cornhuskers", "purdue boilermakers",
"texas a&m aggies", "kentucky wildcats", "missouri tigers", "vanderbilt commodores",
"houston cougars", "utah utes", "byu cougars", "boise state broncos", "san diego state aztecs",
"cincinnati bearcats", "memphis tigers", "ucf knights", "south florida bulls", "smu mustangs",
"tulsa golden hurricane", "tulane green wave", "navy midshipmen", "army black knights",
"arizona state sun devils", "texas tech red raiders", "florida atlantic owls"
}
# --- CORRECTED FUNCTION #1 ---
async def check_m3u8_url(url, referer):
"""Checks the M3U8 URL using the correct referer for validation."""
try:
# Dynamically generate the origin from the referer URL
origin = "https://" + referer.split('/')[2]
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:143.0) Gecko/20100101 Firefox/143.0",
"Referer": referer,
"Origin": origin
}
timeout = aiohttp.ClientTimeout(total=15)
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.get(url, headers=headers) as resp:
# A 200 (OK) or 403 (Forbidden) can both indicate a working link,
# as some servers block direct file access but confirm the path exists.
return resp.status in [200, 403]
except Exception as e:
print(f"❌ Error checking {url}: {e}")
return False
async def get_streams():
try:
timeout = aiohttp.ClientTimeout(total=30)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0'
}
async with aiohttp.ClientSession(timeout=timeout, headers=headers) as session:
print(f"🌐 Fetching streams from {API_URL}")
async with session.get(API_URL) as resp:
print(f"🔍 Response status: {resp.status}")
if resp.status != 200:
error_text = await resp.text()
print(f"❌ Error response: {error_text[:500]}")
return None
return await resp.json()
except Exception as e:
print(f"❌ Error in get_streams: {str(e)}")
return None
# --- CORRECTED FUNCTION #2 ---
async def grab_m3u8_from_iframe(page, iframe_url):
found_streams = set()
def handle_response(response):
if ".m3u8" in response.url:
print(f"✅ Found M3U8 Stream: {response.url}")
found_streams.add(response.url)
page.on("response", handle_response)
print(f"🌐 Navigating to iframe: {iframe_url}")
try:
await page.goto(iframe_url, timeout=30000, wait_until="domcontentloaded")
except Exception as e:
print(f"❌ Failed to load iframe page: {e}")
page.remove_listener("response", handle_response)
return set()
try:
await page.wait_for_timeout(5000)
nested_iframe = page.locator("iframe")
if await nested_iframe.count() > 0:
print("🔎 Found nested iframe, attempting to click inside it.")
player_frame = page.frame_locator("iframe").first
# Use force=True to click even if the element is not "visible"
await player_frame.locator("body").click(timeout=5000, force=True)
else:
print("🖱️ No nested iframe found. Clicking main page body.")
await page.locator("body").click(timeout=5000, force=True)
except Exception as e:
print(f"⚠️ Clicking failed, but proceeding anyway. Error: {e}")
print("⏳ Waiting 8s for stream to be requested...")
await asyncio.sleep(8)
page.remove_listener("response", handle_response)
if not found_streams:
print(f"❌ No M3U8 URLs were captured for {iframe_url}")
return set()
valid_urls = set()
# Pass the correct iframe_url as the referer to the check function
tasks = [check_m3u8_url(url, iframe_url) for url in found_streams]
results = await asyncio.gather(*tasks)
for url, is_valid in zip(found_streams, results):
if is_valid:
valid_urls.add(url)
else:
print(f"🗑️ Discarding invalid or unreachable URL: {url}")
return valid_urls
async def grab_live_now_from_html(page, base_url="https://ppv.to/"):
print("🌐 Scraping 'Live Now' streams from HTML...")
live_now_streams = []
try:
await page.goto(base_url, timeout=20000)
await asyncio.sleep(3)
live_cards = await page.query_selector_all("#livecards a.item-card")
for card in live_cards:
href = await card.get_attribute("href")
name_el = await card.query_selector(".card-title")
poster_el = await card.query_selector("img.card-img-top")
name = await name_el.inner_text() if name_el else "Unnamed Live"
poster = await poster_el.get_attribute("src") if poster_el else None
if href:
iframe_url = f"{base_url.rstrip('/')}{href}"
live_now_streams.append({
"name": name.strip(),
"iframe": iframe_url,
"category": "Live Now",
"poster": poster
})
except Exception as e:
print(f"❌ Failed scraping 'Live Now': {e}")
print(f"✅ Found {len(live_now_streams)} 'Live Now' streams")
return live_now_streams
def build_m3u(streams, url_map):
lines = ['#EXTM3U url-tvg="https://epgshare01.online/epgshare01/epg_ripper_DUMMY_CHANNELS.xml.gz"']
seen_names = set()
for s in streams:
name_lower = s["name"].strip().lower()
if name_lower in seen_names:
continue
seen_names.add(name_lower)
unique_key = f"{s['name']}::{s['category']}::{s['iframe']}"
urls = url_map.get(unique_key, [])
if not urls:
print(f"⚠️ No working URLs for {s['name']}")
continue
orig_category = s.get("category") or "Misc"
final_group = GROUP_RENAME_MAP.get(orig_category, f"PPVLand - {orig_category}")
logo = s.get("poster") or CATEGORY_LOGOS.get(orig_category, "http://drewlive24.duckdns.org:9000/Logos/Default.png")
tvg_id = CATEGORY_TVG_IDS.get(orig_category, "Misc.Dummy.us")
if orig_category == "American Football":
matched_team = None
for team in NFL_TEAMS:
if team in name_lower:
tvg_id = "NFL.Dummy.us"
final_group = "PPVLand - NFL Action"
matched_team = team
break
if not matched_team:
for team in COLLEGE_TEAMS:
if team in name_lower:
tvg_id = "NCAA.Football.Dummy.us"
final_group = "PPVLand - College Football"
matched_team = team
break
url = next(iter(urls))
lines.append(f'#EXTINF:-1 tvg-id="{tvg_id}" tvg-logo="{logo}" group-title="{final_group}",{s["name"]}')
lines.extend(CUSTOM_HEADERS)
lines.append(url)
return "\n".join(lines)
async def main():
print("🚀 Starting PPV Stream Fetcher")
data = await get_streams()
if not data or 'streams' not in data:
print("❌ No valid data received from the API")
if data:
print(f"API Response: {data}")
return
print(f"✅ Found {len(data['streams'])} categories")
streams = []
for category in data.get("streams", []):
cat = category.get("category", "").strip() or "Misc"
if cat not in ALLOWED_CATEGORIES:
ALLOWED_CATEGORIES.add(cat)
for stream in category.get("streams", []):
iframe = stream.get("iframe")
name = stream.get("name", "Unnamed Event")
poster = stream.get("poster")
if iframe:
streams.append({
"name": name,
"iframe": iframe,
"category": cat,
"poster": poster
})
seen_names = set()
deduped_streams = []
for s in streams:
name_key = s["name"].strip().lower()
if name_key not in seen_names:
seen_names.add(name_key)
deduped_streams.append(s)
streams = deduped_streams
async with async_playwright() as p:
# For debugging, you can set headless=False to watch the browser
browser = await p.firefox.launch(headless=True)
context = await browser.new_context()
page = await context.new_page()
url_map = {}
total_streams = len(streams)
for idx, s in enumerate(streams, start=1):
key = f"{s['name']}::{s['category']}::{s['iframe']}"
print(f"\n🔎 Scraping stream {idx}/{total_streams}: {s['name']} ({s['category']})")
urls = await grab_m3u8_from_iframe(page, s["iframe"])
if urls:
print(f"✅ Got {len(urls)} stream(s) for {s['name']} ({idx}/{total_streams})")
else:
print(f"⚠️ No valid streams for {s['name']} ({idx}/{total_streams})")
url_map[key] = urls
# Process Live Now
live_now_streams = await grab_live_now_from_html(page)
for s in live_now_streams:
key = f"{s['name']}::{s['category']}::{s['iframe']}"
urls = await grab_m3u8_from_iframe(page, s["iframe"])
if urls:
print(f"✅ Got {len(urls)} 'Live Now' stream(s) for {s['name']}")
else:
print(f"⚠️ No valid 'Live Now' streams for {s['name']}")
url_map[key] = urls
streams.extend(live_now_streams)
await browser.close()
print("\n💾 Writing final playlist to PPVLand.m3u8 ...")
playlist = build_m3u(streams, url_map)
with open("PPVLand.m3u8", "w", encoding="utf-8") as f:
f.write(playlist)
print(f"✅ Done! Playlist saved as PPVLand.m3u8 at {datetime.utcnow().isoformat()} UTC")
if __name__ == "__main__":
asyncio.run(main())