[Skip to content](https://github.com/tapframe/NuvioStreamsAddon/blob/master/providers/vidsrcextractor.js#start-of-content)

You signed in with another tab or window. [Reload](https://github.com/tapframe/NuvioStreamsAddon/blob/master/providers/vidsrcextractor.js) to refresh your session.You signed out in another tab or window. [Reload](https://github.com/tapframe/NuvioStreamsAddon/blob/master/providers/vidsrcextractor.js) to refresh your session.You switched accounts on another tab or window. [Reload](https://github.com/tapframe/NuvioStreamsAddon/blob/master/providers/vidsrcextractor.js) to refresh your session.Dismiss alert

{{ message }}

This repository was archived by the owner on Apr 21, 2026. It is now read-only.


[tapframe](https://github.com/tapframe)/ **[NuvioStreamsAddon](https://github.com/tapframe/NuvioStreamsAddon)** Public archive

- [Notifications](https://github.com/login?return_to=%2Ftapframe%2FNuvioStreamsAddon) You must be signed in to change notification settings
- [Fork\\
197](https://github.com/login?return_to=%2Ftapframe%2FNuvioStreamsAddon)
- [Star\\
326](https://github.com/login?return_to=%2Ftapframe%2FNuvioStreamsAddon)


## Collapse file tree

## Files

master

Search this repository(forward slash)` forward slash/`

/

# vidsrcextractor.js

Copy path

Blame

More file actions

Blame

More file actions

## Latest commit

[![tapframe](https://avatars.githubusercontent.com/u/85391825?v=4&size=40)](https://github.com/tapframe)[tapframe](https://github.com/tapframe/NuvioStreamsAddon/commits?author=tapframe)

[added proxy support to vidsrc](https://github.com/tapframe/NuvioStreamsAddon/commit/ea993fad2776fbbc3e653d54ffc9126f576cf906)

success

last yearJun 7, 2025

[ea993fa](https://github.com/tapframe/NuvioStreamsAddon/commit/ea993fad2776fbbc3e653d54ffc9126f576cf906) · last yearJun 7, 2025

## History

[History](https://github.com/tapframe/NuvioStreamsAddon/commits/master/providers/vidsrcextractor.js)

Open commit details

[View commit history for this file.](https://github.com/tapframe/NuvioStreamsAddon/commits/master/providers/vidsrcextractor.js) History

418 lines (398 loc) · 18.9 KB

/

# vidsrcextractor.js

Copy path

Top

## File metadata and controls

- Code

- Blame


418 lines (398 loc) · 18.9 KB

[Raw](https://github.com/tapframe/NuvioStreamsAddon/raw/refs/heads/master/providers/vidsrcextractor.js)

Copy raw file

Download raw file

You must be signed in to make or propose changes

More edit options

Open symbols panel

Edit and raw actions

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

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

#!/usr/bin/env node

constcheerio=require('cheerio');

// \-\-\- Constants ---

constVIDSRC\_PROXY\_URL=process.env.VIDSRC\_PROXY\_URL;

letBASEDOM="https://cloudnestra.com";// This can be updated by serversLoad

constSOURCE\_URL="https://vidsrc.xyz/embed";

// \-\-\- Helper: Conditional Proxied Fetch ---

// This function wraps the native fetch. If VIDSRC\_PROXY\_URL is set in the environment,

// it routes requests through the proxy. Otherwise, it makes a direct request.

asyncfunctionfetchWrapper(url,options){

if(VIDSRC\_PROXY\_URL){

constproxiedUrl=\`${VIDSRC\_PROXY\_URL}${encodeURIComponent(url)}\`;

console.log(\`\[VidSrc Proxy\] Fetching: ${url} via proxy\`);

// Note: The proxy will handle the actual fetching, so we send the request to the proxy URL.

// We pass the original headers in the options, the proxy should forward them.

returnfetch(proxiedUrl,options);

}

// If no proxy is set, fetch directly.

console.log(\`\[VidSrc Direct\] Fetching: ${url}\`);

returnfetch(url,options);

}

// \-\-\- Helper Functions (copied and adapted from src/extractor.ts) ---

asyncfunctionserversLoad(html){

const$=cheerio.load(html);

constservers=\[\];

consttitle=$("title").text()??"";

constbaseFrameSrc=$("iframe").attr("src")??"";

if(baseFrameSrc){

try{

constfullUrl=baseFrameSrc.startsWith("//") ? "https:"+baseFrameSrc : baseFrameSrc;

BASEDOM=newURL(fullUrl).origin;

}

catch(e){

console.warn(\`(Attempt 1) Failed to parse base URL from iframe src: ${baseFrameSrc} using new URL(), error: ${e.message}\`);

// Attempt 2: Regex fallback for origin

constoriginMatch=(baseFrameSrc.startsWith("//") ? "https:"+baseFrameSrc : baseFrameSrc).match(/^(https?:\\/\\/\[^/\]+)/);

if(originMatch&&originMatch\[1\]){

BASEDOM=originMatch\[1\];

console.log(\`(Attempt 2) Successfully extracted origin using regex: ${BASEDOM}\`);

}else{

console.error(\`(Attempt 2) Failed to extract origin using regex from: ${baseFrameSrc}. Using default: ${BASEDOM}\`);

// Keep the default BASEDOM = "https://cloudnestra.com" if all fails

}

}

}

$(".serversList .server").each((index,element)=>{

constserver=$(element);

servers.push({

name: server.text().trim(),

dataHash: server.attr("data-hash")??null,

});

});

return{

servers: servers,

title: title,

};

}

asyncfunctionparseMasterM3U8(m3u8Content,masterM3U8Url){

constlines=m3u8Content.split('\\n').map(line=>line.trim());

conststreams=\[\];

for(leti=0;i<lines.length;i++){

if(lines\[i\].startsWith("#EXT-X-STREAM-INF:")){

constinfoLine=lines\[i\];

letquality="unknown";

constresolutionMatch=infoLine.match(/RESOLUTION=(\\d+x\\d+)/);

if(resolutionMatch&&resolutionMatch\[1\]){

quality=resolutionMatch\[1\];

}

else{

constbandwidthMatch=infoLine.match(/BANDWIDTH=(\\d+)/);

if(bandwidthMatch&&bandwidthMatch\[1\]){

quality=\`${Math.round(parseInt(bandwidthMatch\[1\])/1000)}kbps\`;

}

}

if(i+1<lines.length&&lines\[i+1\]&&!lines\[i+1\].startsWith("#")){

conststreamUrlPart=lines\[i+1\];

try{

constfullStreamUrl=newURL(streamUrlPart,masterM3U8Url).href;

streams.push({quality: quality,url: fullStreamUrl});

}

catch(e){

console.error(\`Error constructing URL for stream part: ${streamUrlPart} with base: ${masterM3U8Url}\`,e);

streams.push({quality: quality,url: streamUrlPart});// Store partial URL as a fallback

}

i++;

}

}

}

// Sort streams by quality (highest first)

streams.sort((a,b)=>{

// Extract resolution height from quality (e.g., "1280x720" -> 720)

constgetHeight=(quality)=>{

constmatch=quality.match(/(\\d+)x(\\d+)/);

returnmatch ? parseInt(match\[2\],10) : 0;

};

constheightA=getHeight(a.quality);

constheightB=getHeight(b.quality);

// Higher resolution comes first

returnheightB-heightA;

});

returnstreams;

}

asyncfunctionPRORCPhandler(prorcp){

try{

constprorcpUrl=\`${BASEDOM}/prorcp/${prorcp}\`;

constprorcpFetch=awaitfetchWrapper(prorcpUrl,{

headers: {

"accept": "\*/\*","accept-language": "en-US,en;q=0.9","priority": "u=1",

"sec-ch-ua": "\\"Chromium\\";v=\\"128\\", \\"Not;A=Brand\\";v=\\"24\\", \\"Google Chrome\\";v=\\"128\\"",

"sec-ch-ua-mobile": "?0","sec-ch-ua-platform": "\\"Windows\\"",

"sec-fetch-dest": "script","sec-fetch-mode": "no-cors","sec-fetch-site": "same-origin",

'Sec-Fetch-Dest': 'iframe',"Referer": \`${BASEDOM}/\`,"Referrer-Policy": "origin",

},

timeout: 10000

});

if(!prorcpFetch.ok){

console.error(\`Failed to fetch prorcp: ${prorcpUrl}, status: ${prorcpFetch.status}\`);

returnnull;

}

constprorcpResponse=awaitprorcpFetch.text();

constregex=/file:\\s\*'(\[^'\]\*)'/gm;

constmatch=regex.exec(prorcpResponse);

if(match&&match\[1\]){

constmasterM3U8Url=match\[1\];

constm3u8FileFetch=awaitfetchWrapper(masterM3U8Url,{

headers: {"Referer": prorcpUrl,"Accept": "\*/\*"},

timeout: 10000

});

if(!m3u8FileFetch.ok){

console.error(\`Failed to fetch master M3U8: ${masterM3U8Url}, status: ${m3u8FileFetch.status}\`);

returnnull;

}

constm3u8Content=awaitm3u8FileFetch.text();

returnparseMasterM3U8(m3u8Content,masterM3U8Url);

}

console.warn("No master M3U8 URL found in prorcp response for:",prorcpUrl);

returnnull;

}

catch(error){

console.error(\`Error in PRORCPhandler for ${BASEDOM}/prorcp/${prorcp}:\`,error);

returnnull;

}

}

asyncfunctionSRCRCPhandler(srcrcpPath,refererForSrcrcp){

try{

constsrcrcpUrl=BASEDOM+srcrcpPath;

console.log(\`\[VidSrc - SRCRCP\] Fetching: ${srcrcpUrl} (Referer: ${refererForSrcrcp})\`);

constresponse=awaitfetchWrapper(srcrcpUrl,{

headers: {

"accept": "\*/\*",

"accept-language": "en-US,en;q=0.9",

"sec-ch-ua": "\\"Chromium\\";v=\\"128\\", \\"Not;A=Brand\\";v=\\"24\\", \\"Google Chrome\\";v=\\"128\\"",

"sec-ch-ua-mobile": "?0",

"sec-ch-ua-platform": "\\"Windows\\"",

"sec-fetch-dest": "iframe",

"sec-fetch-mode": "navigate",

"sec-fetch-site": "same-origin",// This might need to be 'cross-site' if BASEDOM's origin differs from srcrcp link's origin

"Referer": refererForSrcrcp,

"Referrer-Policy": "origin",

},

timeout: 10000

});

if(!response.ok){

console.error(\`\[VidSrc - SRCRCP\] Failed to fetch ${srcrcpUrl}, status: ${response.status}\`);

returnnull;

}

constresponseText=awaitresponse.text();

console.log(\`\[VidSrc - SRCRCP\] Response from ${srcrcpUrl} (first 500 chars): ${responseText.substring(0,500)}\`);

// Attempt 1: Check for "file: '...'" like in PRORCP

constfileRegex=/file:\\s\*'(\[^'\]\*)'/gm;

constfileMatch=fileRegex.exec(responseText);

if(fileMatch&&fileMatch\[1\]){

constmasterM3U8Url=fileMatch\[1\];

console.log(\`\[VidSrc - SRCRCP\] Found M3U8 URL (via fileMatch): ${masterM3U8Url}\`);

constm3u8FileFetch=awaitfetchWrapper(masterM3U8Url,{

headers: {"Referer": srcrcpUrl,"Accept": "\*/\*"},

timeout: 10000

});

if(!m3u8FileFetch.ok){

console.error(\`\[VidSrc - SRCRCP\] Failed to fetch master M3U8: ${masterM3U8Url}, status: ${m3u8FileFetch.status}\`);

returnnull;

}

constm3u8Content=awaitm3u8FileFetch.text();

returnparseMasterM3U8(m3u8Content,masterM3U8Url);

}

// Attempt 2: Check if the responseText itself is an M3U8 playlist

if(responseText.trim().startsWith("#EXTM3U")){

console.log(\`\[VidSrc - SRCRCP\] Response from ${srcrcpUrl} appears to be an M3U8 playlist directly.\`);

returnparseMasterM3U8(responseText,srcrcpUrl);

}

// Attempt 3: Look for sources = \[...\] or sources: \[...\] in script tags or in JSON-like structures

const$=cheerio.load(responseText);

letsourcesFound=null;

$('script').each((i,script)=>{

constscriptContent=$(script).html();

if(scriptContent){

// Regex for various ways sources might be defined

constsourcesRegexes=\[\
\
/sources\\s\*\[:=\]\\s\*(\\\[\[^\\\]\]\*\\{(?:\\s\*\|.\*?)file\\s\*:\\s\*\['"\](\[^'"\]+)\['"\](?:\\s\*\|.\*?)\\}\[^\\\]\]\*\\\])/si,// extracts the URL from sources: \[{file: "URL"}\]

/playerInstance\\.setup\\s\*\\(\\s\*\\{\\s\*sources\\s\*:\\s\*(\\\[\[^\\\]\]\*\\{(?:\\s\*\|.\*?)file\\s\*:\\s\*\['"\](\[^'"\]+)\['"\](?:\\s\*\|.\*?)\\}\[^\\\]\]\*\\\])/si,// for playerInstance.setup({sources: \[{file: "URL"}\]})

/file\\s\*:\\s\*\['"\](\[^'"\]+\\.m3u8\[^'"\]\*)\['"\]/i,// Direct M3U8 link in a var or object e.g. file: "URL.m3u8"

/src\\s\*:\\s\*\['"\](\[^'"\]+\\.m3u8\[^'"\]\*)\['"\]/i,// Direct M3U8 link e.g. src: "URL.m3u8"

/loadSource\\(\['"\](\[^'"\]+\\.m3u8\[^'"\]\*)\['"\]\\)/i,// For .loadSource("URL.m3u8")

/new\\s+Player\\(\[^)\]\*\\{\\s\*src\\s\*:\\s\*\['"\](\[^'"\]+)\['"\]\\s\*\\}\\s\*\\)/i// For new Player({src: "URL"})

\];

for(constregexofsourcesRegexes){

constsourcesMatch=scriptContent.match(regex);

// For regexes that capture a JSON array-like structure in group 1 and then the URL in group 2 (first two regexes)

if(regex.source.includes('file\\\s\*:\\\s\*\[\\'\\"\](\[\\'\\"\]+)\[\\'\\"\]')){// Heuristic to identify these complex regexes

if(sourcesMatch&&sourcesMatch\[2\]){// URL is in group 2

console.log(\`\[VidSrc - SRCRCP\] Found M3U8 URL (script complex): ${sourcesMatch\[2\]}\`);

sourcesFound=\[{quality: 'default',url: sourcesMatch\[2\]}\];

returnfalse;// break cheerio loop

}

}

// For simpler regexes where URL is in group 1

elseif(sourcesMatch&&sourcesMatch\[1\]){

console.log(\`\[VidSrc - SRCRCP\] Found M3U8 URL (script simple): ${sourcesMatch\[1\]}\`);

sourcesFound=\[{quality: 'default',url: sourcesMatch\[1\]}\];

returnfalse;// break cheerio loop

}

}

// Fallback: Look for any absolute .m3u8 URL within the script tag

if(!sourcesFound){

constm3u8GenericMatch=scriptContent.match(/\['"\](https?:\\/\\/\[^'"\\s\]+\\.m3u8\[^'"\\s\]\*)\['"\]/i);

if(m3u8GenericMatch&&m3u8GenericMatch\[1\]){

console.log(\`\[VidSrc - SRCRCP\] Found M3U8 URL (script generic fallback): ${m3u8GenericMatch\[1\]}\`);

sourcesFound=\[{quality: 'default',url: m3u8GenericMatch\[1\]}\];

returnfalse;// break cheerio loop

}

}

}

});

if(sourcesFound&&sourcesFound.length>0){

// Process the first valid M3U8 URL found, or return direct links

constm3u8Source=sourcesFound.find(s=>s.url&&s.url.includes('.m3u8'));

if(m3u8Source){

console.log(\`\[VidSrc - SRCRCP\] First M3U8 source from script: ${m3u8Source.url}\`);

// Ensure URL is absolute

constabsoluteM3u8Url=m3u8Source.url.startsWith('http') ? m3u8Source.url : newURL(m3u8Source.url,srcrcpUrl).href;

constm3u8FileFetch=awaitfetchWrapper(absoluteM3u8Url,{

headers: {"Referer": srcrcpUrl,"Accept": "\*/\*"},

timeout: 10000

});

if(!m3u8FileFetch.ok){

console.error(\`\[VidSrc - SRCRCP\] Failed to fetch M3U8 from script source: ${absoluteM3u8Url}, status: ${m3u8FileFetch.status}\`);

returnnull;

}

constm3u8Content=awaitm3u8FileFetch.text();

returnparseMasterM3U8(m3u8Content,absoluteM3u8Url);

}else{

// Assuming direct links if no .m3u8 found in the sources array

console.log(\`\[VidSrc - SRCRCP\] Assuming direct links from script sources:\`,sourcesFound);

returnsourcesFound.map(s=>({

quality: s.quality\|\|s.label\|\|'auto',

url: s.url.startsWith('http') ? s.url : newURL(s.url,srcrcpUrl).href

}));

}

}

console.warn(\`\[VidSrc - SRCRCP\] No stream extraction method succeeded for ${srcrcpUrl}\`);

returnnull;

}catch(error){

console.error(\`\[VidSrc - SRCRCP\] Error in SRCRCPhandler for ${srcrcpPath}:\`,error);

returnnull;

}

}

asyncfunctionrcpGrabber(html){

constregex=/src:\\s\*'(\[^'\]\*)'/;

constmatch=html.match(regex);

if(!match\|\|!match\[1\])

returnnull;

return{metadata: {image: ""},data: match\[1\]};

}

functiongetObject(id){

constarr=id.split(':');

return{id: arr\[0\],season: arr\[1\],episode: arr\[2\]};

}

functiongetUrl(id,type){

if(type==="movie"){

return\`${SOURCE\_URL}/movie/${id}\`;

}

else{

constobj=getObject(id);

return\`${SOURCE\_URL}/tv/${obj.id}/${obj.season}-${obj.episode}\`;

}

}

asyncfunctiongetStreamContent(id,type){

consturl=getUrl(id,type);

constembedRes=awaitfetchWrapper(url,{headers: {"Referer": SOURCE\_URL}});

if(!embedRes.ok){

console.error(\`Failed to fetch embed page ${url}: ${embedRes.status}\`);

return\[\];

}

constembedResp=awaitembedRes.text();

const{ servers, title }=awaitserversLoad(embedResp);

constapiResponse=\[\];

// MODIFIED: Process servers in parallel

constserverPromises=servers.map(async(server)=>{

if(!server.dataHash)returnnull;// Skip servers without dataHash

try{

constrcpUrl=\`${BASEDOM}/rcp/${server.dataHash}\`;

constrcpRes=awaitfetchWrapper(rcpUrl,{

headers: {'Sec-Fetch-Dest': 'iframe',"Referer": url}

});

if(!rcpRes.ok){

console.warn(\`RCP fetch failed for server ${server.name}: ${rcpRes.status}\`);

returnnull;// Failed to fetch RCP

}

constrcpHtml=awaitrcpRes.text();

constrcpData=awaitrcpGrabber(rcpHtml);

if(!rcpData\|\|!rcpData.data){

console.warn(\`Skipping server ${server.name} due to missing rcp data.\`);

returnnull;// Missing RCP data

}

letstreamDetails=null;

if(rcpData.data.startsWith("/prorcp/")){

streamDetails=awaitPRORCPhandler(rcpData.data.replace("/prorcp/",""));

}elseif(rcpData.data.startsWith("/srcrcp/")){

if(server.name==="Superembed"\|\|server.name==="2Embed"){

console.warn(\`\[VidSrc\] Skipping SRCRCP for known problematic server: ${server.name}\`);

returnnull;

}

streamDetails=awaitSRCRCPhandler(rcpData.data,rcpUrl);// Pass rcpUrl as referer

}else{

console.warn(\`Unhandled rcp data type for server ${server.name}: ${rcpData.data.substring(0,50)}\`);

returnnull;// Unhandled type

}

if(streamDetails&&streamDetails.length>0){

return{

name: title,

image: rcpData.metadata.image,

mediaId: id,

streams: streamDetails,

referer: BASEDOM,

};

}else{

console.warn(\`No stream details from handler for server ${server.name} (${rcpData.data})\`);

returnnull;// No stream details found by the handler

}

}catch(e){

console.error(\`Error processing server ${server.name} (${server.dataHash}):\`,e);

returnnull;// Error during server processing

}

});

constresults=awaitPromise.all(serverPromises);

// Filter out null results (failed servers or no streams) and add valid results to apiResponse

results.forEach(result=>{

if(result){

apiResponse.push(result);

}

});

// END MODIFICATION

returnapiResponse;

}

// \-\-\- Main execution logic (conditional) ---

asyncfunctionmain(){

constargs=process.argv.slice(2);

if(args.length<2){

console.error("Usage: node vidsrcextractor.js <id> <type>");

console.error("Example (movie): node vidsrcextractor.js tt0111161 movie");

console.error("Example (series): node vidsrcextractor.js tt0944947:1:1 series");// Game of Thrones S1E1

process.exit(1);

}

constid=args\[0\];

consttype=args\[1\];

if(type!=="movie"&&type!=="series"){

console.error("Invalid type. Must be 'movie' or 'series'.");

process.exit(1);

}

// Basic validation for series ID format

if(type==="series"&&id.split(':').length<3){

console.error("Invalid series ID format. Expected 'ttID:season:episode' (e.g., tt0944947:1:1).");

process.exit(1);

}

console.log(\`Fetching streams for ID: ${id}, Type: ${type}\`);

try{

constresults=awaitgetStreamContent(id,type);

if(results&&results.length>0){

console.log("Extracted Data:");

console.log(JSON.stringify(results,null,2));

}

else{

console.log("No streams found or an error occurred.");

}

}

catch(error){

console.error("Error during extraction process:",error);

}

}

// Export the function for use in other modules

module.exports={ getStreamContent };

// Run main only if the script is executed directly

if(require.main===module){

main().catch(error=>{

console.error("Unhandled error in main execution:",error);

process.exit(1);

});

}

You can’t perform that action at this time.