From d29706538e1d910419bbc3527a48b7a642c4f473 Mon Sep 17 00:00:00 2001 From: Artom Lifshitz Date: Fri, 16 Apr 2021 16:09:04 -0400 Subject: [PATCH] WIP: Ignore mp3 files that mp3gain cannot process In the validator, sometimes audio files either have a typo in their path, or aren't actually audio files (when this patch was being tested, the offending files were HTML files from a 301 redirect response). In those cases, mp3gain does not return any useful output. Specifically, instead of printing the header line plus the actually useful line, it just prints the header line, with an error message going to stderr (which we ignore because we only look at stdout). This patch just makes the validator skip any such files. Resolves #119 Change-Id: Id08899ef6f415aeece6912e9676a7bcab05caf81 --- application/libraries/Librivox_id3tag.php | 1 + application/libraries/Librivox_mp3gain.php | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/application/libraries/Librivox_id3tag.php b/application/libraries/Librivox_id3tag.php index 82b0aef3..46cde18b 100644 --- a/application/libraries/Librivox_id3tag.php +++ b/application/libraries/Librivox_id3tag.php @@ -161,6 +161,7 @@ function _create_files_table($dir, $map = array(), $freeze = false) //analyze volume $mp3gain_result = $this->librivox_mp3gain->analyze_file($dir, $file); + if (! $mp3gain_result) continue; $file_array = $this-> _create_file_array($freeze); //prototype diff --git a/application/libraries/Librivox_mp3gain.php b/application/libraries/Librivox_mp3gain.php index 7e89db33..51f6ea2f 100644 --- a/application/libraries/Librivox_mp3gain.php +++ b/application/libraries/Librivox_mp3gain.php @@ -68,9 +68,13 @@ public function analyze_file($dir, $file_name) $command = $this->mp3gain . ' ' . $this->flag . $dir. $file_name; exec($command, $output); - $parts = explode("\t", $output[1]); + if (count($output) > 1) { + $parts = explode("\t", $output[1]); + return $parts; + } else { + return false; + } - return $parts; } @@ -89,4 +93,4 @@ public function adjust($dir, $map) unset($output); } } -} \ No newline at end of file +}