当前位置: 首页>>代码示例>>PHP>>正文


PHP Format::DurationToSeconds方法代码示例

本文整理汇总了PHP中Format::DurationToSeconds方法的典型用法代码示例。如果您正苦于以下问题:PHP Format::DurationToSeconds方法的具体用法?PHP Format::DurationToSeconds怎么用?PHP Format::DurationToSeconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Format的用法示例。


在下文中一共展示了Format::DurationToSeconds方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: PreProcess

 public function PreProcess()
 {
     $v = Validator::Create();
     $v->Register($this->source[Video_Source::FIELD_EMBED], Validator_Type::NOT_EMPTY, 'The Embed Code field is required');
     $v->Register($this->source[Video_Source::FIELD_DURATION], Validator_Type::VALID_TIME, 'The Video Duration field must be in HH:MM:SS format');
     $this->duration = Format::DurationToSeconds($this->source[Video_Source::FIELD_DURATION]);
     $this->video_dir = new Video_Dir(null, 0700);
     Request::FixFiles();
     // No thumbnails uploaded
     if (!isset($_FILES[Video_Source::FIELD_THUMBNAILS])) {
         return;
     }
     // Process each uploaded file
     foreach ($_FILES[Video_Source::FIELD_THUMBNAILS] as $upload) {
         // No file uploaded in this field
         if ($upload['error'] == UPLOAD_ERR_NO_FILE) {
             continue;
         }
         // Check for other errors
         if ($upload['error'] != UPLOAD_ERR_OK) {
             throw new BaseException(Uploads::CodeToMessage($upload['error']));
         }
         switch (File::Type($upload['name'])) {
             case File::TYPE_ZIP:
                 foreach (Zip::ExtractEntries($upload['tmp_name'], File::TYPE_JPEG) as $name => $data) {
                     $thumbs[] = $this->video_dir->AddTempFromVar($data, JPG_EXTENSION);
                 }
                 break;
             case File::TYPE_JPEG:
                 $thumbs[] = $this->video_dir->AddTempFromFile($upload['tmp_name'], JPG_EXTENSION);
                 break;
         }
     }
     // Resize (if possible) and move images to the correct directory
     if (Video_Thumbnail::CanResize()) {
         $this->thumbs = Video_Thumbnail::ResizeDirectory($this->video_dir->GetTempDir(), $this->video_dir->GetThumbsDir(), Config::Get('thumb_size'), Config::Get('thumb_quality'));
     } else {
         $this->thumbs = $this->video_dir->MoveFiles(Video_Dir::TEMP, Video_Dir::THUMBS, JPG_EXTENSION);
     }
     // Cleanup temp and processing dirs
     $this->video_dir->ClearTemp();
     $this->video_dir->ClearProcessing();
 }
开发者ID:hackingman,项目名称:TubeX,代码行数:43,代码来源:Embed.php

示例2: tbxUploadStepTwo

function tbxUploadStepTwo()
{
    global $t;
    $upload = $_FILES['video_file'];
    $v = Validator::Create();
    $DB = GetDB();
    $v->Register(sha1($_REQUEST['step_one_data'] . Config::Get('random_value')) == $_REQUEST['step_one_sig'], Validator_Type::IS_TRUE, _T('Validation:Video Data Altered'));
    $v->Register($upload['error'] == UPLOAD_ERR_OK, Validator_Type::IS_TRUE, Uploads::CodeToMessage($upload['error']));
    if (is_uploaded_file($upload['tmp_name'])) {
        $max_filesize = Format::StringToBytes(Config::Get('max_upload_size'));
        $max_duration = Format::DurationToSeconds(Config::Get('max_upload_duration'));
        $extensions = str_replace(',', '|', Config::Get('upload_extensions'));
        $v->Register($upload['size'], Validator_Type::IS_BETWEEN, _T('Validation:Video size too large'), '1,' . $max_filesize);
        $v->Register(File::Extension($upload['name']), Validator_Type::REGEX_MATCH, _T('Validation:Video file extension not allowed'), '~^(' . $extensions . ')$~');
        try {
            $vi = new Video_Info($upload['tmp_name']);
            $vi->Extract();
            $v->Register($vi->length, Validator_Type::LESS_EQ, _T('Validation:Video duration too long'), $max_duration);
        } catch (Exception $e) {
            $v->Register(false, Validator_Type::IS_TRUE, $e->getMessage());
        }
        $md5 = md5_file($upload['tmp_name']);
        if (Config::Get('flag_upload_reject_duplicates')) {
            $v->Register($DB->QueryCount('SELECT COUNT(*) FROM `tbx_video_md5sum` WHERE `md5`=?', array($md5)), Validator_Type::IS_ZERO, _T('Validation:Duplicate video'));
        }
    }
    // Validate input
    if (!$v->Validate()) {
        $t->Assign('g_errors', $v->GetErrors());
        $t->AssignByRef('g_form', $_REQUEST);
        if (isset($_REQUEST['flash'])) {
            $t->Display('upload-flash-errors.tpl');
        } else {
            $t->Assign('g_file_types', '*.' . str_replace(',', ';*.', Config::Get('upload_extensions')));
            $t->Assign('g_cookie', $_COOKIE[LOGIN_COOKIE]);
            $t->Display('upload-step-two.tpl');
        }
        return;
    }
    $_REQUEST = array_merge($_REQUEST, unserialize(base64_decode($_REQUEST['step_one_data'])));
    Form_Prepare::Standard('tbx_video');
    Form_Prepare::Standard('tbx_video_stat');
    Form_Prepare::Custom('tbx_video_custom_schema', 'on_submit');
    $_REQUEST['duration'] = $vi->length;
    $_REQUEST['date_added'] = Database_MySQL::Now();
    $_REQUEST['username'] = AuthenticateUser::GetUsername();
    $_REQUEST['is_private'] = Config::Get('flag_upload_allow_private') ? intval($_REQUEST['is_private']) : 0;
    $_REQUEST['allow_ratings'] = intval($_REQUEST['allow_ratings']);
    $_REQUEST['allow_embedding'] = intval($_REQUEST['allow_embedding']);
    $_REQUEST['allow_comments'] = intval($_REQUEST['allow_comments']) ? 'Yes - Add Immediately' : 'No';
    $_REQUEST['is_user_submitted'] = 1;
    if ($_REQUEST['recorded_day'] && $_REQUEST['recorded_month'] && $_REQUEST['recorded_year']) {
        $_REQUEST['date_recorded'] = $_REQUEST['recorded_year'] . '-' . $_REQUEST['recorded_month'] . '-' . $_REQUEST['recorded_day'];
    }
    // Strip HTML tags
    if (Config::Get('flag_video_strip_tags')) {
        $_REQUEST = String::StripTags($_REQUEST);
    }
    // Configure status
    $_REQUEST['status'] = STATUS_ACTIVE;
    if (Config::Get('flag_upload_convert')) {
        $_REQUEST['status'] = STATUS_QUEUED;
        $_REQUEST['next_status'] = Config::Get('flag_upload_review') ? STATUS_PENDING : STATUS_ACTIVE;
    } else {
        if (Config::Get('flag_upload_review')) {
            $_REQUEST['status'] = STATUS_PENDING;
        }
    }
    // Add to database
    $_REQUEST['video_id'] = DatabaseAdd('tbx_video', $_REQUEST);
    DatabaseAdd('tbx_video_custom', $_REQUEST);
    DatabaseAdd('tbx_video_stat', $_REQUEST);
    if ($_REQUEST['status'] == STATUS_ACTIVE && !$_REQUEST['is_private']) {
        Tags::AddToFrequency($_REQUEST['tags']);
    } else {
        if ($_REQUEST['status'] == STATUS_QUEUED) {
            DatabaseAdd('tbx_conversion_queue', array('video_id' => $_REQUEST['video_id'], 'queued' => time()));
        }
    }
    // Mark as private
    if ($_REQUEST['is_private']) {
        $_REQUEST['private_id'] = sha1(uniqid(rand(), true));
        DatabaseAdd('tbx_video_private', $_REQUEST);
    }
    // Setup video files and generate thumbnails
    $directory = Video_Dir::DirNameFromId($_REQUEST['video_id']);
    $vd = new Video_Dir($directory);
    $clip = $vd->AddClipFromFile($upload['tmp_name'], File::Extension($upload['name']));
    if (Video_FrameGrabber::CanGrab()) {
        Video_FrameGrabber::Grab($clip, $vd->GetThumbsDir(), Config::Get('thumb_amount'), Config::Get('thumb_quality'), Config::Get('thumb_size'), $vi);
    }
    foreach ($vd->GetClipURIs() as $clip) {
        $_REQUEST['clip'] = $clip;
        $_REQUEST['filesize'] = filesize(Config::Get('document_root') . $clip);
        DatabaseAdd('tbx_video_clip', $_REQUEST);
    }
    $thumb_ids = array();
    foreach ($vd->GetThumbURIs() as $thumb) {
        $_REQUEST['thumbnail'] = $thumb;
        $thumb_ids[] = DatabaseAdd('tbx_video_thumbnail', $_REQUEST);
//.........这里部分代码省略.........
开发者ID:hackingman,项目名称:TubeX,代码行数:101,代码来源:upload.php

示例3: tbxVideoBulkEdit

function tbxVideoBulkEdit($phase)
{
    switch ($phase) {
        case Phase::PRE_UPDATE:
            $field = func_get_arg(1);
            $value = func_get_arg(2);
            $action = func_get_arg(3);
            $v = Validator::Create();
            switch ($field) {
                case 'sponsor_id':
                    if ($action == BulkEdit::ACTION_SET) {
                        $DB = GetDB();
                        $value = $DB->QuerySingleColumn('SELECT `sponsor_id` FROM `tbx_sponsor` WHERE `name`=?', array($value));
                        $v->Register(empty($value), Validator_Type::IS_FALSE, 'The Sponsor name entered is not valid');
                    }
                    break;
                case 'category_id':
                    $DB = GetDB();
                    $value = $DB->QuerySingleColumn('SELECT `category_id` FROM `tbx_category` WHERE `name`=?', array($value));
                    $v->Register(empty($value), Validator_Type::IS_FALSE, 'The Category name entered is not valid');
                    break;
                case 'username':
                    if ($action == BulkEdit::ACTION_SET) {
                        $DB = GetDB();
                        $value = $DB->QuerySingleColumn('SELECT `username` FROM `tbx_user` WHERE `username`=?', array($value));
                        $v->Register(empty($value), Validator_Type::IS_FALSE, 'The Username entered is not valid');
                    }
                    break;
                case 'duration':
                    if (preg_match('~(\\d\\d:\\d\\d:\\d\\d)~', $value, $matches)) {
                        $value = Format::DurationToSeconds($matches[1]);
                    }
                    break;
            }
            return $value;
        case Phase::POST_UPDATE:
            $field = func_get_arg(1);
            switch ($field) {
                case 'category_id':
                    UpdateCategoryStats();
                    break;
                case 'sponsor_id':
                    UpdateSponsorStats();
                    break;
            }
            break;
    }
}
开发者ID:hackingman,项目名称:TubeX,代码行数:48,代码来源:ajax.php

示例4: Import

 public static function Import($settings)
 {
     $DB = GetDB();
     ProgressBarShow('pb-import');
     $file = TEMP_DIR . '/' . File::Sanitize($settings['import_file']);
     $fp = fopen($file, 'r');
     $filesize = filesize($file);
     $line = $read = $imported = 0;
     $expected = count($settings['fields']);
     while (!feof($fp)) {
         $line++;
         $string = fgets($fp);
         $read += strlen($string);
         $data = explode($settings['delimiter'], trim($string));
         ProgressBarUpdate('pb-import', $read / $filesize * 100);
         // Line does not have the expected number of fields
         if (count($data) != $expected) {
             continue;
         }
         $video = array();
         $defaults = array('category_id' => $settings['category_id'], 'sponsor_id' => $settings['sponsor_id'], 'username' => $settings['username'], 'duration' => Format::DurationToSeconds($settings['duration']), 'status' => $settings['status'], 'next_status' => $settings['status'], 'allow_comments' => $settings['allow_comments'], 'allow_ratings' => $settings['allow_ratings'], 'allow_embedding' => $settings['allow_embedding'], 'is_private' => $settings['is_private'], 'date_added' => Database_MySQL::Now(), 'is_featured' => 0, 'is_user_submitted' => 0, 'conversion_failed' => 0, 'tags' => null, 'title' => null, 'description' => null);
         foreach ($settings['fields'] as $index => $field) {
             if (!empty($field)) {
                 $video[$field] = trim($data[$index]);
             }
         }
         // Setup clips
         $clips = array();
         $thumbs = array();
         $clip_type = 'URL';
         if (isset($video['embed_code'])) {
             // Cannot convert or thumbnail from embed code
             $settings['flag_convert'] = $settings['flag_thumb'] = false;
             $clips[] = $video['embed_code'];
             $clip_type = 'Embed';
         } else {
             if (isset($video['gallery_url'])) {
                 $http = new HTTP();
                 if (!$http->Get($video['gallery_url'])) {
                     // Broken gallery URL, continue
                     continue;
                 }
                 list($thumbs, $clips) = Video_Source_Gallery::ExtractUrls($http->url, $http->body);
             } else {
                 if (!isset($video['video_url']) && isset($video['base_video_url'])) {
                     if (!preg_match('~/$~', $video['base_video_url'])) {
                         $video['base_video_url'] .= '/';
                     }
                     foreach (explode(',', $video['video_filename']) as $filename) {
                         $clips[] = $video['base_video_url'] . $filename;
                     }
                 } else {
                     $clips[] = $video['video_url'];
                 }
             }
         }
         // Check for duplicate clips
         $duplicate = false;
         foreach ($clips as $clip) {
             if (!Request::Get('flag_skip_imported_check') && $DB->QueryCount('SELECT COUNT(*) FROM `tbx_imported` WHERE `video_url`=?', array($clip)) > 0) {
                 $duplicate = true;
             }
             $DB->Update('REPLACE INTO `tbx_imported` VALUES (?)', array($clip));
         }
         // Dupe found
         if ($duplicate) {
             continue;
         }
         // Setup thumbs
         if (!isset($video['gallery_url']) && !isset($video['thumbnail_url']) && isset($video['base_thumbnail_url'])) {
             if (!preg_match('~/$~', $video['base_thumbnail_url'])) {
                 $video['base_thumbnail_url'] .= '/';
             }
             foreach (explode(',', String::FormatCommaSeparated($video['thumbnail_filename'])) as $filename) {
                 $thumbs[] = $video['base_thumbnail_url'] . $filename;
             }
         } else {
             if (!isset($video['gallery_url']) && isset($video['thumbnail_url'])) {
                 $thumbs[] = $video['thumbnail_url'];
             }
         }
         // Setup duration
         if (isset($video['duration_seconds'])) {
             $video['duration'] = $video['duration_seconds'];
         } else {
             if (isset($video['duration_formatted'])) {
                 $video['duration'] = Format::DurationToSeconds($video['duration_formatted']);
             }
         }
         // Use description for title
         if (empty($video['title'])) {
             $video['title'] = isset($video['description']) ? $video['description'] : '';
         }
         // Use title for description
         if (empty($video['description'])) {
             $video['description'] = isset($video['title']) ? $video['title'] : '';
         }
         // Use title for tags
         if (empty($video['tags'])) {
             $video['tags'] = isset($video['title']) ? $video['title'] : '';
//.........这里部分代码省略.........
开发者ID:hackingman,项目名称:TubeX,代码行数:101,代码来源:Import.php

示例5: PreProcess

 public function PreProcess()
 {
     $this->video_dir = new Video_Dir(null, 0700);
     $thumbs = array();
     $clips = array();
     foreach ($this->source[Video_Source::FIELD_URLS] as $url) {
         $url_path = parse_url($url, PHP_URL_PATH);
         switch (File::Type($url_path)) {
             case File::TYPE_ZIP:
                 $http = new HTTP();
                 if ($http->Get($url, $url)) {
                     $zip = $this->video_dir->AddTempFromVar($http->body, ZIP_EXTENSION);
                     foreach (Zip::ExtractEntries($zip, File::TYPE_JPEG) as $name => $data) {
                         $thumbs[] = $this->video_dir->AddTempFromVar($data, JPG_EXTENSION);
                     }
                     foreach (Zip::ExtractEntries($zip, File::TYPE_VIDEO) as $name => $data) {
                         $this->clips[] = $this->video_dir->AddClipFromVar($data, File::Extension($name));
                     }
                 }
                 break;
             case File::TYPE_JPEG:
                 $http = new HTTP();
                 if ($http->Get($url, $url)) {
                     $thumbs[] = $this->video_dir->AddTempFromVar($http->body, JPG_EXTENSION);
                 }
                 break;
             case File::TYPE_VIDEO:
                 if ($this->source[Video_Source::FLAG_HOTLINK]) {
                     $clips[] = $url;
                     $this->duration = Format::DurationToSeconds($this->source[Video_Source::FIELD_DURATION]);
                 } else {
                     $http = new HTTP();
                     if ($http->Get($url, $url)) {
                         $this->clips[] = $this->video_dir->AddClipFromVar($http->body, File::Extension($http->url));
                     }
                 }
                 break;
         }
     }
     if (empty($clips)) {
         if (!empty($this->clips) && Video_Info::CanExtract() && Video_FrameGrabber::CanGrab()) {
             $amount = round(Config::Get('thumb_amount') / count($this->clips));
             foreach ($this->clips as $clip) {
                 $vi = new Video_Info($clip);
                 $vi->Extract();
                 $this->duration += $vi->length;
                 $temp_thumbs = Video_FrameGrabber::Grab($clip, $this->video_dir->GetProcessingDir(), $amount, Config::Get('thumb_quality'), Config::Get('thumb_size'));
                 // Move generated thumbs from the processing directory
                 foreach ($temp_thumbs as $temp_thumb) {
                     $this->thumbs[] = $this->video_dir->AddThumbFromFile($temp_thumb);
                 }
                 $this->video_dir->ClearProcessing();
             }
         }
     } else {
         $this->clips = $clips;
     }
     if (empty($this->clips)) {
         throw new BaseException('No valid video URLs were submitted');
     }
     // Use images from supplied URLs if none could be generated
     if (empty($this->thumbs) && !empty($thumbs)) {
         if (Video_Thumbnail::CanResize()) {
             $this->thumbs = Video_Thumbnail::ResizeDirectory($this->video_dir->GetTempDir(), $this->video_dir->GetThumbsDir(), Config::Get('thumb_size'), Config::Get('thumb_quality'));
         } else {
             $this->thumbs = $this->video_dir->MoveFiles($this->video_dir->GetTempDir(), $this->video_dir->GetThumbsDir(), JPG_EXTENSION);
         }
     }
     // Cleanup temp and processing dirs
     $this->video_dir->ClearTemp();
     $this->video_dir->ClearProcessing();
 }
开发者ID:hackingman,项目名称:TubeX,代码行数:72,代码来源:URL.php

示例6: PreProcess

 public function PreProcess()
 {
     $this->video_dir = new Video_Dir(null, 0700);
     $http = new HTTP();
     if (!$http->Get($this->source[Video_Source::FIELD_GALLERY])) {
         throw new BaseException('Could not access gallery: ' . $http->error);
     }
     list($thumbs, $clips) = self::ExtractUrls($http->url, $http->body);
     if (empty($clips)) {
         throw new BaseException('No video files could be located on this gallery');
     }
     // Hotlinking video from gallery
     if ($this->source[Video_Source::FLAG_HOTLINK]) {
         $this->clips = $clips;
         $this->duration = Format::DurationToSeconds($this->source[Video_Source::FIELD_DURATION]);
     } else {
         // Download clips
         $amount = round(Config::Get('thumb_amount') / count($clips));
         foreach ($clips as $clip) {
             $chttp = new HTTP();
             if ($chttp->Get($clip, $http->url)) {
                 $clip = $this->video_dir->AddClipFromVar($chttp->body, File::Extension($chttp->url));
                 $this->clips[] = $clip;
                 $vi = new Video_Info($clip);
                 $vi->Extract();
                 $this->duration += $vi->length;
                 $temp_thumbs = Video_FrameGrabber::Grab($clip, $this->video_dir->GetProcessingDir(), $amount, Config::Get('thumb_quality'), Config::Get('thumb_size'));
                 // Move generated thumbs from the processing directory
                 foreach ($temp_thumbs as $temp_thumb) {
                     $this->thumbs[] = $this->video_dir->AddThumbFromFile($temp_thumb);
                 }
                 $this->video_dir->ClearProcessing();
             }
         }
     }
     // Download thumbs from gallery if none could be created from the video files
     // or video files are being hotlinked
     if (empty($this->thumbs)) {
         foreach ($thumbs as $thumb) {
             $coords = null;
             if (preg_match('~^\\[(.*?)\\](.*)~', $thumb, $matches)) {
                 $coords = $matches[1];
                 $thumb = $matches[2];
             }
             $thttp = new HTTP();
             if ($thttp->Get($thumb, $http->url)) {
                 $temp_file = $this->video_dir->AddTempFromVar($thttp->body, JPG_EXTENSION);
                 $imgsize = @getimagesize($temp_file);
                 $aspect = $imgsize !== false ? $imgsize[0] / $imgsize[1] : 0;
                 if ($imgsize !== false && $aspect >= self::MIN_ASPECT && $aspect <= self::MAX_ASPECT) {
                     if (Video_Thumbnail::CanResize()) {
                         $this->thumbs[] = Video_Thumbnail::Resize($temp_file, Config::Get('thumb_size'), Config::Get('thumb_quality'), $this->video_dir->GetThumbsDir(), $coords);
                     } else {
                         $this->thumbs[] = $this->video_dir->AddThumbFromFile($temp_file, JPG_EXTENSION);
                     }
                 } else {
                     unlink($temp_file);
                 }
             }
         }
     }
     // Cleanup temp and processing dirs
     $this->video_dir->ClearTemp();
     $this->video_dir->ClearProcessing();
 }
开发者ID:hackingman,项目名称:TubeX,代码行数:65,代码来源:Gallery.php


注:本文中的Format::DurationToSeconds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。