Exemple #1
0
 private function getVideoFromURL($title, $url)
 {
     $url = parse_url($url);
     parse_str($url["query"], $query);
     if (strpos($url["host"], "youtube.com") !== false) {
         $source = "youtube";
         $id = $query["v"];
         $thumb = "https://img.youtube.com/vi/" . $id . "/hqdefault.jpg";
     }
     if ($source && $id && $thumb) {
         return VideoSource::create($title, $source, $id, $thumb);
     }
     return null;
 }
Exemple #2
0
 /**
  https://www.youtube.com/feeds/videos.xml?channel_id=CHANNELID
  https://www.youtube.com/feeds/videos.xml?user=USERNAME
  https://www.youtube.com/feeds/videos.xml?playlist_id=YOUR_YOUTUBE_PLAYLIST_NUMBER
 */
 public function rssUser()
 {
     foreach (YoutubeUser::find()->where('updated_at <=:sevenDay', [':sevenDay' => $this->sevenDaysAgo])->limit(10)->each() as $user) {
         $user->updateAttributes(['updated_at' => time()]);
         try {
             $i = 0;
             $content = @file_get_contents('https://www.youtube.com/feeds/videos.xml?user='******'entry'])) {
                 foreach ($youtube['entry'] as $value) {
                     if (isset($value['id'])) {
                         $id = $this->trimVideoId($value['id']);
                         $title = ArrayHelper::getValue($value, 'title', '');
                         if (!VideoSource::find()->where('code=:id', [':id' => $id])->exists()) {
                             $i++;
                             list($chanel, $category) = $this->getChannel($user->username, $value['author']['name'], $value['author']['uri']);
                             $model = new VideoSource();
                             $model->attributes = ['title' => $title, 'slug' => Common::renderSlug($title), 'code' => $id, 'category' => 0, 'channel' => $chanel, 'feature' => CmDefine::no, 'popular' => CmDefine::no, 'show_index' => 0, 'total_view' => rand(100, 10000), 'total_comment' => CmDefine::zeroNumber, 'total_like' => CmDefine::zeroNumber, 'total_dislike_number' => CmDefine::zeroNumber, 'avatar' => "//i.ytimg.com/vi/{$id}/mqdefault.jpg", 'tags' => '', 'description' => '', 'seo_title' => $title, 'seo_keyworks' => $title, 'seo_description' => $title, 'status' => CmDefine::status_pending, 'type' => VideoSource::TYPE_YOUTUBE];
                             $model->save();
                         }
                     }
                 }
             }
             $user->updateAttributes(['count_video' => $i]);
         } catch (Exception $exc) {
         }
     }
 }
    forward(REFERER);
}
if (empty($resolution)) {
    $resolution = $video->resolution;
}
// See if a source with the same format and resolution already exists
$existing = elgg_get_entities_from_metadata(array('type' => 'object', 'subtype' => 'video_source', 'container_guid' => $video->getGUID(), 'metadata_name_value_pairs' => array('format' => $format, 'resolution' => $resolution)));
if (!empty($existing)) {
    // Reconvert an existing source
    $source = $existing[0];
    $outputfile = $source->getFilenameOnFilestore();
} else {
    $basename = $video->getFilenameWithoutExtension();
    $filename = "video/{$video->getGUID()}/{$basename}_{$resolution}.{$format}";
    // Create a new entity that represents the physical file
    $source = new VideoSource();
    $source->format = $format;
    $source->setFilename($filename);
    $source->setMimeType("video/{$format}");
    $source->resolution = $resolution;
    $source->bitrate = $bitrate;
    $source->owner_guid = $video->getOwnerGUID();
    $source->container_guid = $video->getGUID();
    $source->access_id = $video->access_id;
    $source->save();
}
try {
    $converter = new VideoConverter();
    $converter->setInputfile($video->getFilenameOnFilestore());
    $converter->setOutputfile($source->getFilenameOnFilestore());
    $converter->setResolution($resolution);
Exemple #4
0
 /**
  * Create different video sources based on plugin configuration
  */
 public function setSources()
 {
     $flavors = video_get_flavor_settings();
     foreach ($flavors as $flavor) {
         $source = new VideoSource();
         $source->container_guid = $this->getGUID();
         $source->owner_guid = $this->getOwnerGUID();
         $source->access_id = $this->access_id;
         $source->conversion_done = false;
         if (empty($flavor['resolution'])) {
             $source->resolution = null;
             // Use resolution of the parent in the filename
             $resolution = $this->resolution;
         } else {
             $source->resolution = $flavor['resolution'];
             $resolution = $source->resolution;
         }
         if (empty($flavor['bitrate'])) {
             $source->bitrate = null;
         } else {
             $source->bitrate = $flavor['bitrate'];
         }
         $source->format = $flavor['format'];
         $basename = $this->getFilenameWithoutExtension();
         $filename = "video/{$this->getGUID()}/{$basename}_{$resolution}.{$source->format}";
         $source->setFilename($filename);
         $source->setMimeType("video/{$source->format}");
         $source->save();
     }
 }