This repository has been archived by the owner on Nov 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
25318.user.js
4595 lines (4146 loc) · 153 KB
/
25318.user.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
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
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name VLCTube
// @namespace 0d92f6be108e4fbee9a6a0ee4366b72e
// @run-at document-start
// @include *://youtube.tld/*
// @include *://*.youtube.tld/*
// @include *://*.youtube.tld/embed/*
// @include *://*.youtube.tld/user/*
// @include *://*.youtube-nocookie.tld/embed/*
// @exclude *://*.google.tld/*
// @exclude *google.com*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_listValues
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM_registerMenuCommand
// @grant unsafeWindow
// @version 58.0
// @updateURL https://github.com/jackun/VLCTube/raw/master/25318.user.js
// @downloadURL https://github.com/jackun/VLCTube/raw/master/25318.user.js
// ==/UserScript==
// @updateURL http://userscripts.org:8080/scripts/source/25318.meta.js
// @downloadURL http://userscripts.org:8080/scripts/source/25318.user.js
// http://wiki.videolan.org/Documentation:WebPlugin
// Tested on Arch linux, Fx30+, vlc 2.1.4, (or vlc-git & npapi-vlc-git from AUR)
//TODO cleanup on aisle 3
//2014-06-25 Fix deciphering for firefox v30 and below
//2014-05-21 Try to resume if unexpected EOS. Use bind(). Playlist next item fix.
//2014-04-26 Watch later, regex fix, remove from watch later if viewing WL playlist, hover controls css
//2014-04-26 Embedded crash. seekTo
//2014-04-26 Incomplete quick fix the fix the fix for comments not loading, API calls maybe
//2014-04-25 Fake Live formats for priority map
//2014-04-24 Separate url map parse from DOM generation so we can fail earlier
// and allow flashplayer to take over. May need manual refreshing with SPF.
//2014-04-24 this -> that. Embed font/css for icons
//2014-04-24 Cleanup
//2014-04-24 Alternate method for / quick fix for popups (security errors)
//2014-04-17 Testing font Awesome Icons
//2014-04-17 Option to auto select subtitle
//2014-04-10 focus() leads to random scroll
//2014-04-07 Signature deciphering flippity-boppity -_-
//2014-03-30 Signature deciphering. Call focus() on vlc plugin
//2014-03-13 Watch Later button option
//2014-03-11 Fixed the playlist?
//2014-03-10 Jump to timestamp option
//2014-03-01 CSS hacks and fix some margins
//2014-02-07 Fix popup. User page > video transition is borked still
//2014-01-21 Live HLS stream test
//2014-01-20 Can transition from main page > search results > video or user page > video without shitting itself?
//2014-01-17 Thumbnails
//2014-01-17 SPF hooking and volume restore changes
//2014-01-17 Quick (aka not complete) fix for extra ajaxy 'tube
//2014-01-06 Call stateUpdate on spf nav.
//2014-01-04 Pass unsafeWindow to tampermonkey
//2014-01-03 Mute button test
//TODO that=this to bind()
//TODO https://www.youtube.com/watch?v=IHGEdi6HblI rtmpe
//cipher https://www.youtube.com/watch?v=tka1jPGMyOs
//stream http://www.youtube.com/watch?v=jrZcAsPKK74
//ciphered http://www.youtube.com/watch?v=6CTHwEZK2JA
//unavail https://www.youtube.com/watch?v=gSEzGDzZ1dY
//has/had non-dash 1080p http://www.youtube.com/watch?v=-MJiR5IksEk
//subtitle test https://www.youtube.com/watch?v=sqll1Rib93g
//state play: 1, pause: 2, stop/end: 0
(function(){
var VLCTube = function (){
"use strict;"
var gPlayerApiID = 'player-api';//-legacy';
var gPlayerID = 'player';//-legacy';
var gMoviePlayerID = 'movie_player'; ///< Change to something else if flash/html5 player keeps overwriting VLC player
var vsTxt = false;
var featherVars;
var stateUpdateFreq = 250;// 250ms
var vlc_id = 'mymovie';
var VLC_status = ["Idle", "Opening", "Buffering", "Playing", "Paused", "Stopped", "ended", "Error"];
// Ich olen international.
var gLang = GM_getValue('vlc-lang', "en");
var gLangs = {
"en": {
'LANG' : 'English',
'NONE' : 'None',
'PLAY' : 'Play',
'PAUSE' : 'Pause',
'STOP' : 'Stop',
'FS' : 'Fullscreen',
'WIDE' : 'Wide',
'DND' : 'Drag and drop to rearrange.',
'LINKSAVE' : 'Download',
'DOWNLOAD' : 'Download',
'WATCHYT' : 'Watch on YT',
'POSITION' : 'Position',
'VOLUME' : 'Volume',
'PLAYBACKRATE': 'Playback rate',
'RESETRATE': 'Reset playback rate',
'MINRATE' : 'Minimum rate',
'MAXRATE' : 'Maximum rate',
'vlc-config-autoplay' : ['Autoplay', ''],
'vlc-config-priomap' : ['Always use format priority map', 'Otherwise uses last selected format or prio. map as fallback'],
'vlc-config-resume' : ['Resume on format change', ''],
'vlc-config-forcews' : ['Force 16:9 aspect ratio', '4:3 videos get black bars duh'],
'vlc-config-forcewide' : ['Always in wide mode', ''],
'vlc-config-add3d' : ['Add 3D formats', 'If you wanna watch cross-eyed'],
'vlc-config-hover' : ['Auto hide controls for embedded', ''],
'vlc-config-loadembed' : ['Load embedded video info', 'Load video title etc.'],
'vlc-config-embedcontrols' : ['Fewer controls on embedded video', 'But not so compact for now atleast'],
'vlc-config-vertvolume' : ['Vertical volume bar', 'Experimental'],
'vlc-config-forcepl' : ['Playlist in wide mode', 'Does nothing for now'],
'vlc-config-thumb' : ['Use thumbnail image', ''],
'vlc-config-rate' : ['Show playback rate scrollbar', ''],
//version 32
'vlc-config-repeat' : ['Enable repeat', ''],
'vlc-config-repeat-wait' : ['Wait before repeating:', 'In seconds'],
//v33
'vlc-config-wide-posbar' : ['Wider playback position scrollbar', ''],//seekbar, whatever
//v34
'POPUP' : 'Popup',
'vlc-config-popup' : ['Show popup button', ''],
'vlc-config-popup-autoplay' : ['Autoplay in popup window', ''],
'vlc-config-popup-separate' : ['Allow multiple popup windows', 'Otherwise popups open in one window'],
'vlc-config-cache' : ['Buffer length:', 'In seconds. Maximum is 60s.'],
'vlc-config-volume-max' : ['Maximum volume:', 'Volume restore gets limited to 100% still'],
//v35+
'vlc-config-scrolltoplayer' : ['Scroll to player', ''],
'vlc-config-wide-width' : ['Wide player width:', 'Add "%" for percentage of current window size. Otherwise it is width in pixels.'],
'vlc-config-dropdown' : ['Config as dropdown', 'Configuration div more like a dropdown menu'],
'BUFFERINDICATOR' : 'Buffering indicator',
'vlc-config-uri-fallback' : ['Use fallback host for URIs', 'Use alternative server for videos if available.'],
'vlc-config-discard-flvs' : ['Discard FLV formats', 'Don\'t add FLV formats as selectable.'],
'vlc-config-dark-theme' : ['Dark theme', 'Make a little friendlier for dark themes.'],
'vlc-config-autoplay-pl' : ['Autoplay playlists', 'Also if checked, plays next video automatically.'],
'vlc-config-adaptives' : ['Add adaptive formats', 'Video only or audio only streams. Currently kinda useless.'],
'WATCHLATER' : 'Watch later',
//v43+
'MUTE' : 'Mute',
'vlc-config-mute-button' : ['Show mute button', ''],
'vlc-config-jumpts' : ['Always jump to timestamp', 'if it is specified in URL.'],
'vlc-config-wl-main' : ['Always show Watch Later button', 'Not just embedded videos.'],
'vlc-config-subs-on' : ['Auto enable subtitle', 'Selects first subtitle and enables it if any is available.'],
'vlc-config-btn-icons' : ['Use button icons', 'Show icons instead of text.'],
'CONFIG' : 'Configuration',
},
"et": {
'LANG' : 'Eesti',
'NONE' : 'Midagi',
'PLAY' : 'Mängi',
'PAUSE' : 'Paus',
'STOP' : 'Stop',
'FS' : 'Täisekraan',
'WIDE' : 'Lai',
'DND' : 'Lohista ümber.',
'LINKSAVE' : 'Parem klikk ja salvesta',
'DOWNLOAD' : 'Lae alla',
'WATCHYT' : 'Vaata YT-s',
'RESETRATE': 'Taasesituskiirus normaalseks tagasi',
'vlc-config-autoplay' : ['Mängi automaatselt', ''],
'vlc-config-priomap' : ['Alati kasuta formaadi tähtsuse järjekorda', 'Muidu kasutab viimati valitut või siis prio. mapi jälle'],
'vlc-config-resume' : ['Jätka samast kohast formaadi vahetusel', 'Mõni formaat/video ei taha vahest seekida eriti.'],
'vlc-config-forcews' : ['Jõuga suru pilt 16:9 mõõtudesse', '4:3 saab mustad jutid äärtesse'],
'vlc-config-forcewide' : ['Alati lai režiim', ''],
'vlc-config-add3d' : ['Lisa 3D formaadid valikusse', 'Veidi mõttetud, kui sa just kõõrdi ei taha vaadata.'],
'vlc-config-hover' : ['Hõljuvad juhtnupud manustatud videotel', 'OMG, i can\'t translate this. fo\' shame'],
'vlc-config-loadembed' : ['Laadi manustatud videote info.', 'Krdil ei paista olevat javascriptis kirjas kuskil :('],
'vlc-config-embedcontrols' : ['Vähem juhtnuppe manustatud videol', 'Noo ainult downloadi link'],
'vlc-config-vertvolume' : ['Vertikaalne helivaljususe slaider', 'Eksperimentaalne'],
'vlc-config-forcepl' : ['Playlist ka laias režiimis', 'Veel ei tee midagi'],
'vlc-config-thumb' : ['Näita pisipilti', ''],
'vlc-config-rate' : ['Näita taasesituse kiiruse kerimisriba', ''],
'vlc-config-repeat' : ['Kordus', ''],
'vlc-config-repeat-wait' : ['Oota enne kordusesitust:', 'Sekundites'],
'vlc-config-wide-posbar' : ['Laiem positsiooni kerimisriba', ''],//hmm
'POPUP' : 'Hüpikaken',
'vlc-config-popup' : ['Näita popupi nuppu', ''],
'vlc-config-popup-autoplay' : ['Automaatesitus hüpikaknas', ''],
'vlc-config-popup-separate' : ['Luba mitu hüpikakent', 'Muidu avab ainult ühes aknas'],
'vlc-config-cache' : ['Puhverduse pikkus:', 'Sekundites. Maksimum on 60s.'],
'vlc-config-volume-max' : ['Maksimum helivaljusus:', 'Limiteeritakse 100% peale video lõppedes'],
'vlc-config-scrolltoplayer' : ['Keri pleier vaatesse', ''],
'vlc-config-wide-width' : ['Laia pleieri laius:', 'Laius pikslites või lisa protsendi märk, et seada proportsionaalselt akna laiusega.'],
'WATCHLATER' : 'Vaata hiljem',
},
"fi": {
'LANG' : 'Suomi',
'NONE' : 'Ei mitään',
'PLAY' : 'Pelaa',
'PAUSE' : 'Paussi',
'STOP' : 'Stop', //'Pysäyttää',
'FS' : 'Koko näyttö',
'WIDE' : 'Laaja',
'DND' : 'Vedä siitä ja pudota tuonne.',
'LINKSAVE' : 'Lataa koneellesi oikealla klikkauksella',
'DOWNLOAD' : 'Lataa',
'WATCHYT' : 'Katso YT-ssa',
'RESETRATE': 'Palauta toiston nopeus',
},
/// By MegaPokemon3 [http://userscripts.org/users/BOTCoder]
"tr": {
'LANG' : 'Türkçe',
'NONE' : 'Hiç',
'PLAY' : 'Oynat',
'PAUSE' : 'Duraklat',
'STOP' : 'Durdur',
'FS' : 'Tam Ekran',
'WIDE' : 'Geniş',
'DND' : 'Sürükle ve Yeniden Düzenlemek İçin Bırakın',
'LINKSAVE' : 'Sağ Tıklayıp Kaydet',
'DOWNLOAD' : 'Indir',
'WATCHYT' : 'YTde izle',
'POSITION' : 'Pozisyon',
'VOLUME' : 'Ses',
'PLAYBACKRATE': 'Oynatma Oranı',
'RESETRATE': 'Oynatma Oranı Sıfırla',
'MINRATE' : 'Minimum Oran',
'MAXRATE' : 'Maximum Oran',
'vlc-config-autoplay' : ['Otomatik Oynat', ''],
'vlc-config-priomap' : ['Her zaman biçimi öncelikli haritayı kullanabilirsiniz', 'Aksi takdirde son seçilen biçimi veya prio kullanır. son çare olarak haritası'],
'vlc-config-resume' : ['Biçim değişikliği Devam', ''],
'vlc-config-forcews' : ['16:9 en boy oranı zorla', '4:03 video siyah çubuklar yaa olsun'],
'vlc-config-forcewide' : ['Her zaman geniş modda', ''],
'vlc-config-add3d' : ['3D formatları ekle', 'Eğer siz seyretmek istiyorum şaşı gözlü bir'],
'vlc-config-hover' : ['Gömülü için denetimler gezdirin', ''],
'vlc-config-loadembed' : ['Gömülü video bilgi yüklemek', 'Video başlığı vb Yük'],
'vlc-config-embedcontrols' : ['Gömülü video üzerinde daha az kontrolleri', 'Şimdilik bu kadar kompakt değil'],
'vlc-config-vertvolume' : ['Dikey hacmi bar', 'deneysel'],
'vlc-config-forcepl' : ['Geniş modunda Playlist', 'Şimdilik bir şey yok'],
'vlc-config-thumb' : ['Küçük resim kullanın', ''],
'vlc-config-rate' : ['Oynatma hızını kaydırma göster', ''],
//end of v32
},
/// By decembre [http://userscripts.org/users/5161]
"fr": {
'LANG' : 'Français',
'NONE' : 'None',
'PLAY' : 'Play',
'PAUSE' : 'Pause',
'STOP' : 'Stop',
'FS' : 'Plein Ecran',
'WIDE' : 'Large',
'DND' : 'Réorganiser par Drag and Drop',
'LINKSAVE' : 'Click Droit et Enregistrer',
'DOWNLOAD' : 'Télécharger',
'WATCHYT' : 'Regarder sur YT',
'POSITION' : 'Position',
'VOLUME' : 'Volume',
'PLAYBACKRATE': 'Vitesse de Lecture',
'RESETRATE': 'Reset Vitesse de Lecture',
'MINRATE' : 'Vitesse de Lecture Minimum',
'MAXRATE' : 'Vitesse de Lecture Maximum',
'vlc-config-autoplay' : ['Lecture Auto', ''],
'vlc-config-priomap' : ['Toujours Utiliser le Format Prioritaire', ''],
'vlc-config-resume' : ['Reprendre au chamgement de format', ''],
'vlc-config-forcews' : ['Forcer 16:9 aspect ratio', 'Les videos en 4:3 auront des barres noires'],
'vlc-config-forcewide' : ['Toujours en Grand Ecran', ''],
'vlc-config-add3d' : ['Ajouter 3D formats', ''],
'vlc-config-hover' : ['Contôles visibles par Hover', ''],
'vlc-config-loadembed' : ['Charger les Infos Intégrées de la Vidéo', 'Titre etc.'],
'vlc-config-embedcontrols' : ['Moins de Contrôles dans la Vidéo', 'Pas si compact pour l\'instant'],
'vlc-config-vertvolume' : ['Barre de Volume Verticale', 'Experimental'],
'vlc-config-forcepl' : ['Playlist en Mode Large', 'Ne fait rien pour l\'instant'],
'vlc-config-thumb' : ['Utiliser les Vignettes', ''],
'vlc-config-rate' : ['Vitesse de Lecture dans la Barre de Défilement ', ''],
'vlc-config-repeat' : ['Activer la Répétition', ''],
'vlc-config-repeat-wait' : ['Patienter avant de Répéter:', 'En seconds'],
'vlc-config-wide-posbar' : ['Position de Lecture Plus Large dans la Barre de Défilement', ''],
'POPUP' : 'Popup',
'vlc-config-popup' : ['Montrer le bouton Popup', ''],
'vlc-config-popup-autoplay' : ['Autoplay Popup dans une fenêtre', ''],
'vlc-config-popup-separate' : ['Popups Séparés', 'Sinon les Popups s\'ouvrent dans une autre fenêtre'],
//end of v34
},
};
function _(id)
{
// var in dict seems to work too, but tampermonkey syntax checker is bitching
if(gLangs.hasOwnProperty(gLang) && gLangs[gLang].hasOwnProperty(id))
return gLangs[gLang][id];
else
{
//console.log("Missing translation for " + id + " in " + gLang);
if(gLangs.en.hasOwnProperty(id))
return gLangs.en[id];
else
return id;
}
}
// seeking: webm, mp4 > flv
var convToItag = {
'hd1080/webm' : 46, //1080p
'hd1080/mp4' : 37, //1080p
'hd720/webm' : 45, //720p
'hd720/mp4' : 22, //720p
'large/webm' : 44, //480p
'large/mp4' : 20, //2? 480p
'large/x-flv' : 35, //480p
'medium/webm' : 43, //360p
'medium/mp4' : 18, //360p
'medium/x-flv' : 34,//360p
'small/x-flv' : 5, //240p
'small/3gpp' : 36, //180p
//'small/3gpp' : 17, //144p
"highres/mp4" : 38, //1440p variable?
//"highres/webm" //4? (exists?)
};
var itagPrio = [
46, 37, 45, 22, 44, 20, 35, 43, 18, 34, 5, 36, 17, 38, //4?
//Live streams
96, 95, 94, 93, 92, 91, 90, 132, 151,
//Fake live formats
//11080, 10720, 10480, 10360, 10240, 10180, 10144, 10072,
];
var itagToText = {
0: 'dash',
299: '1080p60/m4v',
298: '720p60/m4v',
272: 'hires/webm',
271: '1440p/webm',
264: '1440p/m4v', //hires
248: '1080p/webm',
247: '720p/webm',
246: '480p/webm',
245: '480p/webm',
244: '480p/webm',
243: '360p/webm',
242: '240p/webm',
172: '160kbps/webm',
171: '96kbps/webm',
160: '144p/m4v',
141: '256kbps/m4a',
140: '128kbps/m4a',
139: '48kbps/m4a',
138: 'hires/m4v',
137: '1080p/m4v',
136: '720p/m4v',
135: '480p/m4v',
134: '360p/m4v',
133: '240p/m4v',
120: '720p/flv',
102: '720p/webm/3D',
101: '360p/webmH/3D',
100: '360p/webmL/3D',
85 : '520p/mp4/3D',
84 : '720p/mp4/3D',
83 : '240p/mp4/3D',
82 : '360p/mp4/3D',
//78: '',
//59: '',
46 : '1080p/webm',
37 : '1080p/mp4',
45 : '720p/webm',
22 : '720p/mp4',
44 : '480p/webm',
20 : '480p/mp4',
35 : '480p/flv',
43 : '360p/webm',
18 : '360p/mp4',
34 : '360p/flv',
5 : '240p/flv',
36 : '180p/3gpp',
17 : '144p/3gpp',
// last, just in case "4k" video crashes graphics card's driver
38 : 'highres/mp4', //1440p variable?
//4? : "highres/webm"
96 : '1080p Live',
95 : '720p Live',
94 : '480p Live',
93 : '360p Live',
92 : '240p Live',
91 : '180p Live', //Guess work
90 : '144p Live', //Guess work
132 : '240p Live',
151 : '72p Live',
/*
//Fake live formats
11080 : '1080p Live',
10720 : '720p Live',
10480 : '480p Live',
10360 : '360p Live',
10240 : '240p Live',
10180 : '180p Live',
10144 : '144p Live',
10072 : '72p Live',
*/
};
//generates this programmatically
var textToItag = {};
var headers = {'User-agent': 'Mozilla/5.0 (compatible) Greasemonkey',
'Accept': 'text/xml'};
function tryParseFloat(v, def)
{
v = parseFloat(v);
return isNaN(v) ? def : v;
}
function ft(i){ if (i>=10) return i; return '0'+i;}
function fmttime(time)
{
if(time < 0) time = 0;
var ms = Math.floor(time % 1000 / 10);
var s = Math.floor(time % 60000 / 1000);
var m = Math.floor(time % 3600000 / 60000);
//var m = Math.floor(time / 60000);
var h = Math.floor(time / 3600000);
//return ft(m) +':'+ ft(s) + '.' + ft(ms);
return (h>0?ft(h)+':':'') + ft(m) +':'+ ft(s);
}
function getMatches(string, regex, index) {
index || (index = 1); // default to the first capturing group
var matches = [];
var match;
while (match = regex.exec(string)) {
matches.push(match[index]);
}
return matches;
}
//Recursively remove node and node's children
function removeChildren(node, keepThis)
{
if(node === undefined || node === null)
{
return;
}
while (node.hasChildNodes())
{
removeChildren(node.firstChild, false);
}
//silence html5 element
if(typeof(node.pauseVideo) === 'function')
node.pauseVideo();
else if(typeof(node.pause) === 'function')
node.pause();
if(!keepThis) node.parentNode.removeChild(node);
}
//ScriptInstance.prototype.str2obj = function (a, b) {
function yt_str2obj(obj, a, b) {
m = {};
m.l = function (a) {
return void 0 !== a
};
var c = a.split('.'), d = obj;//this;
//c[0] in d || !d.execScript || d.execScript('var ' + c[0]);
for (var e; c.length && (e = c.shift()); ) !c.length && (0, m.l) (b) ? d[e] = b : d[e] ? d = d[e] : d = d[e] = {}
console.log(d);
};
function str2obj(obj, a) {
var c = a.split('.'), d = obj;
for (var e; c.length && (e = c.shift()); )
if(d[e]) d = d[e]; else return null;
return d;
}
function fakeTimeout(callback) {
function ftcb(ev)
{
callback(ev);
window.document.body.removeEventListener("timeoutEvent", arguments.callee, false);
}
// Register event listener
window.document.body.addEventListener("timeoutEvent", ftcb, false);
// Generate and dispatch synthetic event
var ev = window.document.createEvent("HTMLEvents");
ev.initEvent("timeoutEvent", true, false);
window.document.body.dispatchEvent(ev);
}
function printStack()
{
var e = new Error('');
var stack = e.stack
//strip script's file name
.replace(/(.*?)@.*?:/gm, '$1:').replace(/:.*?:/gm, ':')
//.replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@')
.split('\n');
console.log("Stack trace:");
for(var s = 1; s < stack.length; s++)
console.log(s, stack[s]);
}
///
/// <Signature decipher>
///
function Decode(sig, arr)
{
sig = sig.split('')
for (i in arr)
{
i = arr[i];
// + swap, - slice, 0 reverse
sig = (i > 0) ? Swap(sig, i) : ((i == 0) ? Reverse(sig) : sig.slice(-i));
}
return sig.join('');
}
function Swap(a, b)
{
var c = a[0];
a[0] = a[b % a.length];
a[b] = c;
return a;
}
function Reverse(str)
{
if(typeof(str) === 'string')
return str.split('').reverse().join('');
else
return str.reverse();
}
//Fallback internal decipherer
//TODO also fallback to this if GetDecodeParam->Decode fails
function DecryptSignature(sig, sts)
{
if(typeof sts == 'undefined') sts = 0;
if(!sig) return;
switch (sig.length)
{
/*case 82:
{
var sigA = Reverse(sig.substr(34, 48));
var sigB = Reverse(sig.substr(0, 33));
sig = sigA.substr(45, 1) + sigA.substr(2, 12) + sigA.substr(0, 1) + sigA.substr(15, 26) +
sig.substr(33, 1) + sigA.substr(42, 1) + sigA.substr(43, 1) + sigA.substr(44, 1) +
sigA.substr(44, 1) + sigA.substr(46, 1) + sigB.substr(31, 1) + sigA.substr(14, 1) +
sigB.substr(0, 32) + sigA.substr(47, 1);
}
break;*/
case 83:
//sig = Decode(sig, [ 24, 53, -2, 31, 4 ]);
switch(sts)
{
case 15995:
sig = Decode(sig, [0,9,0,-1,51,27,0,-1,0])
break;
default:
sig = Decode(sig, [0,-2,0,63,0])
break;
}
break;
case 84:
{
var sigA = Reverse(sig.substr(44, 40));
var sigB = Reverse(sig.substr(3, 40));
sig = sigA + sig.substr(43, 1) + sigB.substr(0, 6) + sig.substr(2, 1) + sigB.substr(7, 9) +
sigB.substr(39, 1) + sigB.substr(17, 22) + sigB.substr(16, 1);
}
break;
case 85:
sig = Decode(sig, [ 0, -2, 17, 61, 0, -1, 7, -1 ]);
break;
case 86:
{
//var sigA = sig.substr(2, 40);
//var sigB = sig.substr(43, 40);
//sig = sigA + sig.substr(42, 1) + sigB.substr(0, 20) + sigB.substr(39, 1) + sigB.substr(21, 18) + sigB.substr(20, 1);
sig = Decode(sig, [0,12,32,0,34,-3,35,42,-2]);
}
break;
case 87:
{
var sigA = Reverse(sig.substr(44, 40));
var sigB = Reverse(sig.substr(3, 40));
sig = sigA.substr(21, 1) + sigA.substr(1, 20) + sigA.substr(0, 1) + sigB.substr(22, 9) +
sig.substr(0, 1) + sigA.substr(32, 8) + sig.substr(43, 1) + sigB;
}
break;
case 88:
sig = Decode(sig, [ -2, 1, 10, 0, -2, 23, -3, 15, 34 ]);
break;
case 92:
sig = Decode(sig, [ -2, 0, -3, 9, -3, 43, -3, 0, 23 ]);
break;
case 93:
sig = Decode(sig, [-3,0,-1,0,-3,0-3,59,-2])
break;
default:
switch(sts) //signature timestamp
{
case 15981:
sig = Decode(sig, [7,37,0,-1])
break;
}
break;
}
return sig;
}
///
/// </Signature decipher>
///
function CustomEvent(){
this._listeners = {};
}
CustomEvent.prototype = {
constructor: CustomEvent,
addListener: function(event, listener){
if (typeof this._listeners[event] == "undefined"){
this._listeners[event] = [];
}
if(typeof listener == "string") listener = window[listener];
listener && this._listeners[event].push(listener);
console.log("addListener:", event, listener);
},
fire: function(event, that){
if (this._listeners[event] instanceof Array){
var listeners = this._listeners[event];
for (var i=0, len=listeners.length; i < len; i++){
//arguments is not an actual Array
listeners[i].apply(that, Array.prototype.slice.call(arguments, 2, arguments.length));
}
}
},
};
// Controls
function ScrollBar (instance) {
this.instance = instance; //greasemonkey script instance
this.formatter = null;
this.offX = 0;
this.offY = 0;
this.value = 0;
this.minValue = 0.0;
this.maxValue = 100.0;
this.type = 0;//0 - hor, 1 - vert
this.bar = null;
this.knob = null;
this.userSeeking = false;
this.instant = false;
this.events = [];
}
//https://developer.mozilla.org/en-US/docs/XPConnect_wrappers
ScrollBar.__exposedProps__ = { };
ScrollBar.prototype = {
constructor: ScrollBar,
$: function(id){ return this.instance.doc.getElementById(id); },
initSB: function(barId, knobId, type, minval, maxval, insta, formatter){
if(typeof(type) == 'undefined') type = 0;
if(typeof(minval) == 'undefined') minval = 0;
if(typeof(maxval) == 'undefined') maxval = 100;
if(typeof(insta) == 'undefined') insta = false;
this.bar = this.instance.doc.querySelector(barId);
//this.bar.ScrollBar = this;
this.knob = this.instance.doc.querySelector(knobId);
//this.knob.ScrollBar = this;
this.knob = this.instance.doc.querySelector(knobId);
this.instant = insta;
this.formatter = formatter;
this.bar.unselectable = "on";
this.knob.unselectable = "on";
this.bar.style.MozUserSelect='none';
this.knob.style.MozUserSelect='none';
//this.knob.style.KhtmlUserSelect='none';
this.type = type;
this.minValue = minval;
this.maxValue = maxval;
//this.knob.onmousedown = ScrollBar.eventHandlers.mouseDown;
this.knob.addEventListener('mousedown',ScrollBar.prototype.mouseDown.bind(this),true);
this.bar.addEventListener('mousedown',ScrollBar.prototype.mouseDownBar.bind(this),true);
// Keep reference so these event handlers can be removed
this.event = {
up: ScrollBar.prototype.mouseUp.bind(this),
move: ScrollBar.prototype.mouseMove.bind(this)
};
},
register: function(ev)
{
this.events.push(ev);
},
unregister: function(ev)
{
for(var i=0;i<this.events.length;i++)
{
if(this.events[i] == ev)
{
this.events.splice(i,1);
break;
}
}
},
emitValue:function(instant){
if(this.formatter) this.formatter(this.value);
for(var i in this.events){
this.events[i].emitValue(this, this.value, instant);
}
},
setValue: function(val){//FIXME minValue
if(val<0) val=0;
if(this.userSeeking || (ScrollBar._ScrollBarDragData && ScrollBar._ScrollBarDragData.Scrollbar == this)) return;
this.value = val;
if(this.type == 0)
this.knob.style.left = Math.round( ((this.value - this.minValue)/(this.maxValue - this.minValue)) * (this.bar.clientWidth - this.knob.clientWidth)) + "px";
if(this.type == 1)
this.knob.style.top = Math.round(((this.maxValue - this.value)/this.maxValue) * (this.bar.clientHeight - this.knob.clientHeight)) + "px";
//Set knob width
if(this.type == 2)
this.knob.style.width = Math.round( ((this.value - this.minValue)/(this.maxValue - this.minValue)) * this.bar.clientWidth) + "px";
// TODO vertical if you want
if(this.formatter) this.formatter(this.value);
},
getValue: function(){ return this.value; },
setMaxValue: function(max){ this.maxValue = max; },
setMinValue: function(min){ this.minValue = min; },
mouseDownBar: function(ev){
if(this.type < 2 && ev.explicitOriginalTarget == this.knob) return;
this.userSeeking = true;
this.off = 0;
var node = this.bar;
while(node.offsetParent) // bar's position is relative so loop through parent nodes
{ // maybe there's some better tricks
this.off += node.offsetLeft;
node = node.offsetParent;
}
if(this.type == 0)
this.knob.style.left = ev.pageX - this.off - this.knob.clientWidth / 2 + "px";
else if(this.type == 1)
this.knob.style.top = ev.pageY - this.off - this.knob.clientHeight / 2 + "px";
//Simulate events
this.mouseDown(ev);
this.mouseMove(ev);
},
mouseDown: function(ev){
this.userSeeking = true;
this._ScrollBarDragData = {
pageX: ev.pageX,
pageY: ev.pageY,
dx: ev.pageX - this.knob.offsetLeft,
dy: ev.pageY - this.knob.offsetTop,
startValue: this.value,
};
this.instance.doc.addEventListener('mouseup',this.event.up,true);
this.instance.doc.addEventListener('mousemove',this.event.move,true);
},
mouseUp: function(ev){
this.userSeeking = false;
this.instance.doc.removeEventListener('mouseup',this.event.up,true);
this.instance.doc.removeEventListener('mousemove',this.event.move,true);
this._ScrollBarDragData = null;
this.emitValue(false);
},
mouseMove: function(ev){
switch(this.type){
case 0:
var x = ev.pageX - this._ScrollBarDragData.dx;
var w = this.bar.clientWidth - this.knob.clientWidth;
if( x < 0 ) x = 0;
if( x > w ) x = w;
this.knob.style.left = x + "px";
if(w != 0) //eh weird, otherwise NaN sometimes if user drags 'over the edge'
this.value = x/w * (this.maxValue - this.minValue) + this.minValue;
//this.knob.title = Math.floor(x/w * 100) + '%';
break;
case 1: //FIXME minValue
var y = ev.pageY - this._ScrollBarDragData.dy;
var h = this.bar.clientHeight - this.knob.clientHeight;
if( y < 0 ) y = 0;
if( y > h ) y = h;
this.knob.style.top = y + "px";
if(h != 0) //eh weird, otherwise NaN sometimes if user drags 'over the edge'
this.value = this.maxValue - (y/h * this.maxValue);
break;
case 2:
//Seems that 'border' width of 2px comes into play
var x = ev.pageX - this.off - 2;
var w = this.bar.clientWidth;
if( x < 0 ) x = 0;
if( x > w ) x = w;
this.knob.style.width = x + "px";
if(w != 0)
this.value = x/w * (this.maxValue - this.minValue) + this.minValue;
break;
}
if(this.instant) this.emitValue(true);
},
};
function ccTimer()
{
this.ccObj = null;
this.ccOffset = 0;
this.lastTime = 0;
this.nodeCount = 0;
this.reset = true;
}
ccTimer.prototype =
{
init : function(cc)
{
this.ccObj = cc;
this.nodeCount = this.ccObj.childNodes.length;
this.update(0);
},
getStart : function(offset)
{
if(offset>-1 && offset < this.nodeCount)
return this.ccObj.childNodes[offset].getAttribute("start");
return 0;
},
getDur : function(offset)
{
if(offset>-1 && offset < this.nodeCount)
return this.ccObj.childNodes[offset].getAttribute("dur");
return 0;
},
getLastStart : function()
{
return this.getStart(this.ccOffset);
},
getLastDur : function()
{
return this.getDur(this.ccOffset);
},
resetState: function()
{
this.ccOffset = -1;
this.lastTime = 0;
this.resetCC();
},
update: function(time, vlc)
{
//sanity check of testing code, wrap back to start
if(this.ccOffset >= this.nodeCount || this.lastTime >= time)
{
this.resetState();
}
if(this.lastTime < time)
{
var newOff = this.ccOffset+1;
while(newOff < this.nodeCount
&& this.getStart(newOff) <= time)
{
newOff++;
}
newOff--;
if( newOff > this.ccOffset //is indeed a new one
//&& time < this.getStart(newOff) + this.getDur(newOff)
)
{
this.setCC(newOff, time, vlc);
this.lastTime = this.getLastStart();
}
}
//console.log(time);
},
setCC : function(offset, time, vlc)
{
vlc.video.marquee.disable();//brute forcing, sometimes it fails to show
vlc.video.marquee.enable();
//Hmm no likey unicode ???
vlc.video.marquee.text = this._unescape(this.ccObj.childNodes[offset].innerHTML);
vlc.video.marquee.timeout = 1000 * this.getDur(offset);
this.ccOffset = offset;
this.reset = false;
},
resetCC : function()
{
this.reset = true;
},
_unescape: function(str)
{
//str = str.replace(/&/g, '&').replace(/"/g, '"');
str = this.htmlDecode(str);
str = this.htmlDecode(str);
//str = decodeURIComponent(str);
var m = getMatches(str, /&#(\d+);/g, 1);
for(var i in m)
{
str = str.replace("&#" + m[i] + ";", String.fromCharCode(m[i]));
}
return str;
},
htmlDecode: function(input)
{
if(this._e === undefined) this._e = document.createElement('div');
this._e.innerHTML = input;
return this._e.childNodes.length === 0 ? "" : this._e.childNodes[0].nodeValue;
}
}
function Storyboard(el, sb)
{
this.element = null;
this.thumbs = [];
this.oldThumb = null;
this.tOut = null;
this.onetimeonly = true;
this.story_spec_url = null;
this.wait = 5; //reduce cpu load
this.element = el;
spec = sb.split('|');
this.story_spec_url = spec[0];
spec = spec.slice(1);
spec.forEach((function(a){
a = a.split('#');
this.thumbs.push({
w : a[0],
h : a[1],
count : a[2],
gridX : a[3],
gridY : a[4],
//unknown : a[5],
n_param : a[6],
sigh : a[7],
});
}).bind(this));
}
Storyboard.prototype = {
Cmp: function(a,b)
{
if(!a || !b) return false;
return
a.page == b.page &&
//a.src == b.src &&
a.x == b.x && a.y == b.y;
},
getStoryBoardSrc: function(page, i)
{
if(i<0) return null;
uri = this.story_spec_url.replace('$L', i).
replace('$N', this.thumbs[i].n_param)
+ "?sigh="
+ this.thumbs[i].sigh;
n_param = this.thumbs[i].n_param.split('$');
if(n_param.length>1)
n_param = '$' + n_param[1];
else
n_param = n_param[0]; //special case 'default'
return (n_param == 'default' ? uri : uri.replace(n_param, page));
},
//pos is normalized to 0..1
getStoryBoardAtPos: function(pos, i)
{
if(i<0) return null;
pages = this.thumbs[i].count / (this.thumbs[i].gridX * this.thumbs[i].gridY);
//if(this.thumbs[i].count % (this.thumbs[i].gridX * this.thumbs[i].gridY))
// pages++;
page = Math.floor(pos * pages);
if(page < 0 || page > pages)