summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/EmbedVideo/classes/VideoService.php
blob: 1d610aa949d02bbffe972d65778cf9bd8ceff085 (plain)
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
<?php
/**
 * EmbedVideo
 * EmbedVideo VideoService Class
 *
 * @license		MIT
 * @package		EmbedVideo
 * @link		https://www.mediawiki.org/wiki/Extension:EmbedVideo
 *
 **/
namespace EmbedVideo;

class VideoService {
	/**
	 * Available services.
	 *
	 * @var		array
	 */
	static private $services = [
		'archiveorg' => [
			'embed'			=> '<iframe src="//archive.org/embed/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio' => 1.2994923857868, // (640 / 493)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#archive\.org/(?:details|embed)/([\d\w\-_][^/\?\#]+)#is'
			],
			'id_regex'		=> [
				'#^([\d\w\-_][^/\?\#]+)$#is'
			]
		],
		'bambuser' => [
			'embed'			=> '<iframe src="//embed.bambuser.com/broadcast/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio' => 1.2994923857868, // (640 / 493)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#bambuser\.com/(?:v|broadcast)/([\d\w\-\+]+)(?:/\S+?)?#is'
			],
			'id_regex'		=> [
				'#^([\d\w\-\+]+)$#is'
			]
		],
		'bambuser_channel' => [
			'embed' 		=> '<iframe src="//embed.bambuser.com/channel/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio' => 1.2994923857868, // (640 / 493)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#bambuser\.com/channel/([\d\w\-\+]+)(?:/\S+?)?#is'
			],
			'id_regex'		=> [
				'#^([\d\w\-\+]+)$#is'
			]
		],
		'beam' => [
			'embed'			=> '<iframe src="https://beam.pro/embed/player/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#beam.pro/([\d\w\-\+]+)(?:/\S+?)?#is'
			],
			'id_regex'		=> [
				'#^([\d\w\-\+]+)$#is'
			]
		],
		'disclose' => [
			'embed'			=> '<iframe src="//www.disclose.tv/embed/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (640 / 360)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#disclose.tv/embed/([\d]+)/([\w-]+)#is',
				'#disclose.tv/action/viewvideo/([\d]+)/([\w-]+)/#is'
			],
			'id_regex'		=> [
				 '#^([\d]+)$#is'
			]
		],
		'blip' => [
			'default_width'	=> 640,
			'default_ratio' => 1.2994923857868, // (640 / 493)
			'https_enabled'	=> false,
			'url_regex'		=> [
				'#(http://blip\.tv/[\w\d\-]+?/[\w\d\-]+?-[\d]+)#is'
			],
			'oembed'		=> 'http://blip.tv/oembed/?url=%1$s&width=%2$d&maxwidth=%2$d'
		],
		'bing' => [
			'embed'			=> '<iframe src="//hub.video.msn.com/embed/%1$s" width="%2$d" height="%3$d" frameborder="0" scrolling="no" noscroll allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#bing.com/videos/watch/video/[\w\d\-]+?/([a-zA-Z0-9]+)(?:/\S+?)?#is'
			],
			'id_regex'		=> [
				'#^([a-zA-Z0-9]+)$#is'
			]
		],
		'collegehumor' => [
			'embed'			=> '<iframe src="//www.collegehumor.com/e/%1$s" width="%2$d" height="%3$d" frameborder="0" allowFullScreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio' => 1.6260162601626, // (600 / 369)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#collegehumor\.com/(?:video|e)/([\d]+)#is'
			],
			'id_regex'		=> [
				'#^([\d]+)$#is'
			]
		],
		'dailymotion' => [
			'embed'			=> '<iframe src="//www.dailymotion.com/embed/video/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#dailymotion\.com/(?:video|embed/video)/([a-zA-Z0-9]+)(?:_\S+?)?#is'
			],
			'id_regex'		=> [
				'#^([a-zA-Z0-9]+)(?:_\S+?)?#is'
			]
		],
		'divshare' => [
			'embed'			=> '<iframe src="//www.divshare.com/flash/video2?myId=%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> true
		],
		'funnyordie' => [
			'embed'			=> '<iframe src="http://www.funnyordie.com/embed/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.64102564102564, // (640 / 390)
			'https_enabled'	=> false,
			'url_regex'		=> [
				'#funnyordie\.com/(?:videos|embed)/([a-zA-Z0-9]+)(?:/\S+?)?#is'
			],
			'id_regex'		=> [
				'#^([a-zA-Z0-9]+)$#is'
			]
		],
		'gfycat' => [
			'embed'			=> '<iframe src="//gfycat.com/ifr/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true" scrolling="no" style="-webkit-backface-visibility: hidden;-webkit-transform: scale(1);" ></iframe>',
			'default_width'	=> 640,
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#gfycat\.com/([a-zA-Z]+)#is'
			],
			'id_regex'		=> [
				'#^([a-zA-Z]+)$#is'
			]
		],
		'hitbox' => [
			'embed'			=> '<iframe src="http://www.hitbox.tv/embed/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> false,
			'url_regex'		=> [
				'#hitbox.tv/([\d\w]+)(?:/\S+?)?#is'
			],
			'id_regex'		=> [
				'#^([\d\w]+)$#is'
			]
		],
		'jwplayer' => [
			'embed'			=> '<iframe src="//content.jwplatform.com/players/%1$s.html" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#content\.jwplatform\.com/players/([a-zA-Z0-9]+-[a-zA-Z0-9]+)(?:.)?#is'
			],
			'id_regex'		=> [
				'#([a-zA-Z0-9]+-[a-zA-Z0-9]+)#is'
			]
		],
		'kickstarter' => [
			'embed'			=> '<iframe src="//www.kickstarter.com/projects/%1$s/widget/video.html" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#kickstarter\.com/projects/([\d\w-]+/[\d\w-]+)(?:/widget/video.html)?#is'
			],
			'id_regex'		=> [
				'#^([\d\w-]+/[\d\w-]+)$#is'
			]
		],
		'mediacccde' => [
			'embed'	 => '<iframe src="https://media.ccc.de/v/%1$s/oembed" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true" scrolling="no"></iframe>',
			'default_width' => 660,
			'default_ratio' => 1.77777777777778, //(16 / 9),
			'https_enabled' => true,
			'url_regex' => [
				'#conferences/.*?([\d\w_-]+)(?:/oembed)?.html$#is'
			],
			'id_regex'	=> [
				'#^([\d\w_-]+)$#is'
			]
		],
		'metacafe' => [
			'embed'			=> '<iframe src="http://www.metacafe.com/embed/%1$s/" width="%2$d" height="%3$d" frameborder="0" allowFullScreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> false,
			'url_regex'		=> [
				'#metacafe\.com/(?:watch|embed)/([\d]+)(?:/\S+?)?#is'
			],
			'id_regex'		=> [
				'#^([\d]+)$#is'
			]
		],
		'nico' => [
			'embed'			=> '<iframe srcdoc="&lt;script type=&quot;text/javascript&quot; src=&quot;http://ext.nicovideo.jp/thumb_watch/%1$s?w=%2$d&amp;h=%3$d&quot;&gt;&lt;/script&gt;" width="%2$d" height="%3$d" frameborder="0" allowFullScreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.59609120521173, // (490 / 307)
			'https_enabled'	=> false,
			'url_regex'		=> [
				'#nicovideo\.jp/watch/((?:[a-zA-Z]{2})?[\d]+)#is'
			],
			'id_regex'		=> [
				'#^((?:[a-zA-Z]{2})?[\d]+)$#is'
			]
		],
		'rutube' => [
			'embed'			=> '<iframe src="//rutube.ru/play/embed/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#rutube\.ru/video/([a-zA-Z0-9]+)(?:/\S+?)?#is'
			],
			'id_regex'		=> [
				'#^([a-zA-Z0-9]+)$#is'
			]
		],
		'soundcloud' => [
			'embed'			=> '<iframe src="https://w.soundcloud.com/player/?url=%1$s&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true" width="%2$d" height="%3$d" scrolling="no" frameborder="no"></iframe>',
			'default_width'	=> 186,
			'default_ratio'	=> 2.66666,
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#^(https://soundcloud\.com/.+?/.+?)$#is',
			]
		],
		'teachertube' => [
			'embed'			=> '<iframe src="http://www.teachertube.com/embed/video/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.72972972972973, // (640 / 370)
			'https_enabled'	=> false,
			'url_regex'		=> [
				'#teachertube\.com/video/(?:[\w\d\-]+?-)?([\d]+)$#is',
			],
			'id_regex'		=> [
				'#^([\d]+)$#is'
			]
		],
		'ted' => [
			'embed'			=> '<iframe src="//embed-ssl.ted.com/talks/%1$s.html" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#ted\.com/talks/([\d\w\-]+)(?:/\S+?)?#is',
			],
			'id_regex'		=> [
				'#^([\d\w\-]+)$#is'
			]
		],
		'tubitv' => [
			'embed'			=> '<iframe src="//tubitv.com/embed/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (640 / 360)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#tubitv.com/(?:video|embed)/([\d]+)(/[\w-]+)?$#is',
			],
			'id_regex'		=> [
				'#^([\d]+)$#is'
			]
		],
		'tudou' => [
			'embed'			=> '<iframe src="http://www.tudou.com/programs/view/html5embed.action?code=%1$s&autoPlay=false&playType=AUTO" allowfullscreen="true" width="%2$d" height="%3$d" frameborder="0"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.6,
			'https_enabled'	=> false,
			'url_regex'		=> [
				'#tudou.com/listplay/([\d\w-]+)/([\d\w-]+).html#is',
				'#tudou.com/listplay/([\d\w-]+).html#is'
			],
			'id_regex'		=> [
				'#^([\d\w-]+)$#is'
			]
		],
		'tvpot' => [
			'embed'			=> '<iframe src="//videofarm.daum.net/controller/video/viewer/Video.html?vid=%1$s&play_loc=undefined&alert=true" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#tvpot\.daum\.net/v/([\d\w-%]+)?#is'
			],
			'id_regex'		=> [
				'#^([\d\w-%]+)$#is'
			]
		],
		'twitch' => [
			'embed'			=> '<iframe src="https://player.twitch.tv/?channel=%1$s&%4$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.64021164021164, // (620 / 378)
			'https_enabled'	=> false,
			'url_regex'		=> [
				'#twitch\.tv/([\d\w-]+)(?:/\S+?)?#is'
			],
			'id_regex'		=> [
				'#^([\d\w-]+)$#is'
			]
		],
		'twitchvod' => [
			'embed'			=> '<iframe src="https://player.twitch.tv/?autoplay=false&video=%1$s&%4$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.64021164021164, // (620 / 378)
			'https_enabled'	=> false,
			'url_regex'		=> [
				'#twitch\.tv/([\d\w-]+)(?:/\S+?)?#is'
			],
			'id_regex'		=> [
				'#^([\d\w-]+)$#is'
			]
		],
		'videomaten' => [
			'embed'			=> '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="%2$d" height="%3$d" id="videomat" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="http://89.160.51.62/recordMe/play.swf?id=%1$s" /><param name="loop" value="false" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="http://89.160.51.62/recordMe/play.swf?id=%1$s" loop="false" quality="high" bgcolor="#ffffff" width="%2$d" height="%3$d" name="videomat" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>',
			'default_ratio'	=> 1.5, // (300 / 200)
			'https_enabled'	=> false
		],
		'vimeo' => [
			'embed'			=> '<iframe src="//player.vimeo.com/video/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio' => 1.77777777777778, // (640 / 360)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#vimeo\.com/([\d]+)#is',
				'#vimeo\.com/channels/[\d\w-]+/([\d]+)#is'
			],
			'id_regex'		=> [
				'#^([\d]+)$#is'
			],
			'oembed'		=> '%4$s//vimeo.com/api/oembed.json?url=%1$s&width=%2$d&maxwidth=%2$d'
		],
		'vine' => [
			'embed'			=> '<iframe src="//vine.co/v/%1$s/embed/simple" width="%2$d" height="%3$d" frameborder="0"></iframe>',
			'default_width'	=> 640,
			'default_ratio' => 1, // (1 / 1)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#vine\.co/v/([a-zA-Z0-9]+)#is'
			],
			'id_regex'		=> [
				'#^([a-zA-Z0-9]+)$#is'
			]
		],
		'yahoo' => [
			'embed'			=> '<iframe src="//screen.yahoo.com/%1$s.html?format=embed" width="%2$d" height="%3$d" scrolling="no" frameborder="0" allowfullscreen="true" allowtransparency="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#screen\.yahoo\.com/([\w\d\-]+?-\d+).html#is'
			],
			'id_regex'		=> [
				'#^([\w\d\-]+?-\d+)$#is'
			]
		],
		'youtube' => [
			'embed'			=> '<iframe src="//www.youtube.com/embed/%1$s?%4$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#v=([\d\w-]+)(?:&\S+?)?#is',
				'#youtu\.be/([\d\w-]+)#is'
			],
			'id_regex'		=> [
				'#^([\d\w-]+)$#is'
			],
			'oembed'		=> [
				'http'	=> 'http://www.youtube.com/oembed?url=%1$s&width=%2$d&maxwidth=%2$d',
				'https'	=> 'http://www.youtube.com/oembed?scheme=https&url=%1$s&width=%2$d&maxwidth=%2$d'
			]
		],
		'youtubeplaylist' => [
			'embed'			=> '<iframe src="//www.youtube.com/embed/videoseries?list=%1$s&%4$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#list=([\d\w-]+)(?:&\S+?)?#is'
			],
			'id_regex'		=> [
				'#^([\d\w-]+)$#is'
			]
		],
		'youtubevideolist' => [
			'embed'			=> '<iframe src="//www.youtube.com/embed/%1$s?%4$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.77777777777778, // (16 / 9)
			'https_enabled'	=> true,
			'url_regex'		=> [
				'#playlist=([\d\w-]+)(?:&\S+?)?#is'
			],
			'id_regex'		=> [
				'#^([\d\w-]+)$#is'
			]
		],
		'youku' => [
			'embed'			=> '<iframe src="https://player.youku.com/embed/%1$s" width="%2$d" height="%3$d" frameborder="0" allowfullscreen="true"></iframe>',
			'default_width'	=> 640,
			'default_ratio'	=> 1.6,
			'https_enabled'	=> false,
			'url_regex'		=> [
				'#id_([\d\w-]+).html#is',
			],
			'id_regex'		=> [
				'#^(?:id_)?([\d\w-]+)$#is'
			]
		]
	];

	/**
	 * Mapping of host names to services
	 * @var array
	 */
	static private $serviceHostMap = [
		'archive.org'				=> 'archiveorg',
		'embed.bambuser.com'		=> ['bambuser', 'bambuser_channel'],
		'beam.pro' 					=> 'beam',
		'blip.tv'					=> 'blip',
		'bing.com'					=> 'bing',
		'collegehumor.com'			=> 'collegehumor',
		'dailymotion.com'			=> 'dailymotion',
		'divshare.com'				=> 'divshare',
		'funnyordie.com'			=> 'funnyordie',
		'gfycat.com'				=> 'gfycat',
		'hitbox.tv'					=> 'hitbox',
		'content.jwplatform.com'	=> 'jwplayer',
		'kickstarter.com'			=> 'kickstarter',
		'media.ccc.de'				=> 'mideacccde',
		'metacafe.com'				=> 'metacafe',
		'nicovideo.jp'				=> 'nico',
		'rutube.ru'					=> 'rutube',
		'teachertube.com'			=> 'teachertube',
		'ted.com'					=> 'ted',
		'tubitv.com'				=> 'tubitv',
		'tudou.com'					=> 'todou',
		'tvpot.daum.net'			=> 'tvpot',
		'twitch.tv'					=> ['twitch', 'twitchvod'],
		'89.160.51.62'				=> 'videomaten',
		'vimeo.com'					=> 'vimeo',
		'vine.co'					=> 'vine',
		'screen.yahoo.com'			=> 'yahoo',
		'youtube.com'				=> ['youtube', 'youtubeplaylist', 'youtubevideolist'],
		'youku.com'					=> 'youku'
	];

	/**
	 * This object instance's service information.
	 *
	 * @var		array
	 */
	private $service = [];

	/**
	 * Video ID
	 *
	 * @var		array
	 */
	private $id = false;

	/**
	 * Player Width
	 *
	 * @var		integer
	 */
	private $width = false;

	/**
	 * Player Height
	 *
	 * @var		integer
	 */
	private $height = false;

	/**
	 * Description Text
	 *
	 * @var		string
	 */
	private $description = false;

	/**
	 * Extra IDs that some services require.
	 *
	 * @var		array
	 */
	private $extraIDs = false;

	/**
	 * Extra URL Arguments that may be utilized by some services.
	 *
	 * @var		array
	 */
	private $urlArgs = false;

	/**
	 * Main Constructor
	 *
	 * @access	private
	 * @param	string	Service Name
	 * @return	void
	 */
	private function __construct($service) {
		$this->service = self::$services[$service];
	}

	/**
	 * Create a new object from a service name.
	 *
	 * @access	public
	 * @param	string	Service Name
	 * @return	mixed	New VideoService object or false on initialization error.
	 */
	static public function newFromName($service) {
		if (isset(self::$services[$service]))	{
			return new self($service);
		} else {
			return false;
		}
	}

	/**
	 * return the service host map array
	 * @return array $serviceHostMap
	 */
	public static function getServiceHostMap() {
		return self::$serviceHostMap;
	}

	/**
	 * return an array of defined services
	 *
	 * @return array $services
	 */
	public static function getAvailableServices() {
		return array_keys(self::$services);
	}

	/**
	 * Add a service
	 *
	 * @access	public
	 * @param	string	Service Name
	 * @param   mixed   args
	 */
	static public function addService($service, $args) {
		if (isset(self::$services[$service])) {
			throw new MWException("Service already already exists: $service");
		}
		self::$services[$service] = $args;
	}

	/**
	 * Return built HTML.
	 *
	 * @access	public
	 * @return	mixed	String HTML to output or false on error.
	 */
	public function getHtml() {
		if ($this->getVideoID() === false || $this->getWidth() === false || $this->getHeight() === false) {
			return false;
		}

		$html = false;
		if (isset($this->service['embed'])) {
			// Embed can be generated locally instead of calling out to the service to get it.
			$data = [
				$this->service['embed'],
				htmlentities($this->getVideoID(), ENT_QUOTES),
				$this->getWidth(),
				$this->getHeight(),
			];

			if ($this->getExtraIds() !== false) {
				foreach ($this->getExtraIds() as $extraId) {
					$data[] = htmlentities($extraId, ENT_QUOTES);
				}
			}

			$urlArgs = $this->getUrlArgs();
			if ($urlArgs !== false) {
				$data[] = $urlArgs;
			}

			$html = call_user_func_array('sprintf', $data);
		} elseif (isset($this->service['oembed'])) {
			// Call out to the service to get the embed HTML.
			if ($this->service['https_enabled']) {
				if (stristr($this->getVideoID(), 'https:') !== false) {
					$protocol = 'https:';
				} else {
					$protocol = 'http:';
				}
			}
			$url = sprintf(
				$this->service['oembed'],
				$this->getVideoID(),
				$this->getWidth(),
				$this->getHeight(),
				$protocol
			);
			$oEmbed = OEmbed::newFromRequest($url);
			if ($oEmbed !== false) {
				$html = $oEmbed->getHtml();
			}
		}

		return $html;
	}

	/**
	 * Return Video ID
	 *
	 * @access	public
	 * @return	mixed	Parsed Video ID or false for one that is not set.
	 */
	public function getVideoID() {
		return $this->id;
	}

	/**
	 * Set the Video ID for this video.
	 *
	 * @access	public
	 * @param	string	Video ID/URL
	 * @return	boolean	Success
	 */
	public function setVideoID($id) {
		$id = $this->parseVideoID($id);
		if ($id !== false) {
			$this->id = $id;
			return true;
		} else {
			return false;
		}
	}

	/**
	 * Parse the video ID/URL provided.
	 *
	 * @access	public
	 * @param	string	Video ID/URL
	 * @return	mixed	Parsed Video ID or false on failure.
	 */
	public function parseVideoID($id) {
		$id = trim($id);
		// URL regexes are put into the array first to prevent cases where the ID regexes might accidentally match an incorrect portion of the URL.
		$regexes = array_merge((array) $this->service['url_regex'], (array) $this->service['id_regex']);
		if (is_array($regexes) && count($regexes)) {
			foreach ($regexes as $regex) {
				if (preg_match($regex, $id, $matches)) {
					// Get rid of the full text match.
					array_shift($matches);

					$id = array_shift($matches);

					if (count($matches)) {
						$this->extraIDs = $matches;
					}

					return $id;
				}
			}
			// If nothing matches and matches are specified then return false for an invalid ID/URL.
			return false;
		} else {
			// Service definition has not specified a sanitization/validation regex.
			return $id;
		}
	}

	/**
	 * Return extra IDs.
	 *
	 * @access	public
	 * @return	boolean	Array of extra information or false if not set.
	 */
	public function getExtraIDs() {
		return $this->extraIDs;
	}

	/**
	 * Return the width.
	 *
	 * @access	public
	 * @return	mixed	Integer value or false for not set.
	 */
	public function getWidth() {
		return $this->width;
	}

	/**
	 * Set the width of the player.  This also will set the height automatically.
	 * Width will be automatically constrained to the minimum and maximum widths.
	 *
	 * @access	public
	 * @param	integer	Width
	 * @return	void
	 */
	public function setWidth($width = null) {
		global $wgEmbedVideoMinWidth, $wgEmbedVideoMaxWidth, $wgEmbedVideoDefaultWidth;

		if (!is_numeric($width)) {
			if ($width === null && $this->getDefaultWidth() !== false && $wgEmbedVideoDefaultWidth < 1) {
				$width = $this->getDefaultWidth();
			} else {
				$width = ($wgEmbedVideoDefaultWidth > 0 ? $wgEmbedVideoDefaultWidth : 640);
			}
		} else {
			$width = intval($width);
		}

		if ($wgEmbedVideoMaxWidth > 0 && $width > $wgEmbedVideoMaxWidth) {
			$width = $wgEmbedVideoMaxWidth;
		}

		if ($wgEmbedVideoMinWidth > 0 && $width < $wgEmbedVideoMinWidth) {
			$width = $wgEmbedVideoMinWidth;
		}
		$this->width = $width;

		if ($this->getHeight() === false) {
			$this->setHeight();
		}
	}

	/**
	 * Return the height.
	 *
	 * @access	public
	 * @return	mixed	Integer value or false for not set.
	 */
	public function getHeight() {
		return $this->height;
	}

	/**
	 * Set the height automatically by a ratio of the width or use the provided value.
	 *
	 * @access	public
	 * @param	mixed	[Optional] Height Value
	 * @return	void
	 */
	public function setHeight($height = null) {
		if ($height !== null && $height > 0) {
			$this->height = intval($height);
			return;
		}

		$ratio = 16 / 9;
		if ($this->getDefaultRatio() !== false) {
			$ratio = $this->getDefaultRatio();
		}
		$this->height = round($this->getWidth() / $ratio);
	}

	/**
	 * Return the optional URL arguments.
	 *
	 * @access	public
	 * @return	mixed	Integer value or false for not set.
	 */
	public function getUrlArgs() {
		if ($this->urlArgs !== false) {
			return http_build_query($this->urlArgs);
		}
	}

	/**
	 * Set URL Arguments to optionally add to the embed URL.
	 *
	 * @access	public
	 * @param	string	Raw Arguments
	 * @return	boolean	Success
	 */
	public function setUrlArgs($urlArgs) {
		if (!$urlArgs) {
			return true;
		}

		$urlArgs = urldecode($urlArgs);
		$_args = explode('&', $urlArgs);

		if (is_array($_args)) {
			foreach ($_args as $rawPair) {
				list($key, $value) = explode("=", $rawPair, 2);
				if (empty($key) || ($value === null || $value === '')) {
					return false;
				}
				$arguments[$key] = htmlentities($value, ENT_QUOTES);
			}
		} else {
			return false;
		}
		$this->urlArgs = $arguments;
		return true;
	}

	/**
	 * Is HTTPS enabled?
	 *
	 * @access	public
	 * @return	boolean
	 */
	public function isHttpsEnabled() {
		return (bool) $this->service['https_enabled'];
	}

	/**
	 * Return default width if set.
	 *
	 * @access	public
	 * @return	mixed	Integer width or false if not set.
	 */
	public function getDefaultWidth() {
		return ($this->service['default_width'] > 0 ? $this->service['default_width'] : false);
	}

	/**
	 * Return default ratio if set.
	 *
	 * @access	public
	 * @return	mixed	Integer ratio or false if not set.
	 */
	public function getDefaultRatio() {
		return ($this->service['default_ratio'] > 0 ? $this->service['default_ratio'] : false);
	}
}