From e1f154780b5b004e047977b6582dd19bf85d4e4d Mon Sep 17 00:00:00 2001 From: Calin-Andrei Burloiu Date: Fri, 11 Nov 2011 17:00:57 +0200 Subject: [PATCH] a simple MediaInfo API implemented as a helper in CodeIgniter useful for verifying if an uploaded video is valid --- .gitignore | 1 + application/controllers/catalog.php | 10 +-- application/helpers/av_info_helper.php | 105 +++++++++++++++++++++++++ application/models/users_model.php | 2 +- nbproject/private/private.properties | 1 + scripts/{sync.sh => sync_devel.sh} | 0 scripts/sync_prod.sh | 3 + 7 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 application/helpers/av_info_helper.php rename scripts/{sync.sh => sync_devel.sh} (100%) create mode 100755 scripts/sync_prod.sh diff --git a/.gitignore b/.gitignore index d06e4c1..b7df4ee 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ application/logs/*.php data/thumbs/* data/torrents/* data/user_pictures/* +data/media/* diff --git a/application/controllers/catalog.php b/application/controllers/catalog.php index da3548a..31bdc51 100644 --- a/application/controllers/catalog.php +++ b/application/controllers/catalog.php @@ -71,13 +71,9 @@ class Catalog extends CI_Controller { public function test() { - $data['email'] = 'CA-LăIN$*(_3@GMAIL.COM'; - $data['email'] = strtolower($data['email']); - $data['username'] = substr($data['email'], - 0, strpos($data['email'], '@')); - $data['username'] = preg_replace(array('/[^a-z0-9\._]*/'), - array(''), $data['username']); - echo $data['username']; + $this->load->helper('av_info'); + + var_dump(get_video_dar('./data/media/test.ogv')); } public function category($category_name, $ordering = 'hottest', $offset = 0) diff --git a/application/helpers/av_info_helper.php b/application/helpers/av_info_helper.php new file mode 100644 index 0000000..013dab3 --- /dev/null +++ b/application/helpers/av_info_helper.php @@ -0,0 +1,105 @@ +&1', 'r'); + + $r = fgets($h, 512); + $r = trim($r); + + if (pclose($h) > 0 || empty($r)) + return FALSE; + + return $r; +} + +/** + * Returns duration in hours, minutes and seconds for an audio/video file. + * + * @param string $file_name + * @return array an associative array with keys 'h', 'min', 's' + */ +function get_av_duration($file_name) +{ + $output = exec_mediainfo( + '--Inform="General;%Duration/String3%" "'. $file_name. '"'); + + if (!$output) + return FALSE; + + $toks = explode(':', $output); + $res['h'] = intval($toks[0]); + $res['min'] = intval($toks[1]); + $res['s'] = floatval($toks[2]); + + return $res; +} + +/** + * Returns video width size in pixels. + * + * @param string $file_name + * @return int + */ +function get_video_width($file_name) +{ + $output = exec_mediainfo( + '--Inform="Video;%Width%" "'. $file_name. '"'); + + if (!$output) + return FALSE; + + return intval($output); +} + +/** + * Returns video height size in pixels. + * + * @param string $file_name + * @return int + */ +function get_video_height($file_name) +{ + $output = exec_mediainfo( + '--Inform="Video;%Height%" "'. $file_name. '"'); + + if (!$output) + return FALSE; + + return intval($output); +} + +/** + * Returns Display Aspect Ration (DAR) of a video. + * + * @param string $file_name + * @return string a ratio represented a two integers separated by a colon + */ +function get_video_dar($file_name) +{ + $output = exec_mediainfo( + '--Inform="Video;%DisplayAspectRatio/String%" "'. $file_name. '"'); + + if (!$output) + return FALSE; + + return $output; +} + +/* End of file av_info_helper.php */ +/* Location: ./application/helpers/av_info_helper.php */ \ No newline at end of file diff --git a/application/models/users_model.php b/application/models/users_model.php index 85ad649..30e18d7 100644 --- a/application/models/users_model.php +++ b/application/models/users_model.php @@ -4,7 +4,7 @@ * Class Users_model models user information from DB * * @category Model - * @author calinburloiu + * @author Călin-Andrei Burloiu * */ class Users_model extends CI_Model { diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties index d3cda86..104ba6a 100644 --- a/nbproject/private/private.properties +++ b/nbproject/private/private.properties @@ -1,5 +1,6 @@ copy.src.files=false copy.src.target=/var/www/P2P-Tube +getter.setter.method.name.generation=AS_JAVA index.file=index.php run.as=LOCAL url=http://localhost/devel/ diff --git a/scripts/sync.sh b/scripts/sync_devel.sh similarity index 100% rename from scripts/sync.sh rename to scripts/sync_devel.sh diff --git a/scripts/sync_prod.sh b/scripts/sync_prod.sh new file mode 100755 index 0000000..a3151a6 --- /dev/null +++ b/scripts/sync_prod.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +rsync -avz ../ p2p-next@koala.cs.pub.ro:public_html/ -- 2.20.1