/** * Fonction volée dans le plugin Vidéo de SPIP (développé par XDjuj, * et distribué sous licence GNU GPLv3). * * Cette fonction est utilisée pour convertir des vidéos YouTube, * Dailymotion ou Viméo en des documents SPIP, qui seront intégrables * avec le modèle <videoXXX> (si le plugin Vidéo est bien installé). * * Code du plugin : * http://zone.spip.org/trac/spip-zone/browser/_plugins_/videos * Code de la fonction : * http://zone.spip.org/trac/spip-zone/browser/_plugins_/videos/trunk/formulaires/insertion_video.php **/ function importer_video($url) { include_spip('inc/acces'); // Retirer les trucs qui emmerdent : tous les arguments d'ancre / les espaces foireux les http:// et les www. éventuels $url = preg_replace('%(#.*$|https?://|www.)%', '', trim($url)); if (preg_match('/dailymotion/', $url)) { $type = 'dist_daily'; $fichier = preg_replace('#dailymotion\\.com/video/#', '', $url); } else { if (preg_match('/vimeo/', $url)) { $type = 'dist_vimeo'; $fichier = preg_replace('#vimeo\\.com/#', '', $url); sleep(1); } else { if (preg_match('/(youtube|youtu\\.be)/', $url)) { $type = 'dist_youtu'; $fichier = preg_replace('#(youtu\\.be/|youtube\\.com/watch\\?v=|&.*$|\\?hd=1)#', '', $url); } } } $titre = ""; $descriptif = ""; $id_vignette = ""; // On tente de récupérer titre et description à l'aide de Videopian if (!preg_match('/culture/', $url) && version_compare(PHP_VERSION, '5.2') >= 0) { include_spip('lib_tierces/Videopian'); // http://www.upian.com/upiansource/videopian/ $Videopian = new Videopian(); if ($Videopian) { $infosVideo = $Videopian->get($url); $titre = $infosVideo->title; $descriptif = $infosVideo->description; $nbVignette = abs(count($infosVideo->thumbnails) - 1); // prendre la plus grande vignette $logoDocument = $infosVideo->thumbnails[$nbVignette]->url; $logoDocument_width = $infosVideo->thumbnails[$nbVignette]->width; $logoDocument_height = $infosVideo->thumbnails[$nbVignette]->height; } else { //echo 'Exception reçue : ', $e->getMessage(), "\n"; spip_log("L'ajout automatique du titre et de la description a echoué", "Plugin Vidéo(s)"); } } // On va pour l'instant utiliser le champ extension pour stocker le type de source $champs = array('titre' => $titre, 'extension' => $type, 'date' => date("Y-m-d H:i:s", time()), 'descriptif' => $descriptif, 'fichier' => $fichier, 'distant' => 'oui'); /** Gérer le cas de la présence des champs de Médiathèque (parce que Mediatheque c'est le BIEN mais c'est pas toujours activé) **/ $trouver_table = charger_fonction('trouver_table', 'base'); $desc = $trouver_table('spip_documents'); if (array_key_exists('taille', $desc['field'])) { if ($infosVideo) { $champs['taille'] = $infosVideo->duration; } } if (array_key_exists('credits', $desc['field'])) { if ($infosVideo) { $champs['credits'] = $infosVideo->author; } } if (array_key_exists('statut', $desc['field'])) { $champs['statut'] = 'publie'; } if (array_key_exists('media', $desc['field'])) { $champs['media'] = 'video'; } /* Cas de la présence d'une vignette à attacher */ if ($logoDocument) { include_spip('inc/distant'); if ($fichier = preg_replace("#IMG/#", '', copie_locale($logoDocument))) { // set_spip_doc ne fonctionne pas... Je ne sais pas pourquoi $champsVignette['fichier'] = $fichier; $champsVignette['mode'] = 'vignette'; // champs extra à intégrer ds SPIP 3 if (array_key_exists('statut', $desc['field'])) { $champsVignette['statut'] = 'publie'; } if (array_key_exists('media', $desc['field'])) { $champsVignette['media'] = 'image'; } // Recuperer les tailles $champsVignette['taille'] = @intval(filesize($fichier)); $size_image = @getimagesize($fichier); $champsVignette['largeur'] = intval($size_image[0]); $champsVignette['hauteur'] = intval($size_image[1]); // $infos['type_image'] = decoder_type_image($size_image[2]); if ($champsVignette['largeur'] == 0) { // en cas d'echec, recuperer les infos videopian $champsVignette['largeur'] = $logoDocument_width; $champsVignette['hauteur'] = $logoDocument_height; } // Ajouter $id_vignette = sql_insertq('spip_documents', $champsVignette); if ($id_vignette) { $champs['id_vignette'] = $id_vignette; } } else { spip_log("Echec de l'insertion du logo {$logoDocument} pour la video {$document}", "Plugin Vidéo(s)"); } } $document = sql_insertq('spip_documents', $champs); if ($document) { $document_lien = sql_insertq('spip_documents_liens', array('id_document' => $document, 'id_objet' => $id_objet, 'objet' => $objet, 'vu' => 'non')); } return $document; }
public static function get($url) { self::$url = $url; self::processUrl(); self::$video = new stdClass(); self::$video->url = self::$url; self::$video->site = self::$service; switch (self::$service) { # -------------------------------------------------------------------------------- case 'blip': # XML data URL $file_data = "http://blip.tv/file/" . self::$id . "?skin=rss"; self::$video->xml_url = $file_data; # XML $xml = new SimpleXMLElement(file_get_contents($file_data)); # Title $title_query = $xml->xpath('/rss/channel/item/title'); self::$video->title = $title_query ? strval($title_query[0]) : null; # Description $description_query = $xml->xpath('/rss/channel/item/blip:puredescription'); self::$video->description = $description_query ? strval(trim($description_query[0])) : null; # Tags $tags_query = $xml->xpath('/rss/channel/item/media:keywords'); self::$video->tags = $tags_query ? explode(', ', strval(trim($tags_query[0]))) : null; # Duration $duration_query = $xml->xpath('/rss/channel/item/blip:runtime'); self::$video->duration = $duration_query ? intval($duration_query[0]) : null; # Author & author URL $author_query = $xml->xpath('/rss/channel/item/blip:user'); self::$video->author = $author_query ? strval($author_query[0]) : null; $author_safe_query = $xml->xpath('/rss/channel/item/blip:safeusername'); self::$video->author_url = 'http://' . strval($author_safe_query[0]) . '.blip.tv'; # Publication date $date_published_query = $xml->xpath('/rss/channel/item/blip:datestamp'); self::$video->date_published = $date_published_query ? new DateTime($date_published_query[0]) : null; # Last update date self::$video->date_updated = null; # Thumbnails $thumbnails_query = $xml->xpath('/rss/channel/item/blip:smallThumbnail'); $thumbnail = new stdClass(); $thumbnail->url = strval($thumbnails_query[0]); list($thumbnail->width, $thumbnail->height) = getimagesize($thumbnail->url); self::$video->thumbnails[] = $thumbnail; $thumbnails_query = $xml->xpath('/rss/channel/item/media:thumbnail/@url'); $thumbnail = new stdClass(); $thumbnail->url = strval($thumbnails_query[0]); list($thumbnail->width, $thumbnail->height) = getimagesize($thumbnail->url); self::$video->thumbnails[] = $thumbnail; # Player URL $player_url_query = $xml->xpath('/rss/channel/item/blip:embedUrl'); self::$video->player_url = $player_url_query ? strval($player_url_query[0]) : null; # FLV file URL $flv_url_query = $xml->xpath('/rss/channel/item/media:group/media:content[@type="video/x-flv"]/@url'); self::$video->files['video/x-flv'] = $flv_url_query ? strval($flv_url_query[0]) : null; # MOV file URL $mov_url_query = $xml->xpath('/rss/channel/item/media:group/media:content[@type="video/quicktime"]/@url'); self::$video->files['video/quicktime'] = $mov_url_query ? strval($mov_url_query[0]) : null; break; # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- case 'dailymotion': # XML data URL $file_data = 'http://www.dailymotion.com/rss/video/' . self::$id; self::$video->xml_url = $file_data; # XML $xml = new SimpleXMLElement(file_get_contents($file_data)); # Title $title_query = $xml->xpath('/rss/channel/item/title'); self::$video->title = $title_query ? strval($title_query[0]) : null; # Description $description_query = $xml->xpath('/rss/channel/item/itunes:summary'); self::$video->description = $description_query ? strval(trim($description_query[0])) : null; # Tags $tags_query = $xml->xpath('/rss/channel/item/itunes:keywords'); self::$video->tags = $tags_query ? explode(', ', strval(trim($tags_query[0]))) : null; # Duration $duration_query = $xml->xpath('/rss/channel/item/media:group/media:content/@duration'); self::$video->duration = $duration_query ? intval($duration_query[0]) : null; # Author & author URL $author_query = $xml->xpath('/rss/channel/item/dm:author'); self::$video->author = $author_query ? strval($author_query[0]) : null; self::$video->author_url = 'http://www.dailymotion.com/' . self::$video->author; # Publication date $date_published_query = $xml->xpath('/rss/channel/item/pubDate'); self::$video->date_published = $date_published_query ? new DateTime($date_published_query[0]) : null; # Last update date self::$video->date_updated = null; # Thumbnails $thumbnail = new stdClass(); $thumbnail->url = 'http://www.dailymotion.com/thumbnail/320x240/video/' . self::$id; $thumbnail->width = 320; $thumbnail->height = 240; self::$video->thumbnails[] = $thumbnail; # Player URL self::$video->player_url = 'http://www.dailymotion.com/swf/' . self::$id; # FLV file URL $flv_url_query = $xml->xpath('/rss/channel/item/media:group/media:content[@type="video/x-flv"]/@url'); self::$video->files['video/x-flv'] = $flv_url_query ? strval($flv_url_query[0]) : null; # MP4 file URL // TODO: Récupération de l'URL du fichier mp4 //$mp4_query = $xml->xpath('/rss/channel/item/media:group/media:content[@type="video/mp4"]/@url'); //self::$mp4 = $mp4_query ? $mp4_query[0] : ''; break; # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- case 'flickr': # API key check if (self::FLICKR_API_KEY == '') { throw new Exception('You need to request an api key in order to grab video information from Flickr.'); } # XML data URL $file_data = 'http://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=' . self::FLICKR_API_KEY . '&photo_id=' . self::$id; self::$video->xml_url = $file_data; # XML $xml = new SimpleXMLElement(file_get_contents($file_data)); # Media type check $media_query = $xml->xpath('/rsp/photo/@media'); if ($media_query[0] != 'video') { throw new Exception('The media you are trying to get from Flickr is not a video.'); } # Title $title_query = $xml->xpath('/rsp/photo/title'); self::$video->title = $title_query ? strval($title_query[0]) : null; # Description $description_query = $xml->xpath('/rsp/photo/description'); self::$video->description = empty($description_query) ? strval(trim($description_query[0])) : null; # Tags $tags_query = $xml->xpath('/rsp/photo/tags/tag'); $tags = array(); foreach ($tags_query as $tag_query) { $tag = (array) $tag_query; $tags[] = $tag[0]; } self::$video->tags = $tags_query ? $tags : null; # Duration $duration_query = $xml->xpath('/rsp/photo/video/@duration'); self::$video->duration = empty($duration_query) ? intval($duration_query[0]) : null; # Author & author URL $author_query = $xml->xpath('/rsp/photo/owner/@username'); self::$video->author = $author_query ? strval($author_query[0]) : null; $author_id_query = $xml->xpath('/rsp/photo/owner/@nsid'); self::$video->author_url = $author_id_query ? 'http://www.flickr.com/photos/' . strval($author_query[0]) : null; # Publication date $date_published_query = $xml->xpath('/rsp/photo/dates/@posted'); self::$video->date_published = $date_published_query ? new DateTime(date(DATE_RSS, intval($date_published_query[0]))) : null; # Last update date $date_updated_query = $xml->xpath('/rsp/photo/dates/@lastupdate'); self::$video->date_updated = $date_updated_query ? new DateTime(date(DATE_RSS, intval($date_updated_query[0]))) : null; # Thumbnails $thumbnails_query = $xml->xpath('/rsp/photo'); $thumbnails_query = $thumbnails_query[0]->attributes(); $thumbnail = new stdClass(); $thumbnail->url = 'http://farm' . $thumbnails_query['farm'] . '.static.flickr.com/' . $thumbnails_query['server'] . '/' . self::$id . '_' . $thumbnails_query['secret'] . '_m.jpg'; list($thumbnail->width, $thumbnail->height) = getimagesize($thumbnail->url); self::$video->thumbnails[] = $thumbnail; $thumbnail = new stdClass(); $thumbnail->url = 'http://farm' . $thumbnails_query['farm'] . '.static.flickr.com/' . $thumbnails_query['server'] . '/' . self::$id . '_' . $thumbnails_query['secret'] . '_t.jpg'; list($thumbnail->width, $thumbnail->height) = getimagesize($thumbnail->url); self::$video->thumbnails[] = $thumbnail; $thumbnail = new stdClass(); $thumbnail->url = 'http://farm' . $thumbnails_query['farm'] . '.static.flickr.com/' . $thumbnails_query['server'] . '/' . self::$id . '_' . $thumbnails_query['secret'] . '_s.jpg'; $thumbnail->width = 75; $thumbnail->height = 75; self::$video->thumbnails[] = $thumbnail; # XML for files data URL $file_sizes_data = 'http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=' . self::FLICKR_API_KEY . '&photo_id=' . self::$id; # XML $xml_sizes = new SimpleXMLElement(file_get_contents($file_sizes_data)); # Player & files URL $files_url_query = $xml_sizes->xpath('/rsp/sizes/size[@media="video"]'); foreach ($files_url_query as $p) { switch (strval($p['label'])) { case 'Video Player': self::$video->player_url = $files_url_query ? strval($p['source']) : null; break; case 'Site MP4': self::$video->files['video/mp4'] = $files_url_query ? strval($p['source']) : null; break; } } break; # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- case 'googlevideo': # XML data URL $file_data = 'http://video.google.com/videofeed?docid=' . self::$id; self::$video->xml_url = $file_data; # XML $xml = new SimpleXMLElement(utf8_encode(file_get_contents($file_data))); $xml->registerXPathNamespace('media', 'http://search.yahoo.com/mrss/'); # Title $title_query = $xml->xpath('/rss/channel/item/title'); self::$video->title = $title_query ? strval($title_query[0]) : null; # Description $description_query = $xml->xpath('/rss/channel/item/media:group/media:description'); self::$video->description = $description_query ? strval(trim($description_query[0])) : null; # Tags self::$video->tags = null; # Duration $duration_query = $xml->xpath('/rss/channel/item/media:group/media:content/@duration'); self::$video->duration = $duration_query ? intval($duration_query[0]) : null; # Author & author URL // TODO: WTF? // $author_query = $xml->xpath('/rss/channel/item/author'); // self::$video->author = $author_query ? strval($author_query[0]) : false; self::$video->author = null; self::$video->author_url = null; # Publication date $date_published_query = $xml->xpath('/rss/channel/item/pubDate'); self::$video->date_published = $date_published_query ? new DateTime($date_published_query[0]) : null; # Last update date self::$video->date_updated = null; # Thumbnails $thumbnails_query = $xml->xpath('/rss/channel/item/media:group/media:thumbnail'); $thumbnails_query = $thumbnails_query[0]->attributes(); $thumbnail = new stdClass(); $thumbnail->url = strval(preg_replace('#&#', '&', $thumbnails_query['url'])); $thumbnail->width = intval($thumbnails_query['width']); $thumbnail->height = intval($thumbnails_query['height']); self::$video->thumbnails[] = $thumbnail; # Player URL $player_url_query = $xml->xpath('/rss/channel/item/media:group/media:content[@type="application/x-shockwave-flash"]/@url'); self::$video->player_url = $player_url_query ? strval($player_url_query[0]) : null; # AVI file URL $avi_url_query = $xml->xpath('/rss/channel/item/media:group/media:content[@type="video/x-msvideo"]/@url'); self::$video->files['video/x-msvideo'] = $avi_url_query ? preg_replace('#&#', '&', $avi_url_query[0]) : null; # FLV file URL $flv_url_query = $xml->xpath('/rss/channel/item/media:group/media:content[@type="video/x-flv"]/@url'); self::$video->files['video/x-flv'] = $flv_url_query ? strval($flv_url_query[0]) : null; # MP4 file URL $mp4_url_query = $xml->xpath('/rss/channel/item/media:group/media:content[@type="video/mp4"]/@url'); self::$video->files['video/mp4'] = $mp4_url_query ? preg_replace('#&#', '&', $mp4_url_query[0]) : null; break; # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- case 'imeem': throw new Exception('Imeem is not yet supported.'); # Support thread opened here: http://www.imeem.com/groups/zJqqiqve/forums/-uuCzu0F/kx-e6b3U/method_searchbyurl/ break; # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- case 'metacafe': # XML data URL $file_data = "http://www.metacafe.com/api/item/" . self::$id; self::$video->xml_url = $file_data; # XML $xml = new SimpleXMLElement(file_get_contents($file_data)); # Title $title_query = $xml->xpath('/rss/channel/item/title'); self::$video->title = $title_query ? strval($title_query[0]) : ''; # Description $description_query = $xml->xpath('/rss/channel/item/media:description'); self::$video->description = $description_query ? strval($description_query[0]) : ''; # Tags $tags_query = $xml->xpath('/rss/channel/item/media:keywords'); self::$video->tags = $tags_query ? explode(',', strval(trim($tags_query[0]))) : null; # Duration self::$video->duration = null; # Author & author URL $author_query = $xml->xpath('/rss/channel/item/author'); self::$video->author = $author_query ? strval($author_query[0]) : ''; self::$video->author_url = "http://www.metacafe.com/" . self::$video->author; # Publication date $date_published_query = $xml->xpath('/rss/channel/item/pubDate'); self::$video->date_published = $date_published_query ? new DateTime($date_published_query[0]) : null; # Last update date self::$video->date_updated = null; # Thumbnails $thumbnails_query = $xml->xpath('/rss/channel/item/media:thumbnail/@url'); $thumbnail = new stdClass(); $thumbnail->url = strval($thumbnails_query[0]); list($thumbnail->width, $thumbnail->height) = getimagesize($thumbnail->url); self::$video->thumbnails[] = $thumbnail; # Player URL $player_url_query = $xml->xpath('/rss/channel/item/media:content[@type="application/x-shockwave-flash"]/@url'); self::$video->player_url = $player_url_query ? strval($player_url_query[0]) : ''; # Files URL self::$video->files = array(); break; # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- case 'myspace': # XML data URL $file_data = "http://mediaservices.myspace.com/services/rss.ashx?type=video&videoID=" . self::$id; self::$video->xml_url = $file_data; # XML $xml = new SimpleXMLElement(file_get_contents($file_data)); # Title $title_query = $xml->xpath('/rss/channel/item/title'); self::$video->title = $title_query ? strval($title_query[0]) : ''; # Description self::$video->description = null; # Tags self::$video->tags = null; # Duration self::$video->duration = null; # Author & author URL self::$video->author = null; self::$video->author_url = null; # Publication date $date_published_query = $xml->xpath('/rss/channel/item/pubDate'); self::$video->date_published = $date_published_query ? new DateTime($date_published_query[0]) : null; # Last update date self::$video->date_updated = null; # Thumbnails $thumbnails_query = $xml->xpath('/rss/channel/item/media:thumbnail/@url'); $thumbnail = new stdClass(); $thumbnail->url = strval($thumbnails_query[0]); list($thumbnail->width, $thumbnail->height) = getimagesize($thumbnail->url); self::$video->thumbnails[] = $thumbnail; # Player URL self::$video->player_url = "http://lads.myspace.com/videos/vplayer.swf?m=" . self::$id; # FLV file URL $flv_url_query = $xml->xpath('/rss/channel/item/media:content[@type="video/x-flv"]/@url'); self::$video->files['video/x-flv'] = $flv_url_query ? strval($flv_url_query[0]) : null; break; # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- case 'revver': # Account check # if (self::REVVER_LOGIN == '' || self::REVVER_PASSWORD == '') throw new Exception('Please specify your Revver account information.'); throw new Exception('Revver is not yet supported.'); break; # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- case 'veoh': # API key check if (self::VEOH_API_KEY == '') { throw new Exception('You need to request an API key in order to grab video information from Veoh.'); } # XML data URL $file_data = "http://www.veoh.com/rest/v2/execute.xml?method=veoh.video.findByPermalink&permalink=" . self::$id . "&apiKey=" . self::VEOH_API_KEY; self::$video->xml_url = $file_data; # XML $xml = new SimpleXMLElement(file_get_contents($file_data)); # Title $title_query = $xml->xpath('/rsp/videoList/video/@title'); self::$video->title = $title_query ? strval($title_query[0]) : ''; # Description $description_query = $xml->xpath('/rsp/videoList/video/@description'); self::$video->description = $description_query ? strval($description_query[0]) : ''; # Tags $tags_query = $xml->xpath('/rsp/videoList/video/tagList/tag/@tagName'); foreach ($tags_query as $tag) { self::$video->tags[] = strval($tag[0]); } # Duration $duration_query = $xml->xpath('/rsp/videoList/video/@length'); $duration_raw = $duration_query ? strval($duration_query[0]) : null; preg_match('#(([0-9]{0,2}) hr )?([0-9]{0,2}) min ([0-9]{0,2}) sec#', $duration_raw, $matches); $hours = intval($matches[2]); $minutes = intval($matches[3]); $seconds = intval($matches[4]); self::$video->duration = $hours * 60 * 60 + $minutes * 60 + $seconds; # Author & author URL $author_query = $xml->xpath('/rsp/videoList/video/@username'); self::$video->author = $author_query ? strval($author_query[0]) : ''; self::$video->author_url = "http://www.veoh.com/users/" . self::$video->author; # Publication date $date_published_query = $xml->xpath('/rsp/videoList/video/@dateAdded'); self::$video->date_published = $date_published_query ? new DateTime($date_published_query[0]) : null; # Last update date self::$video->date_updated = null; # Thumbnails $thumbnails_query_medres = $xml->xpath('/rsp/videoList/video/@medResImage'); $thumbnail = new stdClass(); $thumbnail->url = strval($thumbnails_query_medres[0]); list($thumbnail->width, $thumbnail->height) = getimagesize($thumbnail->url); self::$video->thumbnails[] = $thumbnail; $thumbnails_query_highres = $xml->xpath('/rsp/videoList/video/@highResImage'); $thumbnail = new stdClass(); $thumbnail->url = strval($thumbnails_query_highres[0]); list($thumbnail->width, $thumbnail->height) = getimagesize($thumbnail->url); self::$video->thumbnails[] = $thumbnail; # Player URL self::$video->player_url = "http://www.veoh.com/veohplayer.swf?permalinkId=" . self::$id; # FLV file URL $flv_url_query = $xml->xpath('/rsp/videoList/video/@previewUrl'); self::$video->files['video/x-flv'] = $flv_url_query ? strval($flv_url_query[0]) : null; break; # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- case 'viddler': # API key check # if (self::VIDDLER_API_KEY == '') throw new Exception('You need to request an api key in order to grab video information from Viddler.'); throw new Exception('Viddler is not yet supported.'); break; # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- case 'vimeo': # PHP serialized data URL //$url_data = 'http://vimeo.com/api/clip/'.self::$id.'/php'; $url_data = 'http://vimeo.com/api/v2/video/' . self::$id . '.php'; # Data $data = unserialize(file_get_contents($url_data)); # Title self::$video->title = $data[0]['title']; # Description self::$video->description = $data[0]['caption']; # Tags self::$video->tags = explode(', ', $data[0]['tags']); # Duration self::$video->duration = $data[0]['duration']; # Author & author URL self::$video->author = $data[0]['user_name']; self::$video->author_url = $data[0]['user_url']; # Publication date self::$video->date_published = new DateTime($data[0]['upload_date']); # Last update date self::$video->date_updated = null; # Thumbnails $thumbnail = new stdClass(); $thumbnail->url = $data[0]['thumbnail_small']; list($thumbnail->width, $thumbnail->height) = getimagesize($thumbnail->url); self::$video->thumbnails[] = $thumbnail; $thumbnail = new stdClass(); $thumbnail->url = $data[0]['thumbnail_medium']; list($thumbnail->width, $thumbnail->height) = getimagesize($thumbnail->url); self::$video->thumbnails[] = $thumbnail; $thumbnail = new stdClass(); $thumbnail->url = $data[0]['thumbnail_large']; list($thumbnail->width, $thumbnail->height) = getimagesize($thumbnail->url); self::$video->thumbnails[] = $thumbnail; # Player URL self::$video->player_url = 'http://vimeo.com/moogaloop.swf?clip_id=' . self::$id; # XML data URL $file_data = 'http://vimeo.com/api/v2/video/' . self::$id . '.xml'; self::$video->xml_url = 'http://vimeo.com/api/clip/' . self::$id . '/xml'; # XML $xml = new SimpleXMLElement(file_get_contents($file_data), LIBXML_NOCDATA); # Files URL self::$video->files = array(); break; # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- case 'sevenload': # API key check # if (self::SEVENLOAD_API_KEY == '') throw new Exception('You need to request an api key in order to grab video information from Sevenload'); throw new Exception('Sevenload is not yet supported.'); break; # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- case 'youtube': # XML data URL $file_data = 'http://gdata.youtube.com/feeds/api/videos/' . self::$id; self::$video->xml_url = $file_data; # XML $xml = new SimpleXMLElement(file_get_contents($file_data)); $xml->registerXPathNamespace('a', 'http://www.w3.org/2005/Atom'); $xml->registerXPathNamespace('media', 'http://search.yahoo.com/mrss/'); $xml->registerXPathNamespace('yt', 'http://gdata.youtube.com/schemas/2007'); # Title $title_query = $xml->xpath('/a:entry/a:title'); self::$video->title = $title_query ? strval($title_query[0]) : false; # Description $description_query = $xml->xpath('/a:entry/a:content'); self::$video->description = $description_query ? strval(trim($description_query[0])) : false; # Tags $tags_query = $xml->xpath('/a:entry/media:group/media:keywords'); self::$video->tags = $tags_query ? explode(', ', strval(trim($tags_query[0]))) : false; # Duration $duration_query = $xml->xpath('/a:entry/media:group/yt:duration/@seconds'); self::$video->duration = $duration_query ? intval($duration_query[0]) : false; # Author & author URL $author_query = $xml->xpath('/a:entry/a:author/a:name'); self::$video->author = $author_query ? strval($author_query[0]) : false; self::$video->author_url = 'http://www.youtube.com/' . self::$video->author; # Publication date $date_published_query = $xml->xpath('/a:entry/a:published'); self::$video->date_published = $date_published_query ? new DateTime($date_published_query[0]) : false; # Last update date $date_updated_query = $xml->xpath('/a:entry/a:updated'); self::$video->date_updated = $date_updated_query ? new DateTime($date_updated_query[0]) : false; # Thumbnails $thumbnail_query = $xml->xpath('/a:entry/media:group/media:thumbnail'); foreach ($thumbnail_query as $t) { $thumbnail = new stdClass(); $thumbnail_query = $t->attributes(); $thumbnail->url = strval($thumbnail_query['url']); $thumbnail->width = intval($thumbnail_query['width']); $thumbnail->height = intval($thumbnail_query['height']); self::$video->thumbnails[] = $thumbnail; } # Player URL self::$video->player_url = 'http://www.youtube.com/v/' . self::$id; # Files URL self::$video->files = array(); # FLV file URL // TODO: Récupération de l'URL du fichier flv // self::$video->flv_url = 'http://www.youtube.com/get_video.php?video_id='.self::$id; break; # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- default: throw new Exception('Unable to get the video data. Please make sure the service you’re trying to use is supported by Videopian.'); break; } return self::$video; }