-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathaddon.js
More file actions
347 lines (286 loc) · 11.2 KB
/
Copy pathaddon.js
File metadata and controls
347 lines (286 loc) · 11.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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
const axios = require('axios').default;
axios.defaults.headers.get["content-type"] = "application/json";
axios.defaults.timeout = 60000
axios.defaults.method = "GET"
function getUserData(userConf) {
let retrievedData, url, obj = {}
try {
retrievedData = JSON.parse(Buffer.from(userConf, 'base64').toString())
} catch (error) {
console.log(error)
return "error while parsing url"
}
let domainName,baseURL,idPrefix
if(typeof retrievedData === "object"){
domainName = retrievedData.BaseURL.split("/")[2].split(":")[0] || "unknown"
baseURL = retrievedData.BaseURL
idPrefix = domainName.charAt(0) + domainName.substr(Math.ceil(domainName.length / 2 - 1), domainName.length % 2 === 0 ? 2 : 1) + domainName.charAt(domainName.length - 1) + ":";
obj = {
baseURL,
domainName,
idPrefix,
username:retrievedData.username,
password:retrievedData.password
}
}else if(retrievedData.includes("http")){
url = retrievedData
const queryString = url.split('?')[1] || "unknown"
baseURL = url.split('/')[0] + "//" + url.split('?')[0].split('/')[2] || "unknown"
domainName = url.split("?")[0].split("/")[2].split(":")[0] || "unknown"
idPrefix = domainName.charAt(0) + domainName.substr(Math.ceil(domainName.length / 2 - 1), domainName.length % 2 === 0 ? 2 : 1) + domainName.charAt(domainName.length - 1) + ":";
if(queryString === undefined){return {result:"URL does not have any queries!"}}
if(baseURL === undefined){return {result:"URL does not seem like an url!"}}
obj.baseURL = baseURL
obj.domainName = domainName
obj.idPrefix = idPrefix
const urlParams = new URLSearchParams(queryString);
const entries = urlParams.entries();
for(const entry of entries) {
obj[entry[0]] = entry[1]
}
}
if(obj.username && obj.password && obj.baseURL){
return obj
}else{
console.log("Error while parsing!")
return {}
}
}
async function getManifest(url) {
const obj = getUserData(url)
let vod
try {
vod = await axios({url:`${obj.baseURL}/player_api.php?username=${obj.username}&password=${obj.password}&action=get_vod_categories`})
} catch (error) {
console.log(error)
return {error}
}
const vodJSON = vod.data
let movieCatalog = []
if (vod.status === 200){
vodJSON.forEach(i => {
let name = i.category_name
movieCatalog.push(name)
});
}
let series
try {
series = await axios({url:`${obj.baseURL}/player_api.php?username=${obj.username}&password=${obj.password}&action=get_series_categories`})
} catch (error) {
console.log(error)
return {error}
}
const seriesJSON = series.data
let seriesCatalog = []
if(series.status === 200){
seriesJSON.forEach(i => {
let name = i.category_name
seriesCatalog.push(name)
});
}
let live
try {
live = await axios({url:`${obj.baseURL}/player_api.php?username=${obj.username}&password=${obj.password}&action=get_live_categories`})
} catch (error) {
console.log(error)
return {error}
}
const liveJSON = live.data
let liveCatalog = []
if(series.status === 200){
liveJSON.forEach(i => {
let name = i.category_name
liveCatalog.push(name)
});
}
const manifest = {
id:`org.community.${obj.domainName}` || "org.community.youriptv",
version:"1.0.0",
name:obj.domainName + " IPTV" || "Your IPTV",
description:`You will access to your ${obj.domainName} IPTV with this addon!`,
idPrefixes:[obj.idPrefix],
//idPrefixes:["tmdb:", obj.idPrefix],
catalogs:[
{
id:`${obj.idPrefix}movie`,
name: obj.domainName || "Your IPTV",
type:"movie",
extra:[{name:"genre",options:movieCatalog,isRequired:true}],
isRequired: true
},
{
id:`${obj.idPrefix}series`,
name:obj.domainName || "Your IPTV",
type:"series",
extra:[{name:"genre",options:seriesCatalog,isRequired:true}],
isRequired: true
},
{
id:`${obj.idPrefix}tv`,
name: obj.domainName || "Your IPTV",
type:"tv",
extra:[{name:"genre",options:liveCatalog,isRequired:true}],
}
],
resources:["catalog","meta","stream"],
types:["movie","series","tv"],
behaviorHints:{configurable : true, configurationRequired: false },
}
return manifest
}
function getValidUrl(url) {
try {
const urlObj = new URL(url);
return urlObj.protocol.startsWith('http') ? url : '';
} catch {
return '';
}
}
async function getCatalog(url,type,genre) {
const obj = getUserData(url)
let getCategoryID
try {
if(type === "movie"){
getCategoryID = await axios({url:`${obj.baseURL}/player_api.php?username=${obj.username}&password=${obj.password}&action=get_vod_categories`})
}
else if(type ==="series"){
getCategoryID = await axios({url:`${obj.baseURL}/player_api.php?username=${obj.username}&password=${obj.password}&action=get_series_categories`})
}
else if(type ==="tv"){
getCategoryID = await axios({url:`${obj.baseURL}/player_api.php?username=${obj.username}&password=${obj.password}&action=get_live_categories`})
}
}catch (error) {
console.log(error)
return []
}
let catID
getCategoryID.data.forEach(i => {
if(i.category_name === genre){
catID = i.category_id
}
});
// console.log(catID)
let action = type === "movie" ? "get_vod_streams" : type === "series" ? "get_series": type ==="tv" ? "get_live_streams" : "error"
let paramsCat = {
username: obj.username,
password: obj.password,
action,
category_id: catID
}
let getCatalogs
try {
getCatalogs = await axios({url:`${obj.baseURL}/player_api.php`,method:"GET",params:paramsCat})
} catch (error) {
console.log(error)
// return [{error,errorLocation:"Could not use the parameters wile searching catalogs!"}]
return []
}
let metas = []
getCatalogs.data.forEach(i => {
let id,name = i.name, poster, posterShape, imdbRating
if(type === "series"){
id = obj.idPrefix + i.series_id || ""
poster = getValidUrl(i.cover)
imdbRating = i.rating || ""
posterShape = "poster"
}else if(type === "movie"){
id = obj.idPrefix + i.stream_id || ""
poster = getValidUrl(i.stream_icon)
imdbRating = i.rating || ""
posterShape = "poster"
}else if (type === "tv"){
id = obj.idPrefix + i.stream_id || ""
poster = getValidUrl(i.stream_icon)
imdbRating = null
posterShape = "square"
}
metas.push({id,type,name,poster,posterShape,imdbRating})
});
return metas
}
async function getMeta(url,type,id) {
const streamID = id.split(":")[1]
const obj = getUserData(url)
let action = type === "movie" ? "get_vod_info" : type === "series" ? "get_series_info": type ==="tv" ? "get_live_streams" : "error"
let requestID = type === "movie" ? "vod_id" : type === "series" ? "series_id": type ==="tv" ? "stream_id" : "error"
let params = {
username: obj.username,
password: obj.password,
action,
[requestID]:streamID
}
if(type === "tv"){
delete params[requestID]
}
// console.log(params)
let getMeta
try {
getMeta = await axios({url:`${obj.baseURL}/player_api.php`,params})
} catch (error) {
console.log(error)
return {}
// return [{error,errorLocation:"Could not use the parameters wile searching meta!"}]
}
// console.log(getMeta.data)
let meta = {}
if(type === "movie"|| type === "series"){
meta ={
id: obj.idPrefix + streamID || "",
//id: getMeta.data.info.tmdb_id === undefined ? obj.idPrefix + streamID : "tmdb:"+getMeta.data.info.tmdb_id, // "tmdb:"+getMeta.data.info.tmdb_id || obj.idPrefix + streamID || "",
type,
name: getMeta.data.info.name === undefined ? "" : getMeta.data.info.name,
poster: getMeta.data.info.cover_big || "",
background: getMeta.data.info.backdrop_path[0] || "https://www.stremio.com/website/wallpapers/stremio-wallpaper-5.jpg",
description: getMeta.data.info.description || "",
releaseInfo: String(getMeta.data && getMeta.data.info && (getMeta.data.info.releaseDate || getMeta.data.info.releasedate).split("-")[0])
}
}
if(type === "series"){
let videos = []
const seasons = Object.keys(getMeta.data.episodes)
seasons.forEach(season => {
// console.log(season)
getMeta.data.episodes[season].forEach(episode => {
let id = obj.idPrefix + episode.id || ""
let title = episode.title || ""
let season = episode.season || null
let episodeNo = episode.episode_num || null
let overview = episode.plot || ""
let thumbnail = episode.info.movie_image || null
let released = episode.info.releasedate === undefined ? Date.now() : new Date(episode.info.releasedate)
let container_extension = episode.container_extension || "mp4"
let streams = [{
name:obj.domainName,
description: title,
url: `${obj.baseURL}/series/${obj.username}/${obj.password}/${episode.id}.${container_extension}`,
}]
// console.log(streams)
videos.push({id,title,season,episode:episodeNo,overview,thumbnail,released,streams})
});
});
// console.log(videos)
meta.name = getMeta.data.info.name || "",
meta.videos = videos
}else if(type === "movie"){
let imdbRating = getMeta.data.info.rating || ""
meta.imdbRating = imdbRating
}else if(type === "tv"){
let metaTV = []
getMeta.data.forEach(i => {
if(Number(i.stream_id) === Number(streamID)){
let id= obj.idPrefix + i.stream_id
let name = i.name || ""
let background= "https://www.stremio.com/website/wallpapers/stremio-wallpaper-5.jpg"//i.stream_icon,
let logo = i.stream_icon || null
metaTV.push({id,name,type,background,logo})
// console.log(metaTV)
}
});
// return metaTV
// console.log(metaTV)
return metaTV[0]
}
// console.log(meta)
return meta
}
module.exports={getUserData,getManifest,getCatalog,getMeta}