-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube.js.old
726 lines (682 loc) · 26.2 KB
/
youtube.js.old
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
// ==UserScript==
// @include https://www.youtube.com/*
// @name
// @author Bga
// @version 0.1
// @description play video via WMP plugin. Plugin here http://www.chip.de/downloads/Windows-Media-Player-Firefox-Plug-in_25565274.html
// ==/UserScript==
;(function(undefined) {
var volume = 0
if(location.pathname.match(/^\/embed\//)) {
location.replace("https://www.youtube.com/watch?v=" + location.pathname.slice(7))
}
//# that option show related videos
else if(0 && location.search.match(/(^|&|\?)nofeather=True(&|$)/) == null) {
location.replace(location + ((location.search == "") ? "?" : "&") + "nofeather=True")
}
opera.addEventListener('BeforeExternalScript', function(js) {
// opera.postError(js.element)
js.preventDefault()
}, false)
window.yt = { }
window.__ytRIL = function() {
}
opera.addEventListener('BeforeScript', function(js) {
// opera.postError(js.element)
js.preventDefault()
if(js.element.text.indexOf("\\u003cembed") < 0 && js.element.text.indexOf("yt.playerConfig =") < 0) {
// opera.postError("blocked")
}
}, false)
!(function(global) {
var waitCommon = function(fn) {
if(global.Bga) {
fn()
}
else {
setTimeout(function() {
waitCommon(fn)
}, 0)
}
}
//# allows to use WMP browser plugin for viewing videos
waitCommon(function() {
with(Bga) {
setProtoExpando()
document.documentElement.removeInlineEvents()
var log = (1 ? logRaw : logNull)
//# fix volume
0 && setTimeout(function() {
try {
movie_player.setVolume(8)
}
catch(err) {
setTimeout(arguments.callee, 100)
}
}, 0)
onDOMReady(function() {
var queryParamMap = parseQueryString(location.search.slice(1))
//# lowercase title
if(1) {
document.title = document.title.replace(/(^|\s)([\s\S]+?)(?=\s|$)/g, function(m, pred, word, post) {
return pred + ((word.toUpperCase() == word) ? word.toLowerCase() : word)
})
}
//# load more button
if(document.getElementsByClassName("load-more-button")[0] != null) (function() {
var bindEvent = function() {
var button = document.getElementsByClassName("load-more-button")[0]
button.setAttribute("onclick", null)
var doLoadMore = function(targetNode) {
var ajaxAppendId = targetNode.getAttribute("data-uix-load-more-target-id")
var ajaxUrl = targetNode.getAttribute("data-uix-load-more-href")
fetch(ajaxUrl).then(function(response) {
if(response.ok == false) {
}
else {
var json = response.body.json()
var div = document.createElement("div")
div.innerHTML = json.load_more_widget_html
document.getElementById(ajaxAppendId).insertAdjacentHTML("beforeend", json.content_html)
var newHref = null; try { newHref = div.getElementsByClassName("load-more-button")[0].getAttribute("data-uix-load-more-href") } catch(err) { newHref = null }
if(0) log(targetNode.getAttribute("data-uix-load-more-href"), newHref)
if(newHref != null && targetNode.getAttribute("data-uix-load-more-href") != newHref) {
targetNode.setAttribute("data-uix-load-more-href", newHref)
}
else {
targetNode.style.display = "none"
}
}
})
}
button.addEventListener("click", function(ev) {
doLoadMore(ev.target)
return false
}, false)
document.body.appendChild(de("<a href=# accesskey=L title='Load more'>")).addEventListener("click", function(ev) {
doLoadMore(document.getElementsByClassName("load-more-button")[0])
ev.preventDefault()
return false
}, false)
button = null
}
bindEvent()
})()
//# next video in playlist
if(queryParamMap["list"] != null) (function() {
var getVideoId = function(href) {
return parseQueryString(href.split("?")[1])["v"]
}
var currentVideoId = queryParamMap["v"]
assert("vLxefatea1Y" == getVideoId("https://www.youtube.com/watch?v=vLxefatea1Y&list=PL0QrZvg7QIgpoLdNFnEePRrU-YJfr9Be7&index=66&t=0s&nofeather=True"))
var playListOl = document.getElementById("playlist-autoscroll-list")
//# lazy parsing
var hrefs = []; playListOl.getElementsByTagName("li").each(function(li) {
var href = li.getElementsByClassName("playlist-video")[0].href
hrefs.push(href)
if(3 <= hrefs.length && getVideoId(hrefs[hrefs.length - 2]) == currentVideoId) {
return false
}
})
var nextHref = hrefs[hrefs.length - 1]
var prevHref = hrefs[hrefs.length - 3]
document.body.appendChild(de("".concat("<a accesskey=p href='", prevHref, "' title=Prev></a>")))
document.head.prependChild(de("<link rel='prev' href='" + prevHref + "'/>"))
document.body.appendChild(de("".concat("<a accesskey=n href='", nextHref, "' title=Next></a>")))
document.head.prependChild(de("<link rel='next' href='" + nextHref + "'/>"))
})()
//# play video using WMPlayer plugin
if(location.search.match("v=([a-zA-Z0-9-_]+)") != null) (function() {
// var player = document.getElementById("default-language-message") || document.getElementById("player-api-legacy") || document.getElementById("player")
var player = document.getElementById("player-api")
// var player = document.getElementById("placeholder-player").firstElement
player.innerHTML = "<div /><div />"
var di = function(options) {
//log(options.title + "!")
}
var showMediaPlayer = function(url, w, h) {
//# ui height
h += 72
//# support video?
if(0 && de("<video />").src != null) {
player.lastChild.innerHTML = "".concat('<video id=bgaPlayer tabIndex=-1 src="', url, '" controls="true">')
setTimeout(function() {
var bgaPlayer = player.lastChild.firstChild
bgaPlayer.style.minWidth = "".concat(w, "px")
bgaPlayer.volume = localStorage.bgaPlayerVolume || 0.2
bgaPlayer.play()
bgaPlayer.focus()
bgaPlayer.onclick = function() {
if(bgaPlayer.paused) {
bgaPlayer.play()
}
else {
bgaPlayer.pause()
}
}
bgaPlayer.onkeydown = function(e) {
if(e.shiftKey == false && e.ctrlKey == false && e.altKey == false && e.keyCode == 38) {
localStorage.bgaPlayerVolume = bgaPlayer.volume = Math.min(1, bgaPlayer.volume + 0.05)
e.preventDefault()
}
else if(e.shiftKey == false && e.ctrlKey == false && e.altKey == false && e.keyCode == 40) {
localStorage.bgaPlayerVolume = bgaPlayer.volume = Math.max(0, bgaPlayer.volume - 0.05)
e.preventDefault()
}
else {
}
}
}, 100)
}
else {
//# player.lastChild.innerHTML = "".concat('<embed src="', url, '" autostart="true" showcontrols="true" showstatusbar="1" type="application/x-mplayer2" bgcolor="white" width="', w, 'px" height="', h, 'px" volume="', volume, '">')
player.lastChild.innerHTML = "".concat('<embed src="', url, '" autostart="true" showcontrols="true" showstatusbar="1" type="application/x-mplayer2" bgcolor="white" style="width: ', w, 'px; height: ', h, 'px" volume="', volume, '">')
if(0) {
var bgaPlayer = player.lastChild.lastChild
player.tabIndex=-1
player.onkeydown = function(e) {
log("keydown")
if(0) {
}
else if(e.shiftKey == false && e.ctrlKey == false && e.altKey == false && e.keyCode == 32) {
bgaPlayer.controls.pause()
e.preventDefault()
}
else if(e.shiftKey == false && e.ctrlKey == false && e.altKey == false && e.keyCode == 38) {
localStorage.bgaPlayerVolume = bgaPlayer.volume = Math.min(1, bgaPlayer.volume + 0.05)
e.preventDefault()
}
else if(e.shiftKey == false && e.ctrlKey == false && e.altKey == false && e.keyCode == 40) {
localStorage.bgaPlayerVolume = bgaPlayer.volume = Math.max(0, bgaPlayer.volume - 0.05)
e.preventDefault()
}
else {
}
}
}
}
}
//# [keepvid.com]
//# env emulation
var ap = function(obj) {
var url = obj.params.u
var onOk = obj.callback
var xhr = new XMLHttpRequest()
xhr.open("GET", url, true)
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(200 <= xhr.status && xhr.status < 300) {
onOk({
headers: "",
body: xhr.responseText
})
}
else {
onOk(null)
}
}
}
xhr.send(null)
}
var dl = function(obj) {
var url = obj.url
var type = obj.type
var quality = obj.quality
var title = obj.title
var t = "".concat(type, "-", quality).replace(/<\/?.*?>/g, "")
var link = de("".concat('<a href="', url, '" title="', t, '">', t, '</a> '))
link.childNodes[0].onclick = function() {
var w
var h
var qm = quality.match(/(\d+)p$/)
log(qm + "!")
if(qm) {
h = parseInt(+qm[1])
w = h / 3 * 4
}
else {
w = 640
h = 480
}
log(w, h)
showMediaPlayer(url, w, h)
return false
}
link.childNodes[0].setAttribute("accesskey", (({
"MP4": {
"(Max 480p)": "4",
"720p": "7"
}
})[obj.type] || { })[obj.quality] || null)
if(obj.type == "MP4" && (obj.quality == "(Max 480p)" || obj.quality == "720p")) {
player.firstChild.appendChild(link)
}
else {
}
log(url, type, quality, title)
}
; location.search.match("v=([a-zA-Z0-9-_]+)") && (function(m) {
log("here")
var ua
//function: convert seconds to 1:11 readable format
function duration(secs){
hours = parseInt(secs / 3600) % 24;
minutes = parseInt(secs / 60) % 60;
seconds = secs % 60;
return (hours < 1 ? "" : hours+":")+((minutes < 10 && hours > 0) ? "0" + minutes : minutes)+":"+(seconds < 10 ? "0" + seconds : seconds);
}
var vid = m.match("v=([a-zA-Z0-9-_]+)")[1];
var files;
function swap16230(p1, p2) {
var l3 = p1[0];
var l4c = p2 % p1.length;
var l4 = p1[l4c];
p1[0] = l4;
p1[p2] = l3;
return p1
}
function clone16230(p1, p2) {
return p1.slice(p2)
}
function reverse16230(p1) {
return p1.reverse()
}
function decipher(sig) {
var sigs = sig.split("");
sigs = swap16230(sigs, 25);
sigs = reverse16230(sigs);
sigs = clone16230(sigs, 1);
sigs = swap16230(sigs, 49);
sigs = swap16230(sigs, 52);
sig = sigs.join("");
return sig
}
ap({
params: {
"u": "https://www.youtube.com/get_video_info?video_id=" + vid + "&asv=3&el=detailpage&hl=en_US&sts=16230",
"ua": ua
},
"dispose": 1,
"callback": function(da) {
log("111 " + JSON.stringify(Bga.parseQueryString(da.body), null, " "))
var title = "";
var status = "";
/*
try {
title = unescape(da.body.match("title=([^&]+)")[1]).replace(/\+/g, " ")
} catch (e) {
log("Could not get title.")
}
*/
try {
status = da.body.match("status=([^&]+)")[1]
} catch (e) {
log("Could not get status parameter.")
}
if (status != "fail") {
/*
di({
title: title,
image: "https://i.ytimg.com/vi/" + vid + "/default.jpg",
url: "https://www.youtube.com/watch?v=" + vid,
domain: "youtube.com",
user: unescape(da.body.match("author=([^&]+)")[1].replace(/\+/g, " ")),
duration: duration(da.body.match("length_seconds=([^&]+)")[1])
});
*/
title = escape(title.replace(/\//g, "_").replace(/\"/g, ""));
var order = ("18,22,37,38,160,133,134,135,136,137,264,138,83,82,85,84,139,140,141,5,6,34,35,13,17,36,43,44,45,46,242,243,244,245,246,247,248,271,272,100,101,102,171,172").split(",");
files = {
"18": {
type: "MP4",
quality: "(Max 480p)"
},
"22": {
type: "MP4",
quality: "720p"
},
"37": {
type: "MP4",
quality: "1080p"
},
"160": {
type: "MP4",
quality: "144p (Video Only)"
},
"133": {
type: "MP4",
quality: "240p (Video Only)"
},
"134": {
type: "MP4",
quality: "360p (Video Only)"
},
"135": {
type: "MP4",
quality: "480p (Video Only)"
},
"136": {
type: "MP4",
quality: "720p (Video Only)"
},
"137": {
type: "MP4",
quality: "1080p (Video Only)"
},
"264": {
type: "MP4",
quality: "1440p (Video Only)"
},
"138": {
type: "MP4",
quality: "2160p (Video Only)"
},
"139": {
type: "M4A",
quality: "48 kbps (Audio Only)"
},
"140": {
type: "M4A",
quality: "128 kbps (Audio Only)"
},
"141": {
type: "M4A",
quality: "256 kbps (Audio Only)"
},
"38": {
type: "MP4",
quality: "2160p"
},
"83": {
type: "MP4",
quality: "[3D] - 240p"
},
"82": {
type: "MP4",
quality: "[3D] - 360p"
},
"85": {
type: "MP4",
quality: "[3D] - 520p"
},
"84": {
type: "MP4",
quality: "[3D] - 720p"
},
"5": {
type: "FLV",
quality: "240p"
},
"6": {
type: "FLV",
quality: "270p"
},
"34": {
type: "FLV",
quality: "360p"
},
"35": {
type: "FLV",
quality: "480p"
},
"13": {
type: "3GP",
quality: "144p"
},
"17": {
type: "3GP",
quality: "144p"
},
"36": {
type: "3GP",
quality: "240p"
},
"43": {
type: "WEBM",
quality: "360p"
},
"44": {
type: "WEBM",
quality: "480p"
},
"45": {
type: "WEBM",
quality: "720p"
},
"46": {
type: "WEBM",
quality: "1080p"
},
"242": {
type: "WEBM",
quality: "240p (Video Only)"
},
"243": {
type: "WEBM",
quality: "360p (Video Only)"
},
"244": {
type: "WEBM",
quality: "480p (Video Only)"
},
"245": {
type: "WEBM",
quality: "480p, 110 kbps (Video Only)"
},
"246": {
type: "WEBM",
quality: "480p, 210 kbps (Video Only)"
},
"247": {
type: "WEBM",
quality: "720p (Video Only)"
},
"248": {
type: "WEBM",
quality: "1080p (Video Only)"
},
"271": {
type: "WEBM",
quality: "1440p (Video Only)"
},
"272": {
type: "WEBM",
quality: "2160p (Video Only)"
},
"100": {
type: "WEBM",
quality: "[3D] - 360p"
},
"101": {
type: "WEBM",
quality: "[3D] - 360p"
},
"102": {
type: "WEBM",
quality: "[3D] - 720p"
},
"171": {
type: "WEBM",
quality: "128 kbps (Audio Only)"
},
"172": {
type: "WEBM",
quality: "192 kbps (Audio Only)"
}
};
var urlmap = unescape(da.body.match("url_encoded_fmt_stream_map=([^&]+)")[1]).split(/,/gi);
for (i = 0; i <= urlmap.length; i++) {
if (urlmap[i] == undefined) break;
var itag = parseInt(urlmap[i].match("itag=([^&]+)")[1]);
var url = unescape(urlmap[i].match("url=([^&]+)")[1]);
if (url != "") {
var sign = "";
try {
sign = urlmap[i].match("sig=([^&]+)")[1]
} catch (e) {
try {
sign = urlmap[i].match("&s=([^&]+)")[1]
} catch (e) {
try {
sign = urlmap[i].match("^s=([^&]+)")[1]
} catch (e) {}
}
}
try {
if (sign != "") {
log("Itag: " + itag);
log("Signature length: " + sign.length);
log("Signature: ");
log(sign);
sign = decipher(sign);
log("Deciphered Signature: ");
log(sign);
url += "&signature=" + sign
}
} catch (e) {}
url += "&title=" + decodeURIComponent(escape(title));
if (files[itag] != undefined) {
files[itag].url = url;
files[itag].rclick = 0
}
}
}
try {
log("getting adaptive links");
var adamap = unescape(da.body.match("adaptive_fmts=([^&]+)")[1]).split(/,/gi);
for (i = 0; i <= adamap.length; i++) {
if (adamap[i] == undefined) break;
var itag = parseInt(adamap[i].match("itag=([^&]+)")[1]);
var url = unescape(adamap[i].match("url=([^&]+)")[1]);
var size = "";
try {
size = adamap[i].match("clen=([^&]+)")[1]
} catch (e) {
log("failed size")
}
if (url != "") {
var sign = "";
try {
sign = adamap[i].match("sig=([^&]+)")[1]
} catch (e) {
try {
sign = adamap[i].match("&s=([^&]+)")[1]
} catch (e) {
try {
sign = adamap[i].match("^s=([^&]+)")[1]
} catch (e) {}
}
}
try {
if (sign != "") {
log("Itag: " + itag);
log("Signature length: " + sign.length);
log("Signature: ");
log(sign);
sign = decipher(sign);
log("Deciphered Signature: ");
log(sign);
url += "&signature=" + sign
}
} catch (e) {}
url += "&title=" + decodeURIComponent(escape(title));
if (files[itag] != undefined) {
files[itag].url = url;
if (!isNaN(size)) files[itag].size = size;
files[itag].rclick = 1
}
}
}
} catch (ex) {}
for (j = 0; j < order.length; j++) {
if (files[order[j]] != undefined) {
if (files[order[j]].url != undefined) {
dl({
url: files[order[j]].url,
title: unescape(title),
type: files[order[j]].type,
quality: files[order[j]].quality,
newtab: 0,
size: files[order[j]].size,
showsize: 1,
saveas: files[order[j]].rclick
})
}
}
}
var ttsurl = "";
try {
ttsurl = da.body.match("ttsurl=([^&]+)")[1]
} catch (e) {}
if (ttsurl != "") {
// dl({
// url: "http://keepvid.com/?url=" + escape("http://youtube.com/watch?v=" + vid) + "&mode=subs",
// type: "SRT",
// quality: "Subtitles"
// })
}
// dl({
// url: "http://keepvid.com/?url=" + escape("http://youtube.com/watch?v=" + vid) + "&mode=mp3",
// type: "MP3",
// quality: "64/128 kbps"
// });
var aaa = (new Date).getTime();
var __AM = 65521;
cc = function(a) {
try {
return _cc(a)
} catch (b) {}
return 0
};
function _cc(a) {
if ("string" != typeof a) throw Error("se");
var b = 1,
c = 0,
d, e;
for (e = 0; e < a.length; e++) d = a.charCodeAt(e), b = (b + d) % __AM, c = (c + b) % __AM;
return c << 16 | b
};
// ap({
// params: {
// "u": "http://www.youtube-mp3.org/a/itemInfo/?video_id=" + vid + "&ac=www&t=grp&r=" + aaa,
// "referer": "http://www.youtube-mp3.org/",
// "ua": ua,
// "request_type": "old"
// },
// "dispose": 1,
// "callback": function(da) {
// var ha = inbtwn(da.body, '"h" : "', '"');
// if (ha != "") {
// ap({
// params: {
// "u": "http://www.youtube-mp3.org/get?ab=128&video_id=" + vid + "&h=" + ha + "&r=" + aaa + "." + cc(vid + aaa),
// "referer": "http://www.youtube-mp3.org/",
// "ua": ua,
// "locationonly": "yes"
// },
// "dispose": 1,
// "callback": function(da) {
// dl({
// url: da.body,
// type: "MP3",
// quality: "128 kbps",
// noref: 1
// })
// }
// })
// }
// }
// })
} else if (status == "fail") {
log("Error Reason: " + unescape(da.body.match("reason=([^&]+)")[1]).replace(/\+/g, " "));
if (da.body.match("errorcode=([^&]+)")[1] == "2") error("Invalid YouTube URL. Please check that the link is valid.")
}
}
});
})(location.search)
})()
})
}
})
})(this)
})()