Index: trunk/extensions/Video/VideoClass.php |
— | — | @@ -74,6 +74,42 @@ |
75 | 75 | protected $context; |
76 | 76 | |
77 | 77 | /** |
| 78 | + * Array of providers codes to classes |
| 79 | + * |
| 80 | + * @var array |
| 81 | + */ |
| 82 | + static $providers = array( |
| 83 | + //'archiveorg' => 'ArchiveOrgVideoProvider', // broken/dont know how this works |
| 84 | + 'bliptv' => 'BlipTVVideoProvider', |
| 85 | + 'dailymotion' => 'DailyMotionVideoProvider', |
| 86 | + 'gametrailers' => 'GametrailersVideoProvider', |
| 87 | + //'gamevideos' => 'GamevideosVideoProvider', // broken |
| 88 | + //'gogreentube' => 'GoGreenTubeVideoProvider', // Down |
| 89 | + 'google' => 'GoogleVideoProvider', |
| 90 | + 'hulu' => 'HuluVideoProvider', |
| 91 | + 'metacafe' => 'MetaCafeVideoProvider', |
| 92 | + 'movieclips' => 'MovieClipsVideoProvider', |
| 93 | + // I'd rather not wade through the shit that is MySpace to figure out |
| 94 | + // how videos work, someone else can do that.. |
| 95 | + //'myspace' => 'MySpaceVideoProvider', |
| 96 | + 'myvideo' => 'MyVideoVideoProvider', |
| 97 | + //'thenewsroom' => 'NewsRoomVideoProvider', // Website sucks too much |
| 98 | + 'sevenload' => 'SevenloadVideoProvider', |
| 99 | + 'southparkstudios' => 'SouthParkStudiosVideoProvider', |
| 100 | + 'youtube' => 'YouTubeVideoProvider', |
| 101 | + 'viddler' => 'ViddlerVideoProvider', |
| 102 | + 'vimeo' => 'VimeoVideoProvider', |
| 103 | + 'wegame' => 'WeGameVideoProvider', |
| 104 | + ); |
| 105 | + |
| 106 | + /** |
| 107 | + * Array of domain name to provider codes |
| 108 | + * |
| 109 | + * @var null |
| 110 | + */ |
| 111 | + static protected $providerDomains = null; |
| 112 | + |
| 113 | + /** |
78 | 114 | * Constructor -- create a new Video object from the given Title and set |
79 | 115 | * some member variables |
80 | 116 | * |
— | — | @@ -398,69 +434,13 @@ |
399 | 435 | * @return String: video embed code |
400 | 436 | */ |
401 | 437 | public function getEmbedCode() { |
402 | | - switch( $this->getType() ) { |
403 | | - case 'youtube': |
404 | | - $provider = new YouTubeVideo( $this ); |
405 | | - break; |
406 | | - case 'google': |
407 | | - $provider = new GoogleVideo( $this ); |
408 | | - break; |
409 | | - case 'metacafe': |
410 | | - $provider = new MetaCafeVideo( $this ); |
411 | | - break; |
412 | | - case 'myspace': |
413 | | - $provider = new MySpaceVideo( $this ); |
414 | | - break; |
415 | | - case 'dailymotion': |
416 | | - $provider = new DailyMotionVideo( $this ); |
417 | | - break; |
418 | | - case 'thenewsroom': |
419 | | - $provider = new NewsRoomVideo( $this ); |
420 | | - break; |
421 | | - case 'archiveorg': |
422 | | - $provider = new ArchiveOrgVideo( $this ); |
423 | | - break; |
424 | | - case 'bliptv': |
425 | | - $provider = new BlipTVVideo( $this ); |
426 | | - break; |
427 | | - case 'hulu': |
428 | | - $provider = new HuluVideo( $this ); |
429 | | - break; |
430 | | - case 'gametrailers': |
431 | | - $provider = new GametrailersVideo( $this ); |
432 | | - break; |
433 | | - case 'gamevideos': |
434 | | - $provider = new GamevideosVideo( $this ); |
435 | | - break; |
436 | | - case 'gogreentube': |
437 | | - $provider = new GoGreenTubeVideo( $this ); |
438 | | - break; |
439 | | - case 'movieclips': |
440 | | - $provider = new MovieClipsVideo( $this ); |
441 | | - break; |
442 | | - case 'myvideo': |
443 | | - $provider = new MyVideoVideo( $this ); |
444 | | - break; |
445 | | - case 'sevenload': |
446 | | - $provider = new SevenloadVideo( $this ); |
447 | | - break; |
448 | | - case 'southparkstudios': |
449 | | - $provider = new SouthParkStudiosVideo( $this ); |
450 | | - break; |
451 | | - case 'viddler': |
452 | | - $provider = new ViddlerVideo( $this ); |
453 | | - break; |
454 | | - case 'vimeo': |
455 | | - $provider = new VimeoVideo( $this ); |
456 | | - break; |
457 | | - case 'wegame': |
458 | | - $provider = new WeGameVideo( $this ); |
459 | | - break; |
460 | | - default: |
461 | | - $provider = new FlashVideo( $this ); |
462 | | - break; |
| 438 | + if ( !isset( self::$providers[$this->type] ) ) { |
| 439 | + return ''; |
463 | 440 | } |
464 | 441 | |
| 442 | + $class = self::$providers[$this->type]; |
| 443 | + $provider = new $class( $this ); |
| 444 | + |
465 | 445 | return $provider->getEmbedCode(); |
466 | 446 | } |
467 | 447 | |
— | — | @@ -509,6 +489,36 @@ |
510 | 490 | } |
511 | 491 | |
512 | 492 | /** |
| 493 | + * Populates the $providerDomains variable |
| 494 | + * |
| 495 | + * @return void |
| 496 | + */ |
| 497 | + protected static function getDomainsForProviders() { |
| 498 | + if ( self::$providerDomains !== null ) { |
| 499 | + return; |
| 500 | + } |
| 501 | + |
| 502 | + self::$providerDomains = array(); |
| 503 | + foreach ( self::$providers as $name => $class ) { |
| 504 | + $domains = $class::getDomains(); |
| 505 | + foreach ( $domains as $domain ) { |
| 506 | + self::$providerDomains[$domain] = $name; |
| 507 | + } |
| 508 | + } |
| 509 | + } |
| 510 | + |
| 511 | + /** |
| 512 | + * Returns if $haystack ends with $needle |
| 513 | + * |
| 514 | + * @param $haystack String |
| 515 | + * @param $needle String |
| 516 | + * @return bool |
| 517 | + */ |
| 518 | + protected static function endsWith( $haystack, $needle ) { |
| 519 | + return ( substr( $haystack, ( strlen( $needle ) * -1 ) ) === $needle ); |
| 520 | + } |
| 521 | + |
| 522 | + /** |
513 | 523 | * Figure out the provider's name (lowercased) from a given URL. |
514 | 524 | * |
515 | 525 | * @param $url String: URL to check |
— | — | @@ -516,85 +526,16 @@ |
517 | 527 | * it out |
518 | 528 | */ |
519 | 529 | public static function getProviderByURL( $url ) { |
520 | | - $text = preg_match( '/youtube\.com/i', $url ); |
521 | | - if( $text ) { |
522 | | - return 'youtube'; |
| 530 | + $host = parse_url( $url, PHP_URL_HOST ); |
| 531 | + |
| 532 | + self::getDomainsForProviders(); |
| 533 | + foreach ( self::$providerDomains as $domain => $provider ) { |
| 534 | + if ( self::endsWith( $host, $domain ) ) { |
| 535 | + return $provider; |
| 536 | + } |
523 | 537 | } |
524 | | - $text = preg_match( '/metacafe\.com/i', $url ); |
525 | | - if( $text ) { |
526 | | - return 'metacafe'; |
527 | | - } |
528 | | - $text = preg_match( '/google\.com/i', $url ); |
529 | | - if( $text ) { |
530 | | - return 'google'; |
531 | | - } |
532 | | - $text = preg_match( '/myspace(tv)?\.com/i', $url ); |
533 | | - if( $text ) { |
534 | | - return 'myspace'; |
535 | | - } |
536 | | - $text = preg_match( '/dailymotion\.com/i', $url ); |
537 | | - if( $text ) { |
538 | | - return 'dailymotion'; |
539 | | - } |
540 | | - $text = preg_match( '/thenewsroom\.com/i', $url ); |
541 | | - if( $text ) { |
542 | | - return 'thenewsroom'; |
543 | | - } |
544 | | - $text = preg_match( '/archive\.org/i', $url ); |
545 | | - if( $text ) { |
546 | | - return 'archiveorg'; |
547 | | - } |
548 | | - $text = preg_match( '/blip\.tv/i', $url ); |
549 | | - if( $text ) { |
550 | | - return 'bliptv'; |
551 | | - } |
552 | | - $text = preg_match( '/gametrailers\.com/i', $url ); |
553 | | - if( $text ) { |
554 | | - return 'gametrailers'; |
555 | | - } |
556 | | - $text = preg_match( '/gamevideos\.1up\.com/i', $url ); |
557 | | - if( $text ) { |
558 | | - return 'gamevideos'; |
559 | | - } |
560 | | - $text = preg_match( '/gogreentube\.com/i', $url ); |
561 | | - if( $text ) { |
562 | | - return 'gogreentube'; |
563 | | - } |
564 | | - $text = preg_match( '/hulu\.com/i', $url ); |
565 | | - if( $text ) { |
566 | | - return 'hulu'; |
567 | | - } |
568 | | - $text = preg_match( '/movieclips\.com/i', $url ); |
569 | | - if( $text ) { |
570 | | - return 'movieclips'; |
571 | | - } |
572 | | - $text = preg_match( '/myvideo\.de/i', $url ); |
573 | | - if( $text ) { |
574 | | - return 'myvideo'; |
575 | | - } |
576 | | - $text = preg_match( '/sevenload\.com/i', $url ); |
577 | | - if( $text ) { |
578 | | - return 'sevenload'; |
579 | | - } |
580 | | - $text = preg_match( '/southparkstudios\.com/i', $url ); |
581 | | - if( $text ) { |
582 | | - return 'southparkstudios'; |
583 | | - } |
584 | | - $text = preg_match( '/viddler\.com/i', $url ); |
585 | | - if( $text ) { |
586 | | - return 'viddler'; |
587 | | - } |
588 | | - $text = preg_match( '/vimeo\.com/i', $url ); |
589 | | - if( $text ) { |
590 | | - return 'vimeo'; |
591 | | - } |
592 | | - $text = preg_match( '/wegame\.com/i', $url ); |
593 | | - if( $text ) { |
594 | | - return 'wegame'; |
595 | | - } |
596 | | - if( !$text ) { |
597 | | - return 'unknown'; |
598 | | - } |
| 538 | + |
| 539 | + return 'unknown'; |
599 | 540 | } |
600 | 541 | |
601 | 542 | public function setWidth( $width ) { |
Index: trunk/extensions/Video/VideoPage.php |
— | — | @@ -232,7 +232,7 @@ |
233 | 233 | array(), |
234 | 234 | array( |
235 | 235 | 'wpTitle' => $this->video->getName(), |
236 | | - 'wpForReUpload' => 1, |
| 236 | + 'forReUpload' => 1, |
237 | 237 | ) |
238 | 238 | ); |
239 | 239 | $wgOut->addHTML( "<li>{$ulink}</li>" ); |
Index: trunk/extensions/Video/Video.php |
— | — | @@ -21,8 +21,8 @@ |
22 | 22 | // Extension credits that show up on Special:Version |
23 | 23 | $wgExtensionCredits['other'][] = array( |
24 | 24 | 'name' => 'Video', |
25 | | - 'version' => '1.3', |
26 | | - 'author' => array( 'David Pean', 'Jack Phoenix' ), |
| 25 | + 'version' => '1.4', |
| 26 | + 'author' => array( 'David Pean', 'Jack Phoenix', 'John Du Hart' ), |
27 | 27 | 'description' => 'Allows new Video namespace for embeddable media on supported sites', |
28 | 28 | 'url' => 'http://www.mediawiki.org/wiki/Extension:Video', |
29 | 29 | ); |
— | — | @@ -59,26 +59,27 @@ |
60 | 60 | $wgAutoloadClasses['Video'] = $dir . 'VideoClass.php'; |
61 | 61 | |
62 | 62 | // ...and the dozen different provider classes |
63 | | -$wgAutoloadClasses['ArchiveOrgVideo'] = $dir . 'providers/ArchiveOrgVideo.php'; |
64 | | -$wgAutoloadClasses['BlipTVVideo'] = $dir . 'providers/BlipTVVideo.php'; |
65 | | -$wgAutoloadClasses['DailyMotionVideo'] = $dir . 'providers/DailyMotionVideo.php'; |
66 | | -$wgAutoloadClasses['FlashVideo'] = $dir . 'providers/FlashVideo.php'; |
67 | | -$wgAutoloadClasses['GametrailersVideo'] = $dir . 'providers/GametrailersVideo.php'; |
68 | | -$wgAutoloadClasses['GamevideosVideo'] = $dir . 'providers/GamevideosVideo.php'; |
69 | | -$wgAutoloadClasses['GoGreenTubeVideo'] = $dir . 'providers/GoGreenTubeVideo.php'; |
70 | | -$wgAutoloadClasses['GoogleVideo'] = $dir . 'providers/GoogleVideo.php'; |
71 | | -$wgAutoloadClasses['HuluVideo'] = $dir . 'providers/HuluVideo.php'; |
72 | | -$wgAutoloadClasses['MetaCafeVideo'] = $dir . 'providers/MetaCafeVideo.php'; |
73 | | -$wgAutoloadClasses['MySpaceVideo'] = $dir . 'providers/MySpaceVideo.php'; |
74 | | -$wgAutoloadClasses['MovieClipsVideo'] = $dir . 'providers/MovieClipsVideo.php'; |
75 | | -$wgAutoloadClasses['MyVideoVideo'] = $dir . 'providers/MyVideoVideo.php'; |
76 | | -$wgAutoloadClasses['NewsRoomVideo'] = $dir . 'providers/NewsRoomVideo.php'; |
77 | | -$wgAutoloadClasses['SevenloadVideo'] = $dir . 'providers/SevenloadVideo.php'; |
78 | | -$wgAutoloadClasses['SouthParkStudiosVideo'] = $dir . 'providers/SouthParkStudiosVideo.php'; |
79 | | -$wgAutoloadClasses['ViddlerVideo'] = $dir . 'providers/ViddlerVideo.php'; |
80 | | -$wgAutoloadClasses['VimeoVideo'] = $dir . 'providers/VimeoVideo.php'; |
81 | | -$wgAutoloadClasses['WeGameVideo'] = $dir . 'providers/WeGameVideo.php'; |
82 | | -$wgAutoloadClasses['YouTubeVideo'] = $dir . 'providers/YouTubeVideo.php'; |
| 63 | +$wgAutoloadClasses['ArchiveOrgVideoProvider'] = $dir . 'providers/ArchiveOrgVideo.php'; |
| 64 | +$wgAutoloadClasses['BlipTVVideoProvider'] = $dir . 'providers/BlipTVVideo.php'; |
| 65 | +$wgAutoloadClasses['DailyMotionVideoProvider'] = $dir . 'providers/DailyMotionVideo.php'; |
| 66 | +$wgAutoloadClasses['BaseVideoProvider'] = $dir . 'providers/BaseVideoProvider.php'; |
| 67 | +$wgAutoloadClasses['GametrailersVideoProvider'] = $dir . 'providers/GametrailersVideo.php'; |
| 68 | +$wgAutoloadClasses['GamevideosVideoProvider'] = $dir . 'providers/GamevideosVideo.php'; |
| 69 | +$wgAutoloadClasses['GoGreenTubeVideoProvider'] = $dir . 'providers/GoGreenTubeVideo.php'; |
| 70 | +$wgAutoloadClasses['GoogleVideoProvider'] = $dir . 'providers/GoogleVideo.php'; |
| 71 | +$wgAutoloadClasses['HuluVideoProvider'] = $dir . 'providers/HuluVideo.php'; |
| 72 | +$wgAutoloadClasses['MetaCafeVideoProvider'] = $dir . 'providers/MetaCafeVideo.php'; |
| 73 | +$wgAutoloadClasses['MySpaceVideoProvider'] = $dir . 'providers/MySpaceVideo.php'; |
| 74 | +$wgAutoloadClasses['MovieClipsVideoProvider'] = $dir . 'providers/MovieClipsVideo.php'; |
| 75 | +$wgAutoloadClasses['MTVNetworksVideoProvider'] = $dir . 'providers/MTVNetworksVideo.php'; |
| 76 | +$wgAutoloadClasses['MyVideoVideoProvider'] = $dir . 'providers/MyVideoVideo.php'; |
| 77 | +$wgAutoloadClasses['NewsRoomVideoProvider'] = $dir . 'providers/NewsRoomVideo.php'; |
| 78 | +$wgAutoloadClasses['SevenloadVideoProvider'] = $dir . 'providers/SevenloadVideo.php'; |
| 79 | +$wgAutoloadClasses['SouthParkStudiosVideoProvider'] = $dir . 'providers/SouthParkStudiosVideo.php'; |
| 80 | +$wgAutoloadClasses['ViddlerVideoProvider'] = $dir . 'providers/ViddlerVideo.php'; |
| 81 | +$wgAutoloadClasses['VimeoVideoProvider'] = $dir . 'providers/VimeoVideo.php'; |
| 82 | +$wgAutoloadClasses['WeGameVideoProvider'] = $dir . 'providers/WeGameVideo.php'; |
| 83 | +$wgAutoloadClasses['YouTubeVideoProvider'] = $dir . 'providers/YouTubeVideo.php'; |
83 | 84 | |
84 | 85 | // User Interface stuff |
85 | 86 | $wgAutoloadClasses['VideoPage'] = $dir . 'VideoPage.php'; |
Index: trunk/extensions/Video/providers/GoGreenTubeVideo.php |
— | — | @@ -1,52 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -class GoGreenTubeVideo extends FlashVideo { |
5 | | - |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
9 | | - |
10 | | - public function __construct( $video ) { |
11 | | - if( !is_object( $video ) ) { |
12 | | - throw new MWException( 'GoGreenTubeVideo constructor given bogus video object.' ); |
13 | | - } |
14 | | - |
15 | | - $this->video =& $video; |
16 | | - $this->video->ratio = 432 / 394; // or the other way around... |
17 | | - $this->id = $this->extractID( $this->video->getURL() ); |
18 | | - $this->url = 'http://www.gogreentube.com/embed/' . $this->id; |
19 | | - return $this; |
20 | | - } |
21 | | - |
22 | | - public function getEmbedCode() { |
23 | | - $height = $this->video->getHeight(); |
24 | | - $width = $this->video->getWidth(); |
25 | | - $ggid = $this->extractID(); |
26 | | - $url = "http://www.gogreentube.com/embed/{$ggid}"; |
27 | | - $output = "<script type=\"text/javascript\" src=\"{$url}\"></script>"; |
28 | | - return $output; |
29 | | - } |
30 | | - |
31 | | - /** |
32 | | - * Extract the video ID from its URL. |
33 | | - * |
34 | | - * @return Integer: video ID |
35 | | - */ |
36 | | - private function extractID() { |
37 | | - $url = $this->video->getURL(); |
38 | | - |
39 | | - $id = $url; |
40 | | - |
41 | | - if( preg_match( '/^http:\/\/www\.gogreentube\.com\/watch\.php\?v=(.+)$/', $url, $preg ) ) { |
42 | | - $id = $preg[1]; |
43 | | - } elseif( preg_match( '/^http:\/\/www\.gogreentube\.com\/embed\/(.+)$/', $url, $preg ) ) { |
44 | | - $id = $preg[1]; |
45 | | - } |
46 | | - |
47 | | - preg_match( '/([0-9A-Za-z]+)/', $id, $preg ); |
48 | | - $id = $preg[1]; |
49 | | - |
50 | | - return $id; |
51 | | - } |
52 | | - |
53 | | -} |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/NewsRoomVideo.php |
— | — | @@ -1,12 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -class NewsRoomVideo extends FlashVideo { |
5 | | - |
6 | | - public function __construct( &$video ) { |
7 | | - parent::__construct( $video ); |
8 | | - $this->video->width = 300; |
9 | | - $this->video->height = 325; |
10 | | - $this->video->ratio = 300 / 325; |
11 | | - } |
12 | | - |
13 | | -} |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/GamevideosVideo.php |
— | — | @@ -1,60 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -class GamevideosVideo extends FlashVideo { |
5 | | - |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
9 | | - |
10 | | - public function __construct( $video ) { |
11 | | - if( !is_object( $video ) ) { |
12 | | - throw new MWException( 'GamevideosVideo constructor given bogus video object.' ); |
13 | | - } |
14 | | - |
15 | | - $this->video =& $video; |
16 | | - $this->video->ratio = 500 / 319; |
17 | | - $this->id = $this->extractID( $this->video->getURL() ); |
18 | | - $this->url = 'http://gamevideos.1up.com/video/id/' . $this->id; |
19 | | - return $this; |
20 | | - } |
21 | | - |
22 | | - public function getEmbedCode() { |
23 | | - $height = $this->video->getHeight(); |
24 | | - $width = $this->video->getWidth(); |
25 | | - $output = '<embed wmode="transparent" type="application/x-shockwave-flash" width="' . $width . '" height="' . $height . '" src="http://gamevideos.1up.com/swf/gamevideos12.swf?embedded=1&fullscreen=1&autoplay=0&src=http://gamevideos.1up.com/do/videoListXML%3Fid%3D' . $this->id . '%26adPlay%3Dtrue" align="middle"></embed>'; |
26 | | - return $output; |
27 | | - } |
28 | | - |
29 | | - /** |
30 | | - * Extract the video ID from its URL. |
31 | | - * Copypasted from WikiaVideo's VideoPage.php's parseUrl(). |
32 | | - * |
33 | | - * @return Integer: video ID |
34 | | - */ |
35 | | - private function extractID() { |
36 | | - $url = $this->video->getURL(); |
37 | | - $url = trim( $url ); |
38 | | - |
39 | | - $fixed_url = strtoupper( $url ); |
40 | | - $test = strpos( $fixed_url, 'HTTP://' ); |
41 | | - if( !false === $test ) { |
42 | | - return false; |
43 | | - } |
44 | | - |
45 | | - $fixed_url = str_replace( 'HTTP://', '', $fixed_url ); |
46 | | - $fixed_parts = explode( '/', $fixed_url ); |
47 | | - $fixed_url = $fixed_parts[0]; |
48 | | - |
49 | | - $id = ''; |
50 | | - $text = strpos( $fixed_url, 'GAMEVIDEOS.1UP.COM' ); |
51 | | - if( $text !== false ) { |
52 | | - $parsed = explode( '/', $url ); |
53 | | - if( is_array( $parsed ) ) { |
54 | | - $id = array_pop( $parsed ); |
55 | | - } |
56 | | - } |
57 | | - |
58 | | - return $id; |
59 | | - } |
60 | | - |
61 | | -} |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/ArchiveOrgVideo.php |
— | — | @@ -1,52 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -class ArchiveOrgVideo extends FlashVideo { |
5 | | - |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
9 | | - |
10 | | - public function __construct( $video ) { |
11 | | - if( !is_object( $video ) ) { |
12 | | - throw new MWException( 'ArchiveOrgVideo constructor given bogus video object.' ); |
13 | | - } |
14 | | - |
15 | | - $this->video =& $video; |
16 | | - $this->video->ratio = 320 / 263; // or the other way around :) --Jack |
17 | | - $this->id = $this->extractID( $this->video->getURL() ); |
18 | | - $this->url = "http://www.archive.org/download/{$this->id}.flv"; |
19 | | - return $this; |
20 | | - } |
21 | | - |
22 | | - public function getEmbedCode() { |
23 | | - $height = $this->video->getHeight(); |
24 | | - $width = $this->video->getWidth(); |
25 | | - $aovid = $this->extractID(); |
26 | | - $url = "http://www.archive.org/download/{$aovid}.flv"; |
27 | | - $output = "<object type=\"application/x-shockwave-flash\" data=\"http://www.archive.org/flv/FlowPlayerWhite.swf\" width=\"{$width}\" height=\"{$height}\"> |
28 | | - <param name=\"movie\" value=\"http://www.archive.org/flv/FlowPlayerWhite.swf\"/><param name=\"flashvars\" value=\"config={loop: false, videoFile: '{$url}', autoPlay: false}\"/> |
29 | | - </object>"; |
30 | | - return $output; |
31 | | - } |
32 | | - |
33 | | - /** |
34 | | - * Extract the video ID from its URL. |
35 | | - * |
36 | | - * @return Integer: video ID |
37 | | - */ |
38 | | - private function extractID() { |
39 | | - $url = $this->video->getURL(); |
40 | | - |
41 | | - $id = $url; |
42 | | - |
43 | | - if ( preg_match( '/http:\/\/www\.archive\.org\/download\/(.+)\.flv$/', $url, $preg ) ) { |
44 | | - $id = $preg[1]; |
45 | | - } |
46 | | - |
47 | | - preg_match( '/([0-9A-Za-z_\/.]+)/', $id, $preg ); |
48 | | - $id = $preg[1]; |
49 | | - |
50 | | - return $id; |
51 | | - } |
52 | | - |
53 | | -} |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/FlashVideo.php |
— | — | @@ -1,29 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -class FlashVideo { |
5 | | - |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
9 | | - |
10 | | - public function __construct( $video ) { |
11 | | - if( !is_object( $video ) ) { |
12 | | - throw new MWException( 'FlashVideo constructor given bogus video object.' ); |
13 | | - } |
14 | | - |
15 | | - $this->video =& $video; |
16 | | - $this->url = $this->video->getURL(); |
17 | | - return $this; |
18 | | - } |
19 | | - |
20 | | - public function getEmbedCode() { |
21 | | - $output = "<object width=\"{$this->video->getWidth()}px\" height=\"{$this->video->getHeight()}px\">"; |
22 | | - $output .= "<param name=\"movie\" value=\"{$this->url}\"></param>"; |
23 | | - $output .= '<param name="wmode" value="transparent"></param>'; |
24 | | - $output .= "<embed wmode=\"transparent\" base=\".\" allowScriptAccess=\"always\" src=\"{$this->url}\" type=\"application/x-shockwave-flash\" width=\"{$this->video->getWidth()}px\" height=\"{$this->video->getHeight()}px\">"; |
25 | | - $output .= '</embed>'; |
26 | | - $output .= '</object>'; |
27 | | - return $output; |
28 | | - } |
29 | | - |
30 | | -} |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/MySpaceVideo.php |
— | — | @@ -1,30 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -class MySpaceVideo extends FlashVideo { |
5 | | - |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
9 | | - |
10 | | - public function __construct( $video ) { |
11 | | - if( !is_object( $video ) ) { |
12 | | - throw new MWException( 'MySpace constructor given bogus video object.' ); |
13 | | - } |
14 | | - $this->video =& $video; |
15 | | - $this->video->ratio = 430/346; |
16 | | - $this->id = $this->extractID( $this->video->getURL() ); |
17 | | - $this->url = "http://lads.myspace.com/videos/vplayer.swf?m={$this->id}&v=2&type=video"; |
18 | | - return $this; |
19 | | - } |
20 | | - |
21 | | - private function extractID() { |
22 | | - $url = $this->video->getURL(); |
23 | | - //http://myspacetv.com/index.cfm?fuseaction=vids.individual&videoid=1388509 |
24 | | - //http://lads.myspace.com/videos/vplayer.swf?m=1505336&v=2&type=video |
25 | | - $id = preg_replace( "%http\:\/\/(vids\.|www\.)?myspace(tv)?\.com/index\.cfm\?fuseaction=vids\.individual&VideoID=%i", '', $url ); |
26 | | - $id = preg_replace( "%http\:\/\/(vids\.|www\.|lads\.)?myspace(tv)?\.com\/videos\/vplayer\.swf\?m=%i", '', $id ); |
27 | | - //$id = preg_replace( "%&v=2&type=video%i", '', $id ); |
28 | | - return $id; |
29 | | - } |
30 | | - |
31 | | -} |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/MTVNetworksVideo.php |
— | — | @@ -0,0 +1,9 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +abstract class MTVNetworksVideoProvider extends BaseVideoProvider { |
| 5 | + protected $embedTemplate = '<embed src="http://media.mtvnservices.com/$video_id" width="$width" height="$height" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" base="." flashVars=""></embed>'; |
| 6 | + |
| 7 | + protected function getRatio() { |
| 8 | + return 512 / 288; |
| 9 | + } |
| 10 | +} |
Index: trunk/extensions/Video/providers/MetaCafeVideo.php |
— | — | @@ -1,27 +1,15 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class MetaCafeVideo extends FlashVideo { |
| 4 | +class MetaCafeVideoProvider extends BaseVideoProvider { |
| 5 | + protected $videoIdRegex = '#/watch/(\d+)/#'; |
| 6 | + // heh, the URL needed some text to work :) |
| 7 | + protected $embedTemplate = '<embed flashVars="playerVars=autoPlay=no" src="http://www.metacafe.com/fplayer/$video_id/johnduhart_was_here.swf" width="$width" height="$height" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" name="Metacafe_$video_id" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>'; |
5 | 8 | |
6 | | - public function __construct( &$video ) { |
7 | | - parent::__construct( $video ); |
8 | | - $this->video->ratio = 400/345; |
9 | | - $this->url = $this->video->getURL(); |
10 | | - $this->extractID( $this->video->getURL() ); |
| 9 | + protected function getRatio() { |
| 10 | + return 400 / 345; |
11 | 11 | } |
12 | 12 | |
13 | | - private function extractID() { |
14 | | - // Standard Metacafe browser URL |
15 | | - $url = $this->video->getURL(); |
16 | | - $standard_inurl = strpos( strtoupper( $url ), 'HTTP://WWW.METACAFE.COM/WATCH/' ); |
17 | | - |
18 | | - if( $standard_inurl !== false ) { |
19 | | - $id = substr( $url, $standard_inurl + strlen( 'HTTP://WWW.METACAFE.COM/WATCH/' ), strlen( $url ) ); |
20 | | - $last_char = substr( $id, -1 ,1 ); |
21 | | - |
22 | | - if( $last_char == '/' ) { |
23 | | - $id = substr( $id, 0, strlen( $id )-1 ); |
24 | | - } |
25 | | - $this->url = "http://www.metacafe.com/fplayer/{$id}.swf"; |
26 | | - } |
| 13 | + public static function getDomains() { |
| 14 | + return array( 'metacafe.com' ); |
27 | 15 | } |
28 | 16 | } |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/WeGameVideo.php |
— | — | @@ -1,50 +1,14 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class WeGameVideo extends FlashVideo { |
| 4 | +class WeGameVideoProvider extends BaseVideoProvider { |
| 5 | + protected $videoIdRegex = '#/watch/([a-zA-Z0-9_\-]+)/#'; |
| 6 | + protected $embedTemplate = '<object width="$width" height="$height"><param name="movie" value="http://www.wegame.com/static/flash/player.swf?xmlrequest=http://www.wegame.com/player/video/$video_id"></param><param name="flashVars" value="xmlrequest=http://www.wegame.com/player/video/$video_id&embedPlayer=true"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.wegame.com/static/flash/player.swf?xmlrequest=http://www.wegame.com/player/video/$video_id&embedPlayer=true" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="$width" height="$height"></embed></object>'; |
5 | 7 | |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
9 | | - |
10 | | - public function __construct( $video ) { |
11 | | - if( !is_object( $video ) ) { |
12 | | - throw new MWException( 'WeGameVideo constructor given bogus video object.' ); |
13 | | - } |
14 | | - |
15 | | - $this->video =& $video; |
16 | | - $this->video->ratio = 488 / 387; // or the other way around... |
17 | | - $this->id = $this->extractID( $this->video->getURL() ); |
18 | | - $this->url = 'http://www.wegame.com/watch/' . $this->id; |
19 | | - return $this; |
| 8 | + public static function getDomains() { |
| 9 | + return array( 'wegame.com' ); |
20 | 10 | } |
21 | 11 | |
22 | | - public function getEmbedCode() { |
23 | | - $height = $this->video->getHeight(); |
24 | | - $width = $this->video->getWidth(); |
25 | | - $weid = $this->extractID(); |
26 | | - $output = "<object type=\"application/x-shockwave-flash\" data=\"http://www.wegame.com/static/flash/player2.swf\" width=\"{$width}\" height=\"{$height}\">"; |
27 | | - $output .= "<param name=\"flashvars\" value=\"tag={$weid}\"/></object>"; |
28 | | - return $output; |
| 12 | + protected function getRatio() { |
| 13 | + return 488 / 387; |
29 | 14 | } |
30 | | - |
31 | | - /** |
32 | | - * Extract the video ID from its URL. |
33 | | - * |
34 | | - * @return Integer: video ID |
35 | | - */ |
36 | | - private function extractID() { |
37 | | - $url = $this->video->getURL(); |
38 | | - |
39 | | - $id = $url; |
40 | | - |
41 | | - if ( preg_match( '/^http:\/\/www\.wegame\.com\/watch\/(.+)\/$/', $url, $preg ) ) { |
42 | | - $id = $preg[1]; |
43 | | - } |
44 | | - |
45 | | - preg_match( '/([0-9A-Za-z_-]+)/', $id, $preg ); |
46 | | - $id = $preg[1]; |
47 | | - |
48 | | - return $id; |
49 | | - } |
50 | | - |
51 | 15 | } |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/MovieClipsVideo.php |
— | — | @@ -4,61 +4,22 @@ |
5 | 5 | * @author William Lee <wlee@wikia-inc.com> |
6 | 6 | * @see http://trac.wikia-code.com/changeset/39940 |
7 | 7 | */ |
8 | | -class MovieClipsVideo extends FlashVideo { |
9 | 8 | |
10 | | - var $video, |
11 | | - $id, |
12 | | - $url; |
| 9 | +class MovieClipsVideoProvider extends BaseVideoProvider { |
| 10 | + protected $videoIdRegex = '#/([a-zA-Z0-9]+)-.*?#'; |
| 11 | + protected $embedTemplate = '<object width="$width" height="$height" type="application/x-shockwave-flash" data="http://static.movieclips.com/embedplayer.swf?config=http://config.movieclips.com/player/config/embed/$video_id/%3Floc%3DUS&endpoint=http://movieclips.com/api/v1/player/test/action/&start=0&v=1.0.15" style="display:block; overflow:hidden;"> |
| 12 | +<param name="movie" value="http://static.movieclips.com/embedplayer.swf?config=http://config.movieclips.com/player/config/embed/$video_id/%3Floc%3DUS&endpoint=http://movieclips.com/api/v1/player/test/action/&start=0&v=1.0.15" /> |
| 13 | +<param name="wmode" value="transparent" /> |
| 14 | +<param name="allowscriptaccess" value="always" /> |
| 15 | +<param name="allowfullscreen" value="true" /> |
| 16 | +<embed src="http://static.movieclips.com/embedplayer.swf?config=http://config.movieclips.com/player/config/embed/$video_id/%3Floc%3DUS&endpoint=http://movieclips.com/api/v1/player/test/action/&start=0&v=1.0.15" type="application/x-shockwave-flash" width="$width" height="$height" wmode="transparent" allowscriptaccess="always" allowfullscreen="true"></embed> |
| 17 | +</object>'; |
13 | 18 | |
14 | | - public function __construct( $video ) { |
15 | | - if( !is_object( $video ) ) { |
16 | | - throw new MWException( 'MovieClipsVideo constructor given bogus video object.' ); |
17 | | - } |
18 | | - |
19 | | - $this->video =& $video; |
20 | | - $this->video->ratio = 560 / 304; |
21 | | - $this->id = $this->extractID( $this->video->getURL() ); |
22 | | - $this->url = $url = 'http://movieclips.com/' . $this->id; |
23 | | - return $this; |
| 19 | + protected function getRatio() { |
| 20 | + return 560 / 304; |
24 | 21 | } |
25 | 22 | |
26 | | - public function getEmbedCode() { |
27 | | - $height = $this->video->getHeight(); |
28 | | - $width = $this->video->getWidth(); |
29 | | - $url = 'http://movieclips.com/e/' . $this->id . '/'; |
30 | | - $output = "<embed src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" wmode=\"transparent\" allowScriptAccess=\"always\" allowfullscreen=\"true\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"> </embed>"; |
31 | | - return $output; |
| 23 | + public static function getDomains() { |
| 24 | + return array( 'movieclips.com' ); |
32 | 25 | } |
33 | | - |
34 | | - /** |
35 | | - * Extract the video ID from its URL. |
36 | | - * |
37 | | - * @return Mixed: video ID (integer) on success, boolean false on failure |
38 | | - */ |
39 | | - private function extractID() { |
40 | | - $url = $this->video->getURL(); |
41 | | - $url = trim( $url ); |
42 | | - |
43 | | - $fixed_url = strtoupper( $url ); |
44 | | - $test = strpos( $fixed_url, 'HTTP://' ); |
45 | | - if( !false === $test ) { |
46 | | - return false; |
47 | | - } |
48 | | - |
49 | | - $fixed_url = str_replace( 'HTTP://', '', $fixed_url ); |
50 | | - $fixed_parts = explode( '/', $fixed_url ); |
51 | | - $fixed_url = $fixed_parts[0]; |
52 | | - |
53 | | - $id = ''; |
54 | | - $text = strpos( $fixed_url, 'MOVIECLIPS.COM' ); |
55 | | - if( $text !== false ) { |
56 | | - $url = trim( $url, '/' ); |
57 | | - $parsed = explode( '/', $url ); |
58 | | - if( is_array( $parsed ) ) { |
59 | | - $id = array_pop( $parsed ); |
60 | | - } |
61 | | - } |
62 | | - |
63 | | - return $id; |
64 | | - } |
65 | 26 | } |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/GoogleVideo.php |
— | — | @@ -1,36 +1,15 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class GoogleVideo extends FlashVideo { |
| 4 | +class GoogleVideoProvider extends BaseVideoProvider { |
5 | 5 | |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
| 6 | + protected $videoIdRegex = '#docid=(-?\d+)#i'; |
| 7 | + protected $embedTemplate = '<embed id=VideoPlayback src=http://video.google.com/googleplayer.swf?docid=-5227581495321189338&hl=en&fs=true style=width:$widthpx;height:$heightpx allowFullScreen=true allowScriptAccess=always type=application/x-shockwave-flash> </embed>'; |
9 | 8 | |
10 | | - public function __construct( $video ) { |
11 | | - if( !is_object( $video ) ) { |
12 | | - throw new MWException( 'GoogleVideo constructor given bogus video object.' ); |
13 | | - } |
14 | | - $this->video =& $video; |
15 | | - $this->video->ratio = 425/355; |
16 | | - $this->id = $this->extractID( $this->video->getURL() ); |
17 | | - $this->url = "http://video.google.com/googleplayer.swf?docId={$this->id}"; |
18 | | - return $this; |
| 9 | + public static function getDomains() { |
| 10 | + return array( 'video.google.com' ); |
19 | 11 | } |
20 | 12 | |
21 | | - private function extractID() { |
22 | | - // Standard Google browser URL |
23 | | - $url = $this->video->getURL(); |
24 | | - $standard_inurl = strpos( strtoupper( $url ), 'VIDEOPLAY?DOCID=' ); |
25 | | - |
26 | | - if( $standard_inurl !== false ) { |
27 | | - $id = substr( $url, $standard_inurl + strlen( 'VIDEOPLAY?DOCID=' ), strlen( $url ) ); |
28 | | - } |
29 | | - if( !$id ) { |
30 | | - $id_test = preg_replace( "%http\:\/\/video\.google\.com\/googleplayer\.swf\?docId=%i", '', $url ); |
31 | | - if( $id_test != $url ) { |
32 | | - $id = $id_test; |
33 | | - } |
34 | | - } |
35 | | - return $id; |
| 13 | + protected function getRatio() { |
| 14 | + return 425 / 355; |
36 | 15 | } |
37 | 16 | } |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/MyVideoVideo.php |
— | — | @@ -1,63 +1,14 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class MyVideoVideo extends FlashVideo { |
| 4 | +class MyVideoVideoProvider extends BaseVideoProvider { |
| 5 | + protected $videoIdRegex = '#/watch/(\d+)/?#'; |
| 6 | + protected $embedTemplate = '<object width="$width" height="$height"><param name="movie" value="http://www.myvideo.de/movie/$video_id"></param><param name="AllowFullscreen" value="true"></param><param name="AllowScriptAccess" value="always"></param><embed src="http://www.myvideo.de/movie/$video_id" width="$width" height="$height" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true"></embed></object>'; |
5 | 7 | |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
9 | | - |
10 | | - public function __construct( $video ) { |
11 | | - if( !is_object( $video ) ) { |
12 | | - throw new MWException( 'MyVideoVideo constructor given bogus video object.' ); |
13 | | - } |
14 | | - |
15 | | - $this->video =& $video; |
16 | | - $this->video->ratio = 470 / 406; |
17 | | - $this->id = $this->extractID( $this->video->getURL() ); |
18 | | - $this->url = 'http://www.myvideo.de/watch/' . $this->id; |
19 | | - return $this; |
| 8 | + protected function getRatio() { |
| 9 | + return 470 / 406; |
20 | 10 | } |
21 | 11 | |
22 | | - public function getEmbedCode() { |
23 | | - $height = $this->video->getHeight(); |
24 | | - $width = $this->video->getWidth(); |
25 | | - $output = "<object style=\"width:{$width}px;height:{$height}px;\" type=\"application/x-shockwave-flash\" data=\"http://www.myvideo.de/movie/{$this->id}\">"; |
26 | | - $output .= '<param name="wmode" value="transparent">'; |
27 | | - $output .= '<param name="movie" value="http://www.myvideo.de/movie/' . $this->id . '" />'; |
28 | | - $output .= '<param name="AllowFullscreen?" value="true" /> </object>'; |
29 | | - return $output; |
| 12 | + public static function getDomains() { |
| 13 | + return array( 'myvideo.de' ); |
30 | 14 | } |
31 | | - |
32 | | - /** |
33 | | - * Extract the video ID from its URL. |
34 | | - * Copypasted from WikiaVideo's VideoPage.php's parseUrl(). |
35 | | - * |
36 | | - * @return Integer: video ID |
37 | | - */ |
38 | | - private function extractID() { |
39 | | - $url = $this->video->getURL(); |
40 | | - $url = trim( $url ); |
41 | | - |
42 | | - $fixed_url = strtoupper( $url ); |
43 | | - $test = strpos( $fixed_url, 'HTTP://' ); |
44 | | - if( !false === $test ) { |
45 | | - return false; |
46 | | - } |
47 | | - |
48 | | - $fixed_url = str_replace( 'HTTP://', '', $fixed_url ); |
49 | | - $fixed_parts = explode( '/', $fixed_url ); |
50 | | - $fixed_url = $fixed_parts[0]; |
51 | | - |
52 | | - $id = ''; |
53 | | - $text = strpos( $fixed_url, 'MYVIDEO.DE' ); |
54 | | - if( $text !== false ) { |
55 | | - $parsed = explode( '/', $url ); |
56 | | - if( is_array( $parsed ) ) { |
57 | | - $id = array_pop( $parsed ); |
58 | | - } |
59 | | - } |
60 | | - |
61 | | - return $id; |
62 | | - } |
63 | | - |
64 | 15 | } |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/HuluVideo.php |
— | — | @@ -4,124 +4,45 @@ |
5 | 5 | * @author William Lee <wlee@wikia-inc.com> |
6 | 6 | * @see http://trac.wikia-code.com/changeset/38530 |
7 | 7 | */ |
8 | | -class HuluVideo extends FlashVideo { |
| 8 | +class HuluVideoProvider extends BaseVideoProvider { |
| 9 | + protected $embedTemplate = '<object width="$width" height="$height"><param name="movie" value="$video_id"></param><param name="allowFullScreen" value="true"></param><embed src="$video_id" type="application/x-shockwave-flash" width="$width" height="$height" allowFullScreen="true"></embed></object>'; |
9 | 10 | |
10 | | - var $video, |
11 | | - $id, |
12 | | - $url; |
13 | | - |
14 | | - public function __construct( $video ) { |
15 | | - if( !is_object( $video ) ) { |
16 | | - throw new MWException( 'HuluVideo constructor given bogus video object.' ); |
17 | | - } |
18 | | - |
19 | | - $this->video =& $video; |
20 | | - $this->video->ratio = 512 / 296; |
21 | | - $this->id = $this->extractID( $this->video->getURL() ); |
22 | | - $this->url = 'http://www.hulu.com/watch/' . $this->id; |
23 | | - return $this; |
| 11 | + public static function getDomains() { |
| 12 | + return array( 'hulu.com' ); |
24 | 13 | } |
25 | 14 | |
26 | | - public function getEmbedCode() { |
27 | | - $height = $this->video->getHeight(); |
28 | | - $width = $this->video->getWidth(); |
29 | | - $data = $this->getData(); |
30 | | - $url = 'http://www.hulu.com/embed/' . $data['embedId']; |
31 | | - $output = "<embed src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" wmode=\"transparent\" allowScriptAccess=\"always\" allowfullscreen=\"true\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"> </embed>"; |
32 | | - return $output; |
| 15 | + protected function getRatio() { |
| 16 | + return 512 / 296; |
33 | 17 | } |
34 | 18 | |
35 | | - /** |
36 | | - * Extract the video ID from its URL. |
37 | | - * |
38 | | - * @return Mixed: video ID (integer) on success, boolean false on failure |
39 | | - */ |
40 | | - private function extractID() { |
41 | | - $url = $this->video->getURL(); |
42 | | - $url = trim( $url ); |
| 19 | + protected function extractVideoId( $url ) { |
| 20 | + global $wgMemc; |
43 | 21 | |
44 | | - $fixed_url = strtoupper( $url ); |
45 | | - $test = strpos( $fixed_url, 'HTTP://' ); |
46 | | - if( !false === $test ) { |
47 | | - return false; |
| 22 | + if ( !preg_match( '#/watch/(?<id>\d+)/#', $url, $matches) ) { |
| 23 | + return null; |
48 | 24 | } |
49 | 25 | |
50 | | - $fixed_url = str_replace( 'HTTP://', '', $fixed_url ); |
51 | | - $fixed_parts = explode( '/', $fixed_url ); |
52 | | - $fixed_url = $fixed_parts[0]; |
| 26 | + $videoId = $matches['id']; |
53 | 27 | |
54 | | - $id = ''; |
55 | | - $text = strpos( $fixed_url, 'HULU.COM' ); |
56 | | - if( $text !== false ) { |
57 | | - // Hulu goes like |
58 | | - // http://www.hulu.com/watch/252775/[seo terms] |
59 | | - $url = trim( $url, '/' ); |
60 | | - $parsed = explode( '/', $url ); |
61 | | - if( is_array( $parsed ) ) { |
62 | | - // $id is a number, and it is either last or second to last element of $parsed |
63 | | - $last = explode( '?', array_pop( $parsed ) ); |
64 | | - $last = $last[0]; |
65 | | - if ( is_numeric( $last ) ) { |
66 | | - $id = $last; |
67 | | - } else { |
68 | | - $id = array_pop( $parsed ); |
69 | | - //$seo = $last; |
70 | | - } |
71 | | - /* |
72 | | - $this->mData = null; // getData() works only if mData is null |
73 | | - $huluData = $this->getData(); |
74 | | - $this->mData = array(); |
75 | | - if ( is_array( $huluData ) ) { |
76 | | - foreach ( $huluData as $key => $value ) { |
77 | | - $this->mData[] = $value; |
78 | | - } |
79 | | - } |
80 | | - if ( !empty( $seo ) ) { |
81 | | - $this->mData[] = $seo; |
82 | | - } |
83 | | - */ |
84 | | - } |
| 28 | + $cacheKey = wfMemcKey( 'video', 'hulu', $videoId ); |
| 29 | + $cachedEmbedId = $wgMemc->get( $cacheKey ); |
| 30 | + |
| 31 | + if ( $cachedEmbedId !== false ) { |
| 32 | + return $cachedEmbedId; |
85 | 33 | } |
86 | 34 | |
87 | | - return $id; |
88 | | - } |
| 35 | + $apiUrl = 'http://www.hulu.com/api/oembed.json?url=' . urlencode( $url ); |
| 36 | + $apiResult = Http::get( $apiUrl ); |
89 | 37 | |
90 | | - private function getData() { |
91 | | - $data = array(); |
| 38 | + if ( $apiResult === false ) { |
| 39 | + return null; |
| 40 | + } |
92 | 41 | |
93 | | - /* |
94 | | - if ( !empty( $this->mData ) ) { |
95 | | - // metadata could be a one-element array, expressed in serialized form. |
96 | | - // If so, deserialize |
97 | | - if ( sizeof( $this->mData ) == 1 ) { |
98 | | - $this->mData = explode( ',', $this->mData[0] ); |
99 | | - } |
| 42 | + $apiResult = FormatJson::decode( $apiResult, true ); |
| 43 | + $embedId = $apiResult['embed_url']; |
100 | 44 | |
101 | | - $data['embedId'] = $this->mData[0]; |
102 | | - $data['thumbnailUrl'] = $this->mData[1]; |
103 | | - $data['videoName'] = $this->mData[2]; |
104 | | - if ( sizeof( $this->mData ) > 3 ) { |
105 | | - $data['seo'] = $this->mData[3]; |
106 | | - } |
107 | | - } else {*/ |
108 | | - wfSuppressWarnings(); |
109 | | - $file = Http::get( |
110 | | - 'http://www.hulu.com/api/oembed.xml?url=' . |
111 | | - urlencode( 'http://www.hulu.com/watch/' . $this->id ), false ); |
112 | | - wfRestoreWarnings(); |
| 45 | + $wgMemc->set( $cacheKey, $embedId, 60 * 60 * 24 ); |
113 | 46 | |
114 | | - if ( $file ) { |
115 | | - $doc = new DOMDocument( '1.0', 'UTF-8' ); |
116 | | - wfSuppressWarnings(); |
117 | | - $doc->loadXML( $file ); |
118 | | - wfRestoreWarnings(); |
119 | | - $embedUrl = trim( $doc->getElementsByTagName( 'embed_url' )->item( 0 )->textContent ); |
120 | | - $embedUrlParts = explode( '/', $embedUrl ); |
121 | | - $data['embedId'] = array_pop( $embedUrlParts ); |
122 | | - $data['thumbnailUrl'] = trim( $doc->getElementsByTagName( 'thumbnail_url' )->item( 0 )->textContent ); |
123 | | - $data['videoName'] = trim( $doc->getElementsByTagName( 'title' )->item( 0 )->textContent ); |
124 | | - } |
125 | | - /*}*/ |
126 | | - return $huluData; |
| 47 | + return $embedId; |
127 | 48 | } |
128 | 49 | } |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/GametrailersVideo.php |
— | — | @@ -1,67 +1,27 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class GametrailersVideo extends FlashVideo { |
5 | | - |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
9 | | - |
10 | | - public function __construct( $video ) { |
11 | | - if( !is_object( $video ) ) { |
12 | | - throw new MWException( 'GametrailersVideo constructor given bogus video object.' ); |
13 | | - } |
14 | | - |
15 | | - $this->video =& $video; |
16 | | - $this->video->ratio = 480 / 392; |
17 | | - $this->id = $this->extractID( $this->video->getURL() ); |
18 | | - $this->url = 'http://www.gametrailers.com/video/play/' . $this->id; |
19 | | - return $this; |
| 4 | +class GametrailersVideoProvider extends MTVNetworksVideoProvider { |
| 5 | + public static function getDomains() { |
| 6 | + return array( 'gametrailers.com' ); |
20 | 7 | } |
21 | 8 | |
22 | | - public function getEmbedCode() { |
23 | | - $height = $this->video->getHeight(); |
24 | | - $width = $this->video->getWidth(); |
25 | | - $output = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="gtembed" width="' . $width . '" height="' . $height . '"> |
26 | | - <param name="allowScriptAccess" value="sameDomain" /> |
27 | | - <param name="allowFullScreen" value="true" /> |
28 | | - <param name="movie" value="http://www.gametrailers.com/remote_wrap.php?mid=' . $this->id . '"/> |
29 | | - <param name="quality" value="high" /> |
30 | | - <embed src="http://www.gametrailers.com/remote_wrap.php?mid=' . $this->id . '" swLiveConnect="true" name="gtembed" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' . $width . '" height="' . $height . '"></embed> |
31 | | - </object>'; |
32 | | - return $output; |
33 | | - } |
34 | | - |
35 | | - /** |
36 | | - * Extract the video ID from its URL. |
37 | | - * Copypasted from WikiaVideo's VideoPage.php's parseUrl(). |
38 | | - * |
39 | | - * @return Integer: video ID |
40 | | - */ |
41 | | - private function extractID() { |
42 | | - $url = $this->video->getURL(); |
43 | | - $url = trim( $url ); |
44 | | - |
45 | | - $fixed_url = strtoupper( $url ); |
46 | | - $test = strpos( $fixed_url, 'HTTP://' ); |
47 | | - if( !false === $test ) { |
48 | | - return false; |
| 9 | + protected function extractVideoId( $url ) { |
| 10 | + if ( !preg_match( '#/(?<type>user-movie|video)/[a-zA-Z0-9\-]+/(?<id>\d+)#', $url, $matches ) ) { |
| 11 | + return null; |
49 | 12 | } |
50 | 13 | |
51 | | - $fixed_url = str_replace( 'HTTP://', '', $fixed_url ); |
52 | | - $fixed_parts = explode( '/', $fixed_url ); |
53 | | - $fixed_url = $fixed_parts[0]; |
54 | | - |
55 | | - $id = ''; |
56 | | - $text = strpos( $fixed_url, 'GAMETRAILERS' ); |
57 | | - if( $text !== false ) { |
58 | | - $parsed = explode( '/', $url ); |
59 | | - if( is_array( $parsed ) ) { |
60 | | - $id = explode( '?', array_pop( $parsed ) ); |
61 | | - $id = $id[0]; |
62 | | - } |
| 14 | + $vidType = ''; |
| 15 | + switch ( $matches['type'] ) { |
| 16 | + case 'video': |
| 17 | + $vidType = 'video'; |
| 18 | + break; |
| 19 | + case 'user-movie': |
| 20 | + $vidType = 'usermovie'; |
| 21 | + break; |
| 22 | + default: |
| 23 | + return null; |
63 | 24 | } |
64 | 25 | |
65 | | - return $id; |
| 26 | + return "mgid:moses:$vidType:gametrailers.com:{$matches['id']}"; |
66 | 27 | } |
67 | | - |
68 | 28 | } |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/VimeoVideo.php |
— | — | @@ -1,68 +1,16 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class VimeoVideo extends FlashVideo { |
| 4 | +class VimeoVideoProvider extends BaseVideoProvider { |
5 | 5 | |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
| 6 | + protected $videoIdRegex = '/.*\/(.*)/'; |
| 7 | + protected $embedTemplate = '<iframe src="http://player.vimeo.com/video/$video_id" width="$width" height="$height" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>'; |
9 | 8 | |
10 | | - public function __construct( $video ) { |
11 | | - if( !is_object( $video ) ) { |
12 | | - throw new MWException( 'VimeoVideo constructor given bogus video object.' ); |
13 | | - } |
14 | | - |
15 | | - $this->video =& $video; |
16 | | - $this->video->ratio = 400 / 225; |
17 | | - $this->id = $this->extractID( $this->video->getURL() ); |
18 | | - $this->url = 'http://www.vimeo.com/' . $this->id; |
19 | | - return $this; |
| 9 | + protected function getRatio() { |
| 10 | + return 400 / 225; |
20 | 11 | } |
21 | 12 | |
22 | | - public function getEmbedCode() { |
23 | | - $height = $this->video->getHeight(); |
24 | | - $width = $this->video->getWidth(); |
25 | | - $auto = '';#$autoplay ? '&autoplay=1' : ''; |
26 | | - $output = '<object width="' . $width . '" height="' . $height . '">'; |
27 | | - $output .= '<param name="allowfullscreen" value="true" />'; |
28 | | - $output .= '<param name="wmode" value="transparent">'; |
29 | | - $output .= '<param name="allowscriptaccess" value="always" />'; |
30 | | - $output .= '<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' . $this->id . |
31 | | - '&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1' . $auto . '" />'; |
32 | | - $output .= '<embed src="http://vimeo.com/moogaloop.swf?clip_id=' . $this->id . '&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1' . $auto . '" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="' . $width . '" height="' . $height . '">'; |
33 | | - $output .= '</embed></object>'; |
34 | | - return $output; |
| 13 | + public static function getDomains() { |
| 14 | + return array( 'vimeo.com' ); |
35 | 15 | } |
36 | 16 | |
37 | | - /** |
38 | | - * Extract the video ID from its URL. |
39 | | - * Copypasted from WikiaVideo's VideoPage.php's parseUrl(). |
40 | | - * |
41 | | - * @return Integer: video ID |
42 | | - */ |
43 | | - private function extractID() { |
44 | | - $url = $this->video->getURL(); |
45 | | - $url = trim( $url ); |
46 | | - |
47 | | - $fixed_url = strtoupper( $url ); |
48 | | - $test = strpos( $fixed_url, 'HTTP://' ); |
49 | | - if( !false === $test ) { |
50 | | - return false; |
51 | | - } |
52 | | - |
53 | | - $fixed_url = str_replace( 'HTTP://', '', $fixed_url ); |
54 | | - $fixed_parts = explode( '/', $fixed_url ); |
55 | | - $fixed_url = $fixed_parts[0]; |
56 | | - |
57 | | - $id = ''; |
58 | | - $text = strpos( $fixed_url, 'VIMEO.COM' ); |
59 | | - if( $text !== false ) { |
60 | | - $parsed = explode( '/', $url ); |
61 | | - if( is_array( $parsed ) ) { |
62 | | - $id = array_pop( $parsed ); |
63 | | - } |
64 | | - } |
65 | | - |
66 | | - return $id; |
67 | | - } |
68 | | - |
69 | 17 | } |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/SevenloadVideo.php |
— | — | @@ -10,69 +10,15 @@ |
11 | 11 | * ?username=XYZ&token-id=8b8453ca4b79f500e94aac1fc7025b0704f3f2c7 |
12 | 12 | */ |
13 | 13 | |
14 | | -class SevenloadVideo extends FlashVideo { |
| 14 | +class SevenloadVideoProvider extends BaseVideoProvider { |
| 15 | + protected $videoIdRegex = '#/([a-zA-Z0-9]+)-[a-zA-Z0-9\-]*?(?:(?:\#|\?).*?)?$#'; |
| 16 | + protected $embedTemplate = '<object type="application/x-shockwave-flash" data="http://en.sevenload.com/pl/$video_id/$widthx$height/swf" width="$width" height="$height"><param name="allowFullscreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="movie" value="http://en.sevenload.com/pl/$video_id/$widthx$height/swf" /></object>'; |
15 | 17 | |
16 | | - var $video, |
17 | | - $id, |
18 | | - $url; |
19 | | - |
20 | | - public function __construct( $video ) { |
21 | | - if( !is_object( $video ) ) { |
22 | | - throw new MWException( 'SevenloadVideo constructor given bogus video object.' ); |
23 | | - } |
24 | | - |
25 | | - $this->video =& $video; |
26 | | - $this->video->ratio = 500 / 408; |
27 | | - $this->id = $this->extractID( $this->video->getURL() ); |
28 | | - $this->url = 'http://www.sevenload.com/videos/' . $this->id; |
29 | | - return $this; |
| 18 | + protected function getRatio() { |
| 19 | + return 500 / 408; |
30 | 20 | } |
31 | 21 | |
32 | | - public function getEmbedCode() { |
33 | | - $output = '<object style="visibility: visible;" id="sevenloadPlayer_' . $this->id . |
34 | | - '" data="http://static.sevenload.com/swf/player/player.swf" type="application/x-shockwave-flash" height="' . |
35 | | - $this->video->getHeight() . |
36 | | - '" width="' . $this->video->getWidth() . '">'; |
37 | | - $output .= '<param name="wmode" value="transparent">'; |
38 | | - $output .= '<param value="always" name="allowScriptAccess">'; |
39 | | - $output .= '<param value="true" name="allowFullscreen">'; |
40 | | - $output .= '<param value="configPath=http%3A%2F%2Fflash.sevenload.com%2Fplayer%3FportalId%3Den%26autoplay%3D0%26itemId%3D' . $this->id . |
41 | | - '&locale=en_US&autoplay=0&environment=" name="flashvars">'; |
42 | | - $output .= '</object>'; |
43 | | - return $output; |
| 22 | + public static function getDomains() { |
| 23 | + return array( 'sevenload.com' ); |
44 | 24 | } |
45 | | - |
46 | | - /** |
47 | | - * Extract the video ID from its URL. |
48 | | - * Copypasted from WikiaVideo's VideoPage.php's parseUrl(). |
49 | | - * |
50 | | - * @return Integer: video ID |
51 | | - */ |
52 | | - private function extractID() { |
53 | | - $url = $this->video->getURL(); |
54 | | - $url = trim( $url ); |
55 | | - |
56 | | - $fixed_url = strtoupper( $url ); |
57 | | - $test = strpos( $fixed_url, 'HTTP://' ); |
58 | | - if( !false === $test ) { |
59 | | - return false; |
60 | | - } |
61 | | - |
62 | | - $fixed_url = str_replace( 'HTTP://', '', $fixed_url ); |
63 | | - $fixed_parts = explode( '/', $fixed_url ); |
64 | | - $fixed_url = $fixed_parts[0]; |
65 | | - |
66 | | - $id = ''; |
67 | | - $text = strpos( $fixed_url, 'SEVENLOAD.COM' ); |
68 | | - if( $text !== false ) { |
69 | | - $parsed = explode( '/', $url ); |
70 | | - $id = array_pop( $parsed ); |
71 | | - $parsed_id = explode( '-', $id ); |
72 | | - if( is_array( $parsed_id ) ) { |
73 | | - $id = $parsed_id[0]; |
74 | | - } |
75 | | - } |
76 | | - return $id; |
77 | | - } |
78 | | - |
79 | 25 | } |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/BaseVideoProvider.php |
— | — | @@ -0,0 +1,105 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +abstract class BaseVideoProvider { |
| 5 | + |
| 6 | + /** |
| 7 | + * Video object for this embed |
| 8 | + * |
| 9 | + * @var Video |
| 10 | + */ |
| 11 | + protected $video; |
| 12 | + |
| 13 | + /** |
| 14 | + * Video ID |
| 15 | + * |
| 16 | + * @var string |
| 17 | + */ |
| 18 | + protected $videoId = null; |
| 19 | + |
| 20 | + /** |
| 21 | + * Regular expression used to extract the video ID |
| 22 | + * |
| 23 | + * @var null |
| 24 | + */ |
| 25 | + protected $videoIdRegex = null; |
| 26 | + |
| 27 | + /** |
| 28 | + * Template for embedding |
| 29 | + * |
| 30 | + * @var null |
| 31 | + */ |
| 32 | + protected $embedTemplate = null; |
| 33 | + |
| 34 | + public function __construct( $video ) { |
| 35 | + if ( !($video instanceof Video) ) { |
| 36 | + throw new MWException( 'Video Provider constructor given bogus video object.' ); |
| 37 | + } |
| 38 | + |
| 39 | + $this->video = $video; |
| 40 | + // TODO: This sucks fix it |
| 41 | + $this->video->ratio = $this->getRatio(); |
| 42 | + |
| 43 | + $matches = array(); |
| 44 | + if ( $this->videoIdRegex !== null && preg_match( $this->videoIdRegex, $this->video->getURL(), $matches ) ) { |
| 45 | + $this->videoId = $matches[1]; |
| 46 | + } else { |
| 47 | + $this->videoId = $this->extractVideoId( $this->video->getURL() ); |
| 48 | + } |
| 49 | + |
| 50 | + if ( $this->videoId === null ) { |
| 51 | + return null; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Function to extract the video id |
| 57 | + * |
| 58 | + * Override to use instead of regular expression |
| 59 | + * |
| 60 | + * @param $url |
| 61 | + * @return null |
| 62 | + */ |
| 63 | + protected function extractVideoId( $url ) { |
| 64 | + return null; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Returns the raw HTML to embed the video |
| 69 | + * |
| 70 | + * @return string |
| 71 | + */ |
| 72 | + public function getEmbedCode() { |
| 73 | + if ( $this->embedTemplate === null ) { |
| 74 | + return ''; |
| 75 | + } |
| 76 | + |
| 77 | + return str_replace( array( |
| 78 | + '$video_id', |
| 79 | + '$height', |
| 80 | + '$width', |
| 81 | + ), array( |
| 82 | + $this->videoId, |
| 83 | + $this->video->getHeight(), |
| 84 | + $this->video->getWidth(), |
| 85 | + ), $this->embedTemplate ); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Returns the (aspect?) ratio for the video |
| 90 | + * |
| 91 | + * @return int |
| 92 | + */ |
| 93 | + protected function getRatio() { |
| 94 | + return 1; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Returns all domains associated with the provider |
| 99 | + * |
| 100 | + * @return array |
| 101 | + */ |
| 102 | + public static function getDomains() { |
| 103 | + return array(); |
| 104 | + } |
| 105 | + |
| 106 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/Video/providers/BaseVideoProvider.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 107 | + native |
Index: trunk/extensions/Video/providers/DailyMotionVideo.php |
— | — | @@ -1,26 +1,15 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class DailyMotionVideo extends FlashVideo { |
| 4 | +class DailyMotionVideoProvider extends BaseVideoProvider { |
5 | 5 | |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
| 6 | + protected $videoIdRegex = '#/video/([a-zA-Z0-9]+)_.*#'; |
| 7 | + protected $embedTemplate = '<iframe frameborder="0" width="$width" height="$height" src="http://www.dailymotion.com/embed/video/$video_id"></iframe>'; |
9 | 8 | |
10 | | - public function __construct( $video ) { |
11 | | - if( !is_object( $video ) ) { |
12 | | - throw new MWException( 'DailyMotionVideo constructor given bogus video object.' ); |
13 | | - } |
14 | | - $this->video =& $video; |
15 | | - $this->video->ratio = 425/335; |
16 | | - $this->id = $this->extractID( $this->video->getURL() ); |
17 | | - $this->url = "http://www.dailymotion.com/swf/{$this->id}"; |
18 | | - return $this; |
| 9 | + protected function getRatio() { |
| 10 | + return 425 / 355; |
19 | 11 | } |
20 | 12 | |
21 | | - private function extractID() { |
22 | | - $url = $this->video->getURL(); |
23 | | - $id = preg_replace( '%http\:\/\/www\.dailymotion\.com\/(swf|video)\/%i', '', $url ); |
24 | | - return $id; |
| 13 | + public static function getDomains() { |
| 14 | + return array( 'dailymotion.com' ); |
25 | 15 | } |
26 | | - |
27 | 16 | } |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/ViddlerVideo.php |
— | — | @@ -1,114 +1,46 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class ViddlerVideo extends FlashVideo { |
| 4 | +class ViddlerVideoProvider extends BaseVideoProvider { |
| 5 | + const idRegex = '#src="http://www\.viddler\.com/player/(?<id>[a-zA-Z0-9]*?)/"#'; |
| 6 | + protected $embedTemplate = '<object width="$width" height="$height" id="viddlerplayer-$video_id"><param name="movie" value="http://www.viddler.com/player/$video_id/" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /><param name="allowFullScreen" value="true" /><embed src="http://www.viddler.com/player/$video_id/" width="$width" height="$height" type="application/x-shockwave-flash" wmode="transparent" allowScriptAccess="always" allowFullScreen="true" name="viddlerplayer-$video_id" ></embed></object>'; |
5 | 7 | |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
| 8 | + public static function getDomains() { |
| 9 | + return array( 'viddler.com' ); |
| 10 | + } |
9 | 11 | |
10 | | - /** |
11 | | - * @var String: Viddler API key -- this is Wikia's :) |
12 | | - */ |
13 | | - const API_KEY = 'hacouneo6n6o3nysn0em'; |
14 | | - |
15 | | - public function __construct( $video ) { |
16 | | - if( !is_object( $video ) ) { |
17 | | - throw new MWException( 'ViddlerVideo constructor given bogus video object.' ); |
18 | | - } |
19 | | - |
20 | | - $this->video =& $video; |
21 | | - $this->video->ratio = 437 / 288; |
22 | | - $this->id = $this->extractID( $this->video->getURL() ); |
23 | | - // This needs to take from their API, since they're doing some conversion on their side |
24 | | - // URL ID -> embedding ID |
25 | | - // The above is what Bartek once wrote on the WikiaVideo extension. |
26 | | - // I'm not sure if my code is correct, but if it's not, feel free to |
27 | | - // correct me... |
28 | | - //$this->url = $this->getURLToEmbed(); |
29 | | - $this->url = 'http://www.viddler.com/explore/' . $this->id; |
30 | | - return $this; |
| 12 | + protected function getRatio() { |
| 13 | + return 437 / 288; |
31 | 14 | } |
32 | 15 | |
33 | | - /** |
34 | | - * This function is a combination of WikiaVideo's getUrlToEmbed() and |
35 | | - * getViddlerTrueID() functions. |
36 | | - * I removed memcached support -- if it ever worked that must've |
37 | | - * been good luck, because the code was just...well, wtf: it used |
38 | | - * uninitialized $url variable in the memcached key. |
39 | | - * |
40 | | - * @return Mixed: false in case of failure or video URL in case of success |
41 | | - */ |
42 | | - private function getURLToEmbed() { |
43 | | - //global $wgMemc; |
44 | 16 | |
45 | | - //$cacheKey = wfMemcKey( 'wvi', 'viddlerid', $this->id, $url ); |
46 | | - //$obj = $wgMemc->get( $cacheKey ); |
| 17 | + protected function extractVideoId( $url ) { |
| 18 | + global $wgMemc; |
47 | 19 | |
48 | | - //if ( isset( $obj ) ) { |
49 | | - // return $obj; |
50 | | - //} |
| 20 | + $cacheKey = wfMemcKey( 'video', 'viddler', sha1( $url ) ); |
| 21 | + $cachedEmbedId = $wgMemc->get( $cacheKey ); |
51 | 22 | |
52 | | - $url = 'http://api.viddler.com/rest/v1/?method=viddler.videos.getDetailsByUrl&api_key=' . |
53 | | - self::API_KEY . '&url=http://www.viddler.com/explore/' . $this->id; |
54 | | - wfSuppressWarnings(); |
55 | | - $file = Http::get( $url ); |
56 | | - $doc = new DOMDocument( '1.0', 'UTF-8' ); |
57 | | - $doc->loadXML( $file ); |
58 | | - wfRestoreWarnings(); |
59 | | - $trueID = trim( $doc->getElementsByTagName( 'id' )->item( 0 )->textContent ); |
60 | | - if ( empty( $trueID ) ) { |
61 | | - return false; |
| 23 | + if ( $cachedEmbedId !== false ) { |
| 24 | + return $cachedEmbedId; |
62 | 25 | } |
63 | 26 | |
64 | | - //$wgMemc->set( $cacheKey, $trueID, 60 * 60 * 24 ); |
| 27 | + $apiUrl = 'http://lab.viddler.com/services/oembed/?format=json&url=' . urlencode( $url ); |
| 28 | + $apiResult = HTTP::get( $apiUrl ); |
65 | 29 | |
66 | | - return 'http://www.viddler.com/player/' . $trueID . '/'; |
67 | | - } |
| 30 | + if ( $apiResult === false ) { |
| 31 | + return null; |
| 32 | + } |
68 | 33 | |
69 | | - public function getEmbedCode() { |
70 | | - $height = $this->video->getHeight(); |
71 | | - $width = $this->video->getWidth(); |
72 | | - $url = $this->getURLToEmbed(); |
73 | | - $output = "<embed src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" wmode=\"transparent\" allowScriptAccess=\"always\" allowfullscreen=\"true\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"> </embed>"; |
74 | | - return $output; |
75 | | - } |
| 34 | + $apiResult = FormatJson::decode( $apiResult, true ); |
76 | 35 | |
77 | | - /** |
78 | | - * Extract the video ID from its URL. |
79 | | - * Copypasted from WikiaVideo's VideoPage.php's parseUrl(). |
80 | | - * |
81 | | - * @return Integer: video ID |
82 | | - */ |
83 | | - private function extractID() { |
84 | | - $url = $this->video->getURL(); |
85 | | - $url = trim( $url ); |
86 | | - |
87 | | - $fixed_url = strtoupper( $url ); |
88 | | - $test = strpos( $fixed_url, 'HTTP://' ); |
89 | | - if( !false === $test ) { |
90 | | - return false; |
| 36 | + // Extract the player source from the HTML |
| 37 | + if ( !preg_match( self::idRegex, $apiResult['html'], $matches ) ) { |
| 38 | + return null; |
91 | 39 | } |
92 | 40 | |
93 | | - $fixed_url = str_replace( 'HTTP://', '', $fixed_url ); |
94 | | - $fixed_parts = explode( '/', $fixed_url ); |
95 | | - $fixed_url = $fixed_parts[0]; |
| 41 | + $embedId = $matches['id']; |
96 | 42 | |
97 | | - $id = ''; |
98 | | - $text = strpos( $fixed_url, 'VIDDLER.COM' ); |
99 | | - if( $text !== false ) { |
100 | | - $parsed = explode( '/explore/', strtolower( $url ) ); |
101 | | - if( is_array( $parsed ) ) { |
102 | | - $mdata = array_pop( $parsed ); |
103 | | - if ( ( $mdata != '' ) && ( strpos( $mdata, '?' ) === false ) ) { |
104 | | - $id = $mdata; |
105 | | - } else { |
106 | | - $id = array_pop( $parsed ); |
107 | | - } |
108 | | - if ( substr( $id, -1, 1 ) != '/' ) { |
109 | | - $id .= '/'; |
110 | | - } |
111 | | - } |
112 | | - } |
| 43 | + $wgMemc->set( $cacheKey, $embedId, 60 * 60 * 24 ); |
113 | 44 | |
114 | | - return $id; |
| 45 | + return $embedId; |
115 | 46 | } |
| 47 | +} |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/SouthParkStudiosVideo.php |
— | — | @@ -1,65 +1,17 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class SouthParkStudiosVideo extends FlashVideo { |
| 4 | +class SouthParkStudiosVideoProvider extends MTVNetworksVideoProvider { |
| 5 | + protected $videoRegexId = '#/clips/(\d+)/#'; |
5 | 6 | |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
9 | | - |
10 | | - public function __construct( $video ) { |
11 | | - if( !is_object( $video ) ) { |
12 | | - throw new MWException( 'SouthParkStudiosVideo constructor given bogus video object.' ); |
13 | | - } |
14 | | - |
15 | | - $this->video =& $video; |
16 | | - $this->video->ratio = 480 / 400; |
17 | | - $this->id = $this->extractID( $this->video->getURL() ); |
18 | | - $this->url = 'http://www.southparkstudios.com/clips/' . $this->id; |
19 | | - return $this; |
| 7 | + public static function getDomains() { |
| 8 | + return array( 'southparkstudios.com' ); |
20 | 9 | } |
21 | 10 | |
22 | | - public function getEmbedCode() { |
23 | | - $height = $this->video->getHeight(); |
24 | | - $width = $this->video->getWidth(); |
25 | | - $output = '<embed src="http://media.mtvnservices.com/mgid:cms:item:southparkstudios.com:' . $this->id . '" width="' . $width . '" height="' . $height . '" type="application/x-shockwave-flash" wmode="window" flashVars="autoPlay=false&dist=http://www.southparkstudios.com&orig=" allowFullScreen="true" allowScriptAccess="always" allownetworking="all" bgcolor="#000000"></embed>'; |
26 | | - return $output; |
27 | | - } |
28 | | - |
29 | | - /** |
30 | | - * Extract the video ID from its URL. |
31 | | - * Copypasted from WikiaVideo's VideoPage.php's parseUrl(). |
32 | | - * |
33 | | - * @return Integer: video ID |
34 | | - */ |
35 | | - private function extractID() { |
36 | | - $url = $this->video->getURL(); |
37 | | - $url = trim( $url ); |
38 | | - |
39 | | - $fixed_url = strtoupper( $url ); |
40 | | - $test = strpos( $fixed_url, 'HTTP://' ); |
41 | | - if( !false === $test ) { |
42 | | - return false; |
| 11 | + protected function extractVideoId( $url ) { |
| 12 | + if ( !preg_match( '#/clips/(\d+)/#', $url, $matches ) ) { |
| 13 | + return null; |
43 | 14 | } |
44 | 15 | |
45 | | - $fixed_url = str_replace( 'HTTP://', '', $fixed_url ); |
46 | | - $fixed_parts = explode( '/', $fixed_url ); |
47 | | - $fixed_url = $fixed_parts[0]; |
48 | | - |
49 | | - $id = ''; |
50 | | - $text = strpos( $fixed_url, 'SOUTHPARKSTUDIOS.COM' ); |
51 | | - if( $text !== false ) { |
52 | | - $parsed = explode( '/', $url ); |
53 | | - if( is_array( $parsed ) ) { |
54 | | - $mdata = array_pop( $parsed ); |
55 | | - if ( ( $mdata != '' ) && ( strpos( $mdata, '?' ) === false ) ) { |
56 | | - $id = $mdata; |
57 | | - } else { |
58 | | - $id = array_pop( $parsed ); |
59 | | - } |
60 | | - } |
61 | | - } |
62 | | - |
63 | | - return $id; |
| 16 | + return "mgid:cms:item:southparkstudios.com:{$matches[1]}"; |
64 | 17 | } |
65 | | - |
66 | 18 | } |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/YouTubeVideo.php |
— | — | @@ -1,37 +1,16 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class YouTubeVideo extends FlashVideo { |
| 4 | +class YouTubeVideoProvider extends BaseVideoProvider { |
5 | 5 | |
6 | | - var $video, |
7 | | - $id, |
8 | | - $url; |
| 6 | + protected $videoIdRegex = '/.*v=([A-Za-z0-9-_]+).*/'; |
9 | 7 | |
10 | | - public function __construct( $video ) { |
11 | | - if( !is_object( $video ) ) { |
12 | | - throw new MWException( 'YouTube constructor given bogus video object.' ); |
13 | | - } |
14 | | - $this->video =& $video; |
15 | | - $this->video->ratio = 425/355; |
16 | | - $this->id = $this->extractYouTubeID( $this->video->getURL() ); |
17 | | - $this->url = "http://www.youtube.com/v/{$this->id}"; |
18 | | - return $this; |
| 8 | + protected $embedTemplate = '<object width="$width" height="$height"><param name="movie" value="http://www.youtube.com/v/$video_id&fs=1"></param><param name="wmode" value="transparent"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/$video_id&fs=1" type="application/x-shockwave-flash" wmode="transparent" allowFullScreen="true" width="$width" height="$height"></embed></object>'; |
| 9 | + |
| 10 | + protected function getRatio() { |
| 11 | + return 425 / 355; |
19 | 12 | } |
20 | 13 | |
21 | | - private function extractYouTubeID() { |
22 | | - // Standard YouTube URL |
23 | | - $url = $this->video->getURL(); |
24 | | - $standard_youtube_inurl = strpos( strtoupper( $url ), 'WATCH?V=' ); |
25 | | - |
26 | | - $id = ''; |
27 | | - if( $standard_youtube_inurl !== false ) { |
28 | | - $id = substr( $url, $standard_youtube_inurl + 8, strlen( $url ) ); |
29 | | - } |
30 | | - if( empty( $id ) ) { |
31 | | - $id_test = str_replace( 'http://www.youtube.com/v/', '', $url ); |
32 | | - if( $id_test != $url ) { |
33 | | - $id = $id_test; |
34 | | - } |
35 | | - } |
36 | | - return $id; |
| 14 | + public static function getDomains() { |
| 15 | + return array( 'youtube.com' ); |
37 | 16 | } |
38 | 17 | } |
\ No newline at end of file |
Index: trunk/extensions/Video/providers/BlipTVVideo.php |
— | — | @@ -2,125 +2,49 @@ |
3 | 3 | /** |
4 | 4 | * @file |
5 | 5 | */ |
6 | | -class BlipTVVideo extends FlashVideo { |
| 6 | +class BlipTVVideoProvider extends BaseVideoProvider { |
| 7 | + protected $embedTemplate = '<iframe src="http://blip.tv/play/$video_id.html" width="$width" height="$height" frameborder="0" allowfullscreen></iframe>'; |
7 | 8 | |
8 | | - var $video, |
9 | | - $id, |
10 | | - $url; |
11 | | - |
12 | | - public function __construct( $video ) { |
13 | | - if( !is_object( $video ) ) { |
14 | | - throw new MWException( 'BlipTVVideo constructor given bogus video object.' ); |
15 | | - } |
16 | | - |
17 | | - $this->video =& $video; |
18 | | - $this->video->ratio = 480 / 350; |
19 | | - $this->id = $this->extractID( $this->video->getURL() ); |
20 | | - $this->url = 'http://blip.tv/file/' . $this->id; |
21 | | - return $this; |
| 9 | + public static function getDomains() { |
| 10 | + return array( 'blip.tv' ); |
22 | 11 | } |
23 | 12 | |
24 | | - public function getEmbedCode() { |
25 | | - $height = $this->video->getHeight(); |
26 | | - $width = $this->video->getWidth(); |
27 | | - $result = $this->getData(); |
28 | | - $url = 'http://blip.tv/play/' . $result['mTrueID']; |
29 | | - $output = "<embed src=\"{$url}\" width=\"{$width}\" height=\"{$height}\" wmode=\"transparent\" allowScriptAccess=\"always\" allowfullscreen=\"true\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"> </embed>"; |
30 | | - return $output; |
| 13 | + protected function getRatio() { |
| 14 | + return 480 / 350; |
31 | 15 | } |
| 16 | + |
| 17 | + protected function extractVideoId( $url ) { |
| 18 | + global $wgMemc; |
32 | 19 | |
33 | | - /** |
34 | | - * Extract the video ID from its URL. |
35 | | - * |
36 | | - * @return Integer: video ID |
37 | | - */ |
38 | | - private function extractID() { |
39 | | - $url = $this->video->getURL(); |
40 | | - $url = trim( $url ); |
41 | | - |
42 | | - $fixed_url = strtoupper( $url ); |
43 | | - $test = strpos( $fixed_url, 'HTTP://' ); |
44 | | - if( !false === $test ) { |
45 | | - return false; |
| 20 | + // See if this is a valid url |
| 21 | + if ( !preg_match( '#/[a-zA-Z0-9\-]+/[a-zA-Z0-9\-]*-(\d+)#', $url, $matches ) ) { |
| 22 | + return null; |
46 | 23 | } |
47 | 24 | |
48 | | - $fixed_url = str_replace( 'HTTP://', '', $fixed_url ); |
49 | | - $fixed_parts = explode( '/', $fixed_url ); |
50 | | - $fixed_url = $fixed_parts[0]; |
| 25 | + $videoId = $matches[1]; |
51 | 26 | |
52 | | - $id = ''; |
53 | | - $text = strpos( $fixed_url, 'BLIP.TV' ); |
54 | | - if( $text !== false ) { |
55 | | - $blip = ''; |
56 | | - $parsed = explode( '/', $url ); |
57 | | - if( is_array( $parsed ) ) { |
58 | | - $mdata = array_pop( $parsed ); |
59 | | - if ( $mdata != '' ) { |
60 | | - $blip = $mdata; |
61 | | - } else { |
62 | | - $blip = array_pop( $parsed ); |
63 | | - } |
64 | | - $last = explode( '?', $blip ); |
65 | | - $id = $last[0]; |
66 | | - } |
67 | | - } |
| 27 | + $cacheKey = wfMemcKey( 'video', 'bliptv', $videoId ); |
| 28 | + $cachedEmbedId = $wgMemc->get( $cacheKey ); |
68 | 29 | |
69 | | - return $id; |
70 | | - } |
71 | | - |
72 | | - /** |
73 | | - * Get BlipTV data (true ID and thumbnail URL) via their API and hold in |
74 | | - * memcached. |
75 | | - * Thumbnail URL isn't used anywhere at the moment |
76 | | - * |
77 | | - * @return Mixed: array containing the true ID number and thumbnail URL on |
78 | | - * sucess, boolean false on failure |
79 | | - */ |
80 | | - private function getData() { |
81 | | - global $wgMemc; |
82 | | - |
83 | | - // Try memcached first |
84 | | - $cacheKey = wfMemcKey( 'video', 'bliptv', $this->id, $url ); |
85 | | - $obj = $wgMemc->get( $cacheKey ); |
86 | | - |
87 | | - // Got something? Super! We can return here and give the cached data to |
88 | | - // the user instead of having to make a HTTP request to Blip.tv API. |
89 | | - if ( isset( $obj ) ) { |
90 | | - return $obj; |
| 30 | + if ( $cachedEmbedId !== false ) { |
| 31 | + return $cachedEmbedId; |
91 | 32 | } |
92 | 33 | |
93 | | - $url = 'http://blip.tv/file/' . $this->id . '?skin=rss&version=3'; |
| 34 | + list( $apiUrl ) = explode( '?', $url); |
| 35 | + $apiUrl .= '?skin=api'; |
94 | 36 | |
95 | | - wfSuppressWarnings(); |
96 | | - $file = Http::get( $url ); |
97 | | - wfRestoreWarnings(); |
98 | | - if ( empty( $file ) ) { |
99 | | - return false; |
| 37 | + $apiContents = Http::get( $apiUrl ); |
| 38 | + if ( empty( $apiContents ) ) { |
| 39 | + return null; |
100 | 40 | } |
101 | | - $doc = new DOMDocument( '1.0', 'UTF-8' ); |
102 | | - wfSuppressWarnings(); |
103 | | - $doc->loadXML( $file ); |
104 | | - wfRestoreWarnings(); |
105 | 41 | |
106 | | - $mTrueID = trim( $doc->getElementsByTagNameNS( 'http://blip.tv/dtd/blip/1.0', 'embedLookup' )->item( 0 )->textContent ); |
107 | | - $thumbnailUrl = trim( $doc->getElementsByTagNameNS( 'http://search.yahoo.com/mrss/', 'thumbnail' )->item( 0 )->getAttribute( 'url' ) ); |
108 | | - $mType = trim( $doc->getElementsByTagNameNS( 'http://blip.tv/dtd/blip/1.0', 'embedUrl' )->item( 0 )->getAttribute( 'type' ) ); |
| 42 | + $dom = new DOMDocument( '1.0', 'UTF-8' ); |
| 43 | + $dom->loadXML( $apiContents ); |
109 | 44 | |
110 | | - if ( |
111 | | - ( $mType !== 'application/x-shockwave-flash' ) || |
112 | | - ( empty( $mTrueID ) ) || ( empty( $thumbnailUrl ) ) |
113 | | - ) |
114 | | - { |
115 | | - return false; |
116 | | - } |
| 45 | + $embedId = $dom->getElementsByTagName( 'embedLookup' )->item( 0 )->textContent; |
117 | 46 | |
118 | | - $obj = array( |
119 | | - 'mTrueID' => $mTrueID, |
120 | | - 'thumbnailUrl' => $thumbnailUrl |
121 | | - ); |
| 47 | + $wgMemc->set( $cacheKey, $embedId, 60 * 60 * 24 ); |
122 | 48 | |
123 | | - $wgMemc->set( $cacheKey, $obj, 60 * 60 * 24 ); |
124 | | - |
125 | | - return $obj; |
| 49 | + return $embedId; |
126 | 50 | } |
127 | 51 | } |
\ No newline at end of file |