-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
71 lines (62 loc) · 2.6 KB
/
index.js
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
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
try {
const { pathname } = new URL(request.url)
if (pathname === '/ns') {
const nsM3U = await createNSPlayerM3U()
return new Response(nsM3U, { headers: { 'Content-Type': 'application/json' } })
} else if (pathname === '/ott') {
const ottM3U = await createOTTNavM3U()
return new Response(ottM3U, { headers: { 'Content-Type': 'text/plain' } })
} else {
return new Response('Toffee and Tsports marger . for ns player user /ns and for ott navigator usr /ott path', { status: 404 })
}
} catch (error) {
return new Response(`Internal Server Error: ${error.message}`, { status: 500 })
}
}
async function fetchData(url) {
const response = await fetch(url)
if (!response.ok) {
throw new Error(`Failed to fetch data from ${url}: ${response.statusText}`)
}
return response.json()
}
async function getCombinedChannelData() {
const toffeeUrl = "https://raw.githubusercontent.com/Jeshan-akand/Toffee-Channels-Link-Headers/main/toffee_channel_data.json"
const tsportsUrl = "https://raw.githubusercontent.com/byte-capsule/TSports-m3u8-Grabber/main/TSports_m3u8_headers.Json"
const toffeeData = await fetchData(toffeeUrl)
const tsportsData = await fetchData(tsportsUrl)
const combinedChannelData = [...toffeeData.channels, ...tsportsData.channels]
combinedChannelData.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()))
return combinedChannelData
}
async function createNSPlayerM3U() {
const channels = await getCombinedChannelData()
const nsPlayerData = channels.map(channel => ({
"name": channel.name,
"link": channel.link,
"logo": channel.logo,
"origin": channel.link.split("/")[2],
"referrer": "PiratesTV",
"userAgent": channel.userAgent || "",
"cookie": channel.headers?.cookie || channel.headers.Cookie,
"drmScheme": "",
"drmLicense": ""
}))
return JSON.stringify(nsPlayerData, null, 2)
}
async function createOTTNavM3U() {
const channels = await getCombinedChannelData()
let ottNavData = "# This m3u presented by t.me/piratestv_updates\n# API from byte-capsule\n"
channels.forEach((channel, i) => {
ottNavData += `#EXTINF:-1 group-title="LIVE" tvg-chno="" tvg-id="" tvg-logo="${channel.logo}", ${channel.name}\n`
ottNavData += `#EXTVLCOPT:http-user-agent=${channel.userAgent || ""}\n`
const cookie = channel.headers?.cookie || channel.headers.Cookie
ottNavData += `#EXTHTTP:{"cookie":"${cookie}"}\n`
ottNavData += `${channel.link}\n`
})
return ottNavData
}