function proccess_streams($stream_name = 'all') { if ($stream_name == 'all') { $sql = "SELECT * FROM `mv_streams` LIMIT 0, 5000"; } else { $sql = "SELECT * FROM `mv_streams` WHERE `name` ={$stream_name}"; } $dbr = wfGetDB(DB_READ); $dbw = wfGetDB(DB_WRITE); $result = $dbr->query($sql); $skip_list = unserialize(file_get_contents(ARCHIVE_ORG_SKIP_LIST)); while ($stream = $dbr->fetchObject($result)) { $local_fl = MV_DOWNLOAD_DIR . $stream->name . '.flv'; $remote_fl = MV_ARCHIVE_ORG_DL . $stream->name . '/' . $stream->name . '.flv'; if (is_file($local_fl) . META_DATA_EXT && is_file($local_fl)) { // check db table for updated mv_flash_low_quality ref $sql = " SELECT * FROM `mv_stream_files` WHERE `stream_id`='" . $stream->id . "' " . " AND `file_desc_msg`='mv_flash_low_quality'"; $resFcheck = $dbr->query($sql); if ($dbr->numRows($resFcheck) == 0) { // grab duration from mv_ogg_low_quality $sql = " SELECT * FROM `mv_stream_files` WHERE `stream_id`='" . $stream->id . "' " . " AND `file_desc_msg`='mv_ogg_low_quality'"; $rdur = $dbr->query($sql); $dur_val = 0; if ($dbr->numRows($rdur)) { $ogg_file = $dbr->fetchObject($rdur); $dur_val = $ogg_file->duration; } $dbw->insert('mv_stream_files', array('stream_id' => $stream->id, 'duration' => $dur_val, 'file_desc_msg' => 'mv_flash_low_quality', 'path_type' => 'url_anx', 'path' => MV_BASE_MEDIA_SERVER_PATH . $stream->name . ".flv'")); print $dbw->lastQuery(); die; print "insert {$stream->name}.flv\n"; // $dbw->query($sql); } else { $file = $dbr->fetchObject($resFcheck); $dbr->update('mv_stream_files', array('path' => MV_BASE_MEDIA_SERVER_PATH . $stream->name . '.flv'), array('id' => $file->id), __METHOD__, array('LIMIT' => 1)); $dbw->query($sql); } } // lets just skip local files for now and try to remove incomplete mannually if (isset($skip_list[$stream->name])) { print "skipping:" . $stream->name . "\n"; continue; } // senate_proceeding_08-01-07/senate_proceeding_08-01-07.flv // check local file size matches remote: if (is_file($local_fl)) { print "file {$local_fl} present (skipping size check)\n"; /*if( filesize($local_fl)!=remotefsize($remote_fl)){ echo ' local:'. hr_bytes(filesize($local_fl)). ' != remote:' . hr_bytes(remotefsize($remote_fl))."\n"; echo '(skipping): ' . "\n"; //curldownload($remote_fl, $local_fl); }else{ echo ' sizes match: ' . hr_bytes(filesize($local_fl)) .'='. hr_bytes(remotefsize($remote_fl))."\n"; }*/ } else { // check if flash file exists: // $sql ="SELECT * FROM `mv_stream_files` WHERE `stream_id`=" .$stream->id // ao_file_flash_flv if (remotefsize($remote_fl) < 100000) { print "remote file: {$remote_fl} < 100k (skipping) \n"; $skip_list[$stream->name] = true; continue; } echo "DL it: {$remote_fl} \n"; if (curldownload($remote_fl, $local_fl)) { echo 'succesfully grabed ' . $remote_fl . "\n"; } } if (!is_file($local_fl) . META_DATA_EXT) { echo "gennerating flv metadata\n"; $flv = new MyFLV(); try { $flv->open($local_fl); } catch (Exception $e) { die("<pre>The following exception was detected while trying to open a FLV file:\n" . $e->getMessage() . "</pre>"); } $flv->getMetaData(); echo "done with .meta (" . filesize($local_fl . META_DATA_EXT) . ") \n"; } // add to skip list if (is_file($local_fl) . META_DATA_EXT && is_file($local_fl)) { $skip_list[$stream->name] = true; } file_put_contents(ARCHIVE_ORG_SKIP_LIST, serialize($skip_list)); } }
function do_request() { $file_req = filter_input(INPUT_GET, 'file', FILTER_SANITIZE_STRING); $time_req = filter_input(INPUT_GET, 't', FILTER_SANITIZE_STRING); //try to grab the file from /filename format if ($file_req == '') { if (isset($_SERVER['PHP_SELF'])) { $pathparts = explode('/', $_SERVER['PHP_SELF']); $file_req = strpos($pathparts[count($pathparts) - 1], '?') !== false ? substr($pathparts[count($pathparts) - 1], 0, strpos($pathparts[count($pathparts) - 1], '?')) : $pathparts[count($pathparts) - 1]; } } //additional filtering to avoid directory traversing: $file_req = str_replace(array('../', './'), '', $file_req); if ($file_req == '') { die('error: missing file name'); } $file_loc = BASE_LOCAL_CLIP_PATH . '/' . $file_req; if (!is_file($file_loc)) { die('error: requested file not found:' . $file_loc); } //if 't' is empty no seeking necessary: if ($time_req == '') { header('Content-type: ' . FLASH_VIDEO_CONTENT_TYPE); header('Content-Length: ' . filesize($file_loc)); output_full_file($file_loc); } else { //@@todo support more time request formats if (strpos($time_req, '/') !== false) { list($start_time_ntp, $end_time_ntp) = explode('/', $time_req); $start_sec = npt2seconds($start_time_ntp); $end_sec = npt2seconds($end_time_ntp); } else { $start_sec = npt2seconds($time_req); $end_sec = null; if ($start_sec == 0) { output_full_file($file_loc); } } if ($start_sec > $end_sec) { die('error: requested invalid time range'); } //print "DO: $start_sec $end_sec \n"; require_once 'MvFlv.php'; //open up the metavid Flv object: $flv = new MyFLV(); try { $flv->open($file_loc); } catch (Exception $e) { die("<pre>The following exception was detected while trying to open a FLV file:\n" . $e->getMessage() . "</pre>"); } header('Content-type: ' . FLASH_VIDEO_CONTENT_TYPE); $one_year = 60 * 60 * 24 * 365; header("Expires: " . gmdate("D, d M Y H:i:s", time() + $one_year) . " GM"); //small meta file to parse no big deal: list($start_byte, $end_byte) = $flv->getKeyFrameByteTimes($start_sec, $end_sec); //send out content length: header('Content-Length: ' . ($end_byte - $start_byte)); $flv->play($start_byte, $end_byte); //$end = microtime(true); //file_put_contents('/tmp/time.log', "<hr/>EXTRACT METADATA PROCESS TOOK " . number_format(($end-$start), 2) . " seconds<br />"); $flv->close(); } }
function update_flv_meta() { $path = '/metavid/video_archive/'; $flist = scandir($path); require_once '../skins/mv_embed/flvServer/MvFlv.php'; foreach ($flist as $local_fl) { print "lf: is_file(" . $path . $local_fl . ")\n"; if (is_file($path . $local_fl) && substr($local_fl, -3) == 'flv') { //check for .meta if (!is_file($path . $local_fl . '.meta')) { echo "generating flv metadata for {$path}{$local_fl} \n"; $flv = new MyFLV(); try { $flv->open($path . $local_fl); } catch (Exception $e) { die("<pre>The following exception was detected while trying to open a FLV file:\n" . $e->getMessage() . "</pre>"); } $flv->getMetaData(); echo "done with .meta (" . filesize($path . $local_fl . META_DATA_EXT) . ") \n"; } } } }
//give time for the proccess to start up while (is_process_running($pid)) { clearstatcache(); print "running trascode: " . hr_bytes(filesize($local_fl)) . "\n"; sleep(10); } //now it should be there if (is_file($local_fl)) { //flv is found print "flv found: " . $mvMountedDest . $stream_name . ".flv \n"; //check for .meta if (!is_file($local_fl . META_DATA_EXT)) { echo "gennerating flv metadata for {$local_fl} \n"; $flv = new MyFLV(); try { $flv->open($local_fl); } catch (Exception $e) { die("<pre>The following exception was detected while trying to open a FLV file:\n" . $e->getMessage() . "</pre>"); } $flv->getMetaData(); echo "done with .meta (" . filesize($local_fl . META_DATA_EXT) . ") \n"; } //update db: update_flv_pointer_db($stream_name); //remove the old local_file: if ($genNewFlv) { unlink($mvMountedDest . $stream_name . '.flv'); unlink($mvMountedDest . $stream_name . '.flv' . META_DATA_EXT); //move file to "live" location rename($local_fl, $mvMountedDest . $stream_name . '.flv'); rename($local_fl . META_DATA_EXT, $mvMountedDest . $stream_name . '.flv' . META_DATA_EXT);