Exemple #1
0
 public static function getAccount($url)
 {
     $url_parts = \PVL\Utilities::parseUrl($url);
     $url_components = explode('/', $url_parts['path']);
     $url_last_element = array_pop($url_components);
     $account = trim($url_last_element);
     return $account;
 }
 public static function addTracking($url, $utm_data = array())
 {
     $utm_defaults = array('source' => 'pvlive', 'medium' => 'direct', 'campaign' => 'pvlive', 'term' => NULL, 'content' => NULL);
     $utm_data = array_merge($utm_defaults, $utm_data);
     $url_parts = Utilities::parseUrl($url);
     $url_params = (array) $url_parts['query_arr'];
     foreach ($utm_data as $utm_key => $utm_val) {
         if (!empty($utm_val)) {
             $url_params['utm_' . $utm_key] = $utm_val;
         }
     }
     $url_parts['query'] = http_build_query($url_params);
     return Utilities::buildUrl($url_parts);
 }
Exemple #3
0
 public static function getAccount($url)
 {
     if (stristr($url, 'youtube.com') !== FALSE) {
         $url_parts = \PVL\Utilities::parseUrl($url);
         if ($url_parts['path_clean'] == 'playlist') {
             return array('type' => 'playlist', 'id' => $url_parts['query_arr']['list']);
         } else {
             $url_components = explode('/', $url_parts['path']);
             $url_last_element = array_pop($url_components);
             $account = trim($url_last_element);
             return array('type' => 'user', 'id' => $account);
         }
     } else {
         return array('type' => 'user', 'id' => trim($url));
     }
 }
 /**
  * Process an individual convention archive row.
  * @param ConventionArchive $row
  */
 public static function process(ConventionArchive $row)
 {
     $di = \Phalcon\Di::getDefault();
     $em = $di->get('em');
     $config = $di->get('config');
     // Set up Google Client
     $gclient_api_key = $config->apis->google_apis_key;
     $gclient_app_name = $config->application->name;
     if (empty($gclient_api_key)) {
         return null;
     }
     $gclient = new \Google_Client();
     $gclient->setApplicationName($gclient_app_name);
     $gclient->setDeveloperKey($gclient_api_key);
     $yt_client = new YouTube($gclient);
     $url = $row->web_url;
     if (empty($row->playlist_id)) {
         switch ($row->type) {
             case "yt_playlist":
                 $url_parts = \PVL\Utilities::parseUrl($url);
                 $playlist_id = $url_parts['query_arr']['list'];
                 if (!$playlist_id) {
                     break;
                 }
                 // Clear existing related items.
                 $em->createQuery('DELETE FROM Entity\\ConventionArchive ca WHERE ca.playlist_id = :id')->setParameter('id', $row->id)->execute();
                 $data = $yt_client->playlists->listPlaylists('id,snippet', array('id' => $playlist_id, 'maxResults' => 1));
                 if ($data) {
                     $playlist = $data['items'][0]['snippet'];
                     $row->name = $playlist['title'];
                     $row->description = $playlist['description'];
                     $row->thumbnail_url = YouTube::getThumbnail($playlist['thumbnails']);
                 }
                 // Get playlist contents.
                 $data = $yt_client->getPlaylistItems($playlist_id);
                 foreach ((array) $data as $item) {
                     $row_name = self::filterName($row, $item['snippet']['title']);
                     $row_thumb = YouTube::getThumbnail($item['snippet']['thumbnails']);
                     // Apply name/thumbnail filtering to sub-videos.
                     if (!empty($row_name) && !empty($row_thumb)) {
                         $child_row = new ConventionArchive();
                         $child_row->convention = $row->convention;
                         $child_row->playlist_id = $row->id;
                         $child_row->type = 'yt_video';
                         $child_row->folder = $row->folder;
                         $child_row->name = $row_name;
                         $child_row->description = $item['snippet']['description'];
                         $child_row->web_url = 'http://www.youtube.com/watch?v=' . $item['id'];
                         $child_row->thumbnail_url = $row_thumb;
                         $em->persist($child_row);
                     }
                 }
                 $row->synchronized_at = time();
                 $em->persist($row);
                 break;
             case "yt_video":
             default:
                 // Pull video ID from any URL format.
                 if (preg_match('%(?:youtube(?:-nocookie)?\\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\\.be/)([^"&?/ ]{11})%i', $url, $match)) {
                     $video_id = $match[1];
                 } else {
                     break;
                 }
                 // Reformat video URL to match standard format.
                 $row->web_url = 'http://www.youtube.com/watch?v=' . $video_id;
                 // Pull data from API.
                 $data = $yt_client->videos->listVideos('snippet,contentDetails', array('id' => $video_id, 'maxResults' => 1));
                 if ($data) {
                     $video = $data['items'][0]['snippet'];
                     $row->name = self::filterName($row, $video['title']);
                     $row->description = $video['description'];
                     $row->thumbnail_url = YouTube::getThumbnail($video['thumbnails']);
                     $row->synchronized_at = time();
                     $em->persist($row);
                 }
                 break;
         }
     }
     $em->flush();
 }