-
Notifications
You must be signed in to change notification settings - Fork 4
/
Prompt.js
146 lines (137 loc) · 4.43 KB
/
Prompt.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
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
javascript:(function() {
var videoSourceCode = document.documentElement.innerHTML;
var urlRegex = /https?:\/\/[^\s/$.?#].[^\s]*videoplayback(?:\?|%3F)[^'"]+/g;
var matches = videoSourceCode.match(urlRegex);
var videoUrls = [];
if (matches) {
for (var i = 0; i < matches.length; i++) {
videoUrls.push(matches[i]);
}
if (videoUrls.length > 0) {
// Sort the video URLs by quality
videoUrls.sort(function(a, b) {
var itagA = getItagFromUrl(a);
var itagB = getItagFromUrl(b);
return compareItags(itagA, itagB);
});
var formatOptions = '';
for (var j = 0; j < videoUrls.length; j++) {
var formattedUrl = videoUrls[j].replace(/\\u0026/g, '&');
var itag = getItagFromUrl(formattedUrl);
var quality = getQualityFromItag(itag);
formatOptions += (j + 1) + '. ' + quality + ' (' + itag + ')' + '\n';
}
var selectedFormat = prompt('Select the desired video format by entering its corresponding number:\n\n' + formatOptions);
if (selectedFormat !== null && selectedFormat !== '') {
var chosenUrl = videoUrls[selectedFormat - 1].replace(/\\u0026/g, '&');
window.open(chosenUrl);
}
} else {
alert('No video URLs found in the source code.');
}
} else {
alert('No matches found in the source code.');
}
})();
function getItagFromUrl(url) {
url = decodeURIComponent(url);
var itagRegex = /itag=(\d+)/;
var match = url.match(itagRegex);
if (match && match.length > 1) {
return match[1];
}
return '';
}
function compareItags(itagA, itagB) {
var qualityA = getQualityFromItag(itagA);
var qualityB = getQualityFromItag(itagB);
return qualityA.localeCompare(qualityB);
}
function getQualityFromItag(itag) {
switch (itag) {
case '5':
return 'FLV 240p';
case '6':
return 'FLV 270p';
case '17':
return '3GP 144p';
case '18':
return 'MP4 360p';
case '22':
return 'MP4 720p';
case '34':
return 'FLV 360p';
case '35':
return 'FLV 480p';
case '36':
return '3GP 180p';
case '37':
return 'MP4 1080p';
case '38':
return 'MP4 3072p';
case '43':
return 'WebM 360p';
case '44':
return 'WebM 480p';
case '45':
return 'WebM 720p';
case '46':
return 'WebM 1080p';
case '82':
return 'MP4 360p (3D)';
case '83':
return 'MP4 480p (3D)';
case '84':
return 'MP4 720p (3D)';
case '85':
return 'MP4 1080p (3D)';
case '92':
return 'HLS 240p (3D)';
case '93':
return 'HLS 360p (3D)';
case '94':
return 'HLS 480p (3D)';
case '95':
return 'HLS 720p (3D)';
case '96':
return 'HLS 1080p (3D)';
case '133':
return 'MP4 240p Video Only';
case '134':
return 'MP4 360p Video Only';
case '135':
return 'MP4 480p Video Only';
case '136':
return 'MP4 720p Video Only';
case '137':
return 'MP4 1080p Video Only';
case '140':
return 'M4A Audio 128k';
case '160':
return 'MP4 144p Video Only';
case '242':
return 'WebM 240p Video Only';
case '243':
return 'WebM 360p Video Only';
case '244':
return 'WebM 480p Video Only';
case '247':
return 'WebM 720p Video Only';
case '248':
return 'WebM 1080p Video Only';
case '249':
return 'WebM Audio 50k';
case '250':
return 'WebM Audio 70k';
case '251':
return 'WebM Audio 160k';
case '271':
return 'WebM 1440p Video Only';
case '278':
return 'WebM 144p Video Only';
case '313':
return 'WebM 2160p Video Only';
default:
return 'Unknown';
}
}