/** * Confirm this is an NFO file. * * @param string $possibleNFO The nfo. * @param string $guid The guid of the release. * * @return bool True on success, False on failure. * * @access public */ public function isNFO(&$possibleNFO, $guid) { if ($possibleNFO === false) { return false; } // Make sure it's not too big or small, size needs to be at least 12 bytes for header checking. Ignore common file types. $size = strlen($possibleNFO); if ($size < 65535 && $size > 11 && !preg_match('/\\A(\\s*<\\?xml|=newz\\[NZB\\]=|RIFF|\\s*[RP]AR|.{0,10}(JFIF|matroska|ftyp|ID3))|;\\s*Generated\\s*by.*SF\\w/i', $possibleNFO)) { // File/GetId3 work with files, so save to disk. $tmpPath = $this->tmpPath . $guid . '.nfo'; file_put_contents($tmpPath, $possibleNFO); // Linux boxes have 'file' (so should Macs), Windows *can* have it too: see GNUWIN.txt in docs. $result = Utility::fileInfo($tmpPath); if (!empty($result)) { // Check if it's text. if (preg_match('/(ASCII|ISO-8859|UTF-(8|16|32).*?)\\s*text/', $result)) { @unlink($tmpPath); return true; // Or binary. } else { if (preg_match('/^(JPE?G|Parity|PNG|RAR|XML|(7-)?[Zz]ip)/', $result) || preg_match('/[\\x00-\\x08\\x12-\\x1F\\x0B\\x0E\\x0F]/', $possibleNFO)) { @unlink($tmpPath); return false; } } } // If above checks couldn't make a categorical identification, Use GetId3 to check if it's an image/video/rar/zip etc.. $getid3 = new getid3(); $check = $getid3->analyze($tmpPath); @unlink($tmpPath); if (isset($check['error'])) { // Check if it's a par2. $par2info = new Par2Info(); $par2info->setData($possibleNFO); if ($par2info->error) { // Check if it's an SFV. $sfv = new SfvInfo(); $sfv->setData($possibleNFO); if ($sfv->error) { return true; } } } } return false; }
public function write($filepath, $mimetype) { if (!$this->handle) { return false; } if (!($ext = $this->info["EXPORT"][$mimetype])) { # this plugin can't write this mimetype $this->postError(1610, _t("Can't convert '%1' to '%2': unsupported format", $this->handle["mime_type"], $mimetype), "WLPlugAudio->write()"); return false; } $o_config = Configuration::load(); $va_tags = $this->get("getID3_tags"); $vs_intro_filepath = $this->get("intro_filepath"); $vs_outro_filepath = $this->get("outro_filepath"); if (($vn_output_bitrate = $this->get("bitrate")) < 32) { $vn_output_bitrate = 64; } if (($vn_sample_frequency = $this->get("sample_frequency")) < 4096) { $vn_sample_frequency = 44100; } if (($vn_channels = $this->get("channels")) < 1) { $vn_channels = 1; } if ($this->properties["mimetype"] == $mimetype && !($this->properties["mimetype"] == "audio/mpeg" && ($vs_intro_filepath || $vs_outro_filepath)) && ($vn_output_bitrate == $this->input_bitrate && $vn_sample_frequency == $this->input_sample_frequency && $vn_channels == $this->input_channels)) { # write the file if (!copy($this->filepath, $filepath . "." . $ext)) { $this->postError(1610, _t("Couldn't write file to '%1'", $filepath), "WLPlugAudio->write()"); return false; } } else { if ($mimetype != "image/png" && $mimetype != "image/jpeg" && $this->opb_ffmpeg_available) { # # Do conversion # if ($mimetype == 'audio/ogg') { exec($this->ops_path_to_ffmpeg . " -f " . $this->info["IMPORT"][$this->properties["mimetype"]] . " -i " . caEscapeShellArg($this->filepath) . " -acodec libvorbis -ab " . $vn_output_bitrate . " -ar " . $vn_sample_frequency . " -ac " . $vn_channels . " -y " . caEscapeShellArg($filepath . "." . $ext) . " 2>&1", $va_output, $vn_return); } else { exec($this->ops_path_to_ffmpeg . " -f " . $this->info["IMPORT"][$this->properties["mimetype"]] . " -i " . caEscapeShellArg($this->filepath) . " -f " . $this->info["EXPORT"][$mimetype] . " -ab " . $vn_output_bitrate . " -ar " . $vn_sample_frequency . " -ac " . $vn_channels . " -y " . caEscapeShellArg($filepath . "." . $ext) . " 2>&1", $va_output, $vn_return); } if ($vn_return != 0) { @unlink($filepath . "." . $ext); $this->postError(1610, _t("Error converting file to %1 [%2]: %3", $this->typenames[$mimetype], $mimetype, join("; ", $va_output)), "WLPlugAudio->write()"); return false; } if ($mimetype == "audio/mpeg") { if ($vs_intro_filepath || $vs_outro_filepath) { // add intro $vs_tmp_filename = tempnam(caGetTempDirPath(), "audio"); if ($vs_intro_filepath) { exec($this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($vs_intro_filepath) . " -f mp3 -ab " . $vn_output_bitrate . " -ar " . $vn_sample_frequency . " -ac " . $vn_channels . " -y " . caEscapeShellArg($vs_tmp_filename), $va_output, $vn_return); if ($vn_return != 0) { @unlink($filepath . "." . $ext); $this->postError(1610, _t("Error converting intro to %1 [%2]: %3", $this->typenames[$mimetype], $mimetype, join("; ", $va_output)), "WLPlugAudio->write()"); return false; } } $r_fp = fopen($vs_tmp_filename, "a"); $r_mp3fp = fopen($filepath . "." . $ext, "r"); while (!feof($r_mp3fp)) { fwrite($r_fp, fread($r_mp3fp, 8192)); } fclose($r_mp3fp); if ($vs_outro_filepath) { $vs_tmp_outro_filename = tempnam(caGetTempDirPath(), "audio"); exec($this->ops_path_to_ffmpeg . " -i " . caEscapeShellArg($vs_outro_filepath) . " -f mp3 -ab " . $vn_output_bitrate . " -ar " . $vn_sample_frequency . " -ac " . $vn_channels . " -y " . caEscapeShellArg($vs_tmp_outro_filename), $va_output, $vn_return); if ($vn_return != 0) { @unlink($filepath . "." . $ext); $this->postError(1610, _t("Error converting outro to %1 [%2]: %3", $this->typenames[$mimetype], $mimetype, join("; ", $va_output)), "WLPlugAudio->write()"); return false; } $r_mp3fp = fopen($vs_tmp_outro_filename, "r"); while (!feof($r_mp3fp)) { fwrite($r_fp, fread($r_mp3fp, 8192)); } unlink($vs_tmp_outro_filename); } fclose($r_fp); copy($vs_tmp_filename, $filepath . "." . $ext); unlink($vs_tmp_filename); } $o_getid3 = new getid3(); $va_mp3_output_info = $o_getid3->analyze($filepath . "." . $ext); $this->properties = array(); if (is_array($va_mp3_output_info["tags"]["id3v1"]["title"])) { $this->properties["title"] = join("; ", $va_mp3_output_info["tags"]["id3v1"]["title"]); } if (is_array($va_mp3_output_info["tags"]["id3v1"]["artist"])) { $this->properties["author"] = join("; ", $va_mp3_output_info["tags"]["id3v1"]["artist"]); } if (is_array($va_mp3_output_info["tags"]["id3v1"]["comment"])) { $this->properties["copyright"] = join("; ", $va_mp3_output_info["tags"]["id3v1"]["comment"]); } if (is_array($va_mp3_output_info["tags"]["id3v1"]["album"]) && is_array($va_mp3_output_info["tags"]["id3v1"]["year"]) && is_array($va_mp3_output_info["tags"]["id3v1"]["genre"])) { $this->properties["description"] = join("; ", $va_mp3_output_info["tags"]["id3v1"]["album"]) . " " . join("; ", $va_mp3_output_info["tags"]["id3v1"]["year"]) . " " . join("; ", $va_mp3_output_info["tags"]["id3v1"]["genre"]); } $this->properties["type_specific"] = array("audio" => $va_mp3_output_info["audio"], "tags" => $va_mp3_output_info["tags"]); $this->properties["bandwidth"] = array("min" => $va_mp3_output_info["bitrate"], "max" => $va_mp3_output_info["bitrate"]); $this->properties["bitrate"] = $va_mp3_output_info["bitrate"]; $this->properties["channels"] = $va_mp3_output_info["audio"]["channels"]; $this->properties["sample_frequency"] = $va_mp3_output_info["audio"]["sample_rate"]; $this->properties["duration"] = $va_mp3_output_info["playtime_seconds"]; } } else { # use default media icons if ffmpeg is not present or the current version is an image if (!$this->get("width") && !$this->get("height")) { $this->set("width", 580); $this->set("height", 200); } return __CA_MEDIA_AUDIO_DEFAULT_ICON__; } } if ($mimetype == "audio/mpeg") { // try to write getID3 tags (if set) if (is_array($pa_options) && is_array($pa_options) && sizeof($pa_options) > 0) { require_once 'parsers/getid3/getid3.php'; require_once 'parsers/getid3/write.php'; $o_getID3 = new getID3(); $o_tagwriter = new getid3_writetags(); $o_tagwriter->filename = $filepath . "." . $ext; $o_tagwriter->tagformats = array('id3v2.3'); $o_tagwriter->tag_data = $pa_options; // write them tags if (!$o_tagwriter->WriteTags()) { // failed to write tags } } } $this->properties["mimetype"] = $mimetype; $this->properties["typename"] = $this->typenames[$mimetype]; return $filepath . "." . $ext; }
/** * Get duration of audio file * Uses getid3 class for calculation audio duration - http://www.getid3.org/ * @param string $file File name & path * @return mixed File duration on success, boolean false on failure */ public function get_file_duration($file) { if ($file) { if (!class_exists('getid3')) { require_once $this->assets_dir . '/getid3/getid3.php'; } $getid3 = new getid3(); // Identify file by root path and not URL (required for getID3 class) $site_root = trailingslashit(ABSPATH); $file = str_replace($this->home_url, $site_root, $file); $info = $getid3->analyze($file); $duration = false; if (isset($info['playtime_string']) && strlen($info['playtime_string']) > 0) { $duration = $info['playtime_string']; } else { if (isset($info['playtime_seconds']) && strlen($info['playtime_seconds']) > 0) { $duration = gmdate('H:i:s', $info['playtime_seconds']); } } return apply_filters('ssp_file_duration', $duration, $file); } return false; }
public function mobile_mp4($VideoTask) { $this->create(); $this->id = $VideoTask['VideoTask']['id']; $this->save(array("task_status" => "working")); //import objects $MediaFile = ClassRegistry::init("MediaFile"); App::import("Vendor", "LLFTP", array("LLFTP.php")); App::import("Vendor", "getid3", array("file" => "getid3/getid3.php")); $video = $MediaFile->find("first", array("conditions" => array("MediaFile.id" => $VideoTask['VideoTask']['foreign_key']), "contain" => array())); $llftp = new LLFTP(); $id3 = new getid3(); //let's download the video to tmp $tmp_file = $MediaFile->downloadVideoToTmp($VideoTask['VideoTask']['foreign_key']); //let's get the size of the FLV file $vid = $id3->analyze($tmp_file); $height = $vid['video']['resolution_y']; $width = $vid['video']['resolution_x']; $newFileName = str_replace(".mp4", ".mobile.mp4", $video['MediaFile']['limelight_file']); $newFilePath = "/home/sites/tmpfiles/" . $newFileName; //determine height and width if ($height == 394 && $width > 640 || $height == 720) { $height = 180; $width = 320; } else { $height = 240; $width = 320; } $cmd = "/usr/local/bin/ffmpeg -y -i {$tmp_file} -vcodec libx264 -vf 'scale={$width}:{$height}' {$newFilePath}"; SysMsg::add(array("category" => "MobileMp4", "from" => "VideoTask", "crontab" => 1, "title" => $cmd)); $this->query("SET SESSION wait_timeout = 28800"); $this->getDatasource()->disconnect(); $output = `{$cmd}`; $this->getDatasource()->connect(); //ftp the file $llftp->ftpFile($newFileName, $newFilePath); //update the video file $MediaFile->create(); $MediaFile->id = $video['MediaFile']['id']; $MediaFile->save(array("limelight_file_mobile" => $newFileName)); $this->create(); $this->id = $VideoTask['VideoTask']['id']; $this->save(array("task_status" => "completed")); }
<author>nicholas@aquarionics.com</author> <link>%s</link> <enclosure url="%s" length="%s" type="%s" /> <description>%s</description> <!-- end RSS 2.0 tags --> </item> EOW; $dir = './'; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file[0] == '.' || $file == "index.php") { continue; } $idthree = $getID3->analyze($dir . $file); getid3_lib_sigh::CopyTagsToComments($idthree); $url = 'http://cenote.gkhs.net/~aquarion/podcast/' . $file; $filesize = filesize($dir . $file); $filetype = mime_content_type($dir . $file); $desc = $title = $idthree['comments']['artist'][0] . ' ' . $idthree['comments']['title'][0]; $title = trim($title); if (empty($title)) { $title = 'Untitled Thing'; } printf($item, $title, $url, date('r'), $url, $url, $filesize, $filetype, $desc); } closedir($dh); } } echo <<<EOW