format
This commit is contained in:
parent
6284f3bcb8
commit
1159ba2fa1
7 changed files with 29 additions and 35 deletions
|
@ -9,8 +9,9 @@ class CommandBuilder
|
||||||
private $args = [];
|
private $args = [];
|
||||||
public $output;
|
public $output;
|
||||||
|
|
||||||
function __construct(String $executable) {
|
public function __construct(String $executable)
|
||||||
if(empty($executable)) {
|
{
|
||||||
|
if (empty($executable)) {
|
||||||
throw new InvalidArgumentException("executable cannot be empty");
|
throw new InvalidArgumentException("executable cannot be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ class CommandBuilder
|
||||||
public function generate(): string
|
public function generate(): string
|
||||||
{
|
{
|
||||||
$command = escapeshellarg($this->executable);
|
$command = escapeshellarg($this->executable);
|
||||||
if(!empty($this->args)) {
|
if (!empty($this->args)) {
|
||||||
$command .= " ";
|
$command .= " ";
|
||||||
$command .= join(" ", $this->args);
|
$command .= join(" ", $this->args);
|
||||||
}
|
}
|
||||||
|
@ -40,12 +41,11 @@ class CommandBuilder
|
||||||
|
|
||||||
public function combineOutput(string $empty_output = ""): string
|
public function combineOutput(string $empty_output = ""): string
|
||||||
{
|
{
|
||||||
if(empty($this->output)) {
|
if (empty($this->output)) {
|
||||||
return $empty_output;
|
return $empty_output;
|
||||||
} else {
|
} else {
|
||||||
return implode("\r\n", $this->output);
|
return implode("\r\n", $this->output);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(bool $fail_on_non_zero_return = false): int
|
public function execute(bool $fail_on_non_zero_return = false): int
|
||||||
|
@ -57,7 +57,7 @@ class CommandBuilder
|
||||||
|
|
||||||
log_debug('command_builder', "Command `$cmd` returned $ret and outputted $output");
|
log_debug('command_builder', "Command `$cmd` returned $ret and outputted $output");
|
||||||
|
|
||||||
if($fail_on_non_zero_return&&(int)$ret!==(int)0) {
|
if ($fail_on_non_zero_return&&(int)$ret!==(int)0) {
|
||||||
throw new SCoreException("Command `$cmd` failed, returning $ret and outputting $output");
|
throw new SCoreException("Command `$cmd` failed, returning $ret and outputting $output");
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Eokm extends Extension
|
||||||
$username = $config->get_string("eokm_username");
|
$username = $config->get_string("eokm_username");
|
||||||
$password = $config->get_string("eokm_password");
|
$password = $config->get_string("eokm_password");
|
||||||
|
|
||||||
if($username && $password) {
|
if ($username && $password) {
|
||||||
$ch = curl_init("https://api.eokmhashdb.nl/v1/check/md5");
|
$ch = curl_init("https://api.eokmhashdb.nl/v1/check/md5");
|
||||||
// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $additionalHeaders));
|
// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $additionalHeaders));
|
||||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||||
|
@ -21,18 +21,16 @@ class Eokm extends Extension
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||||
curl_setopt($ch, CURLOPT_POST, 1);
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $event->image->hash);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $event->image->hash);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
$return = curl_exec($ch);
|
$return = curl_exec($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
if($return == "false") {
|
if ($return == "false") {
|
||||||
// all ok
|
// all ok
|
||||||
}
|
} elseif ($return == "true") {
|
||||||
elseif($return == "true") {
|
|
||||||
log_warning("eokm", "User tried to upload banned image {$event->image->hash}");
|
log_warning("eokm", "User tried to upload banned image {$event->image->hash}");
|
||||||
throw new UploadException("Image banned");
|
throw new UploadException("Image banned");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
log_warning("eokm", "Unexpected return from EOKM: $return");
|
log_warning("eokm", "Unexpected return from EOKM: $return");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,8 +97,8 @@ class VideoFileHandler extends DataHandlerExtension
|
||||||
$event->image->video = $video;
|
$event->image->video = $video;
|
||||||
$event->image->video_codec = $video_codec;
|
$event->image->video_codec = $video_codec;
|
||||||
$event->image->audio = $audio;
|
$event->image->audio = $audio;
|
||||||
if($event->image->get_mime()==MimeType::MKV &&
|
if ($event->image->get_mime()==MimeType::MKV &&
|
||||||
VideoContainers::is_video_codec_supported(VideoContainers::WEBM,$event->image->video_codec)) {
|
VideoContainers::is_video_codec_supported(VideoContainers::WEBM, $event->image->video_codec)) {
|
||||||
// WEBMs are MKVs with the VP9 or VP8 codec
|
// WEBMs are MKVs with the VP9 or VP8 codec
|
||||||
// For browser-friendliness, we'll just change the mime type
|
// For browser-friendliness, we'll just change the mime type
|
||||||
$event->image->set_mime(MimeType::WEBM);
|
$event->image->set_mime(MimeType::WEBM);
|
||||||
|
|
|
@ -592,8 +592,8 @@ class Media extends Extension
|
||||||
|
|
||||||
$file_arg = "${input_ext}:\"${input_path}[0]\"";
|
$file_arg = "${input_ext}:\"${input_path}[0]\"";
|
||||||
|
|
||||||
if($resize_type===Media::RESIZE_TYPE_FIT_BLUR_PORTRAIT) {
|
if ($resize_type===Media::RESIZE_TYPE_FIT_BLUR_PORTRAIT) {
|
||||||
if($new_height>$new_width) {
|
if ($new_height>$new_width) {
|
||||||
$resize_type = Media::RESIZE_TYPE_FIT_BLUR;
|
$resize_type = Media::RESIZE_TYPE_FIT_BLUR;
|
||||||
} else {
|
} else {
|
||||||
$resize_type = Media::RESIZE_TYPE_FILL;
|
$resize_type = Media::RESIZE_TYPE_FILL;
|
||||||
|
|
|
@ -33,8 +33,8 @@ abstract class VideoContainers
|
||||||
|
|
||||||
public static function is_video_codec_supported(string $container, string $codec): bool
|
public static function is_video_codec_supported(string $container, string $codec): bool
|
||||||
{
|
{
|
||||||
return array_key_exists($container,self::VIDEO_CODEC_SUPPORT) &&
|
return array_key_exists($container, self::VIDEO_CODEC_SUPPORT) &&
|
||||||
in_array($codec,self::VIDEO_CODEC_SUPPORT[$container]);
|
in_array($codec, self::VIDEO_CODEC_SUPPORT[$container]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,8 @@ class TranscodeVideo extends Extension
|
||||||
|
|
||||||
if ($event->image->video===true && $user->can(Permissions::EDIT_FILES)) {
|
if ($event->image->video===true && $user->can(Permissions::EDIT_FILES)) {
|
||||||
$options = self::get_output_options($event->image->get_mime(), $event->image->video_codec);
|
$options = self::get_output_options($event->image->get_mime(), $event->image->video_codec);
|
||||||
if(!empty($options)&&sizeof($options)>1) {
|
if (!empty($options)&&sizeof($options)>1) {
|
||||||
$event->add_part($this->theme->get_transcode_html($event->image,$options));
|
$event->add_part($this->theme->get_transcode_html($event->image, $options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ class TranscodeVideo extends Extension
|
||||||
// transcodes recorded already, otherwise the image entries will be stuck pointing to
|
// transcodes recorded already, otherwise the image entries will be stuck pointing to
|
||||||
// missing image files
|
// missing image files
|
||||||
$database->commit();
|
$database->commit();
|
||||||
if($output_image!=$image) {
|
if ($output_image!=$image) {
|
||||||
$total++;
|
$total++;
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
@ -187,11 +187,11 @@ class TranscodeVideo extends Extension
|
||||||
|
|
||||||
|
|
||||||
foreach (VideoContainers::ALL as $container) {
|
foreach (VideoContainers::ALL as $container) {
|
||||||
if($starting_container==$container) {
|
if ($starting_container==$container) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!empty($starting_codec)&&
|
if (!empty($starting_codec)&&
|
||||||
!VideoContainers::is_video_codec_supported($container,$starting_codec)) {
|
!VideoContainers::is_video_codec_supported($container, $starting_codec)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$description = MimeMap::get_name_for_mime($container);
|
$description = MimeMap::get_name_for_mime($container);
|
||||||
|
@ -202,16 +202,16 @@ class TranscodeVideo extends Extension
|
||||||
|
|
||||||
private function transcode_and_replace_video(Image $image, String $target_mime): Image
|
private function transcode_and_replace_video(Image $image, String $target_mime): Image
|
||||||
{
|
{
|
||||||
if($image->get_mime()==$target_mime) {
|
if ($image->get_mime()==$target_mime) {
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($image->video==null||($image->video===true && empty($image->video_codec))) {
|
if ($image->video==null||($image->video===true && empty($image->video_codec))) {
|
||||||
// If image predates the media system, or the video codec support, run a media check
|
// If image predates the media system, or the video codec support, run a media check
|
||||||
send_event(new MediaCheckPropertiesEvent($image));
|
send_event(new MediaCheckPropertiesEvent($image));
|
||||||
$image->save_to_db();
|
$image->save_to_db();
|
||||||
}
|
}
|
||||||
if(empty($image->video_codec)) {
|
if (empty($image->video_codec)) {
|
||||||
throw new VideoTranscodeException("Cannot transcode item $image->id because its video codec is not known");
|
throw new VideoTranscodeException("Cannot transcode item $image->id because its video codec is not known");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,12 +237,10 @@ class TranscodeVideo extends Extension
|
||||||
send_event(new ImageReplaceEvent($image->id, $new_image));
|
send_event(new ImageReplaceEvent($image->id, $new_image));
|
||||||
|
|
||||||
return $new_image;
|
return $new_image;
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
/* Remove temporary file */
|
/* Remove temporary file */
|
||||||
@unlink($tmp_filename);
|
@unlink($tmp_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,7 +248,7 @@ class TranscodeVideo extends Extension
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
if(empty($source_video_codec)) {
|
if (empty($source_video_codec)) {
|
||||||
throw new VideoTranscodeException("Cannot transcode item because it's video codec is not known");
|
throw new VideoTranscodeException("Cannot transcode item because it's video codec is not known");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +265,7 @@ class TranscodeVideo extends Extension
|
||||||
$command->add_flag("-i");
|
$command->add_flag("-i");
|
||||||
$command->add_escaped_arg($source_file);
|
$command->add_escaped_arg($source_file);
|
||||||
|
|
||||||
if(!VideoContainers::is_video_codec_supported($target_mime, $source_video_codec)) {
|
if (!VideoContainers::is_video_codec_supported($target_mime, $source_video_codec)) {
|
||||||
throw new VideoTranscodeException("Cannot transcode item to $target_mime because it does not support the video codec $source_video_codec");
|
throw new VideoTranscodeException("Cannot transcode item to $target_mime because it does not support the video codec $source_video_codec");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,6 +287,4 @@ class TranscodeVideo extends Extension
|
||||||
|
|
||||||
return $target_file;
|
return $target_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ class CustomViewImageTheme extends ViewImageTheme
|
||||||
<br>Filesize: $h_filesize
|
<br>Filesize: $h_filesize
|
||||||
<br>Type: ".$h_type."
|
<br>Type: ".$h_type."
|
||||||
";
|
";
|
||||||
if($image->video_codec!=null) {
|
if ($image->video_codec!=null) {
|
||||||
$html .= "<br/>Video Codec: $image->video_codec";
|
$html .= "<br/>Video Codec: $image->video_codec";
|
||||||
}
|
}
|
||||||
if ($image->length!=null) {
|
if ($image->length!=null) {
|
||||||
|
|
Reference in a new issue