-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.js
More file actions
37 lines (33 loc) · 1.41 KB
/
parser.js
File metadata and controls
37 lines (33 loc) · 1.41 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
// Unused code, Although it is a good idea to keep it for future reference.
import { get } from 'axios';
import { load } from 'cheerio';
function parseScriptTags(url) {
return new Promise((resolve, reject) => {
get(url)
.then(response => {
const $ = load(response.data);
const scriptTags = $('script');
let found = false; // Flag to indicate if a URL was found
scriptTags.each((index, element) => {
const scriptContent = $(element).html();
if (scriptContent && scriptContent.includes('sources:')) {
const regex = /file:"(.*?)"/;
const match = scriptContent.match(regex);
if (match) {
found = true;
const url = match[1];
resolve(url); // Resolve the Promise with the URL
return false; // Break the loop after finding the URL
}
}
});
if (!found) {
reject(new Error('Try another video source option.'));
}
})
.catch(error => {
reject(new Error(`Failed to fetch or parse content: ${error.message}`));
});
});
}
export default parseScriptTags;