diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index 256a8d812..6552f5eb0 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -3142,7 +3142,10 @@ class Daemon(metaclass=JSONRPCServerType): f"Use --allow-duplicate-name flag to override." ) - file_path = await self._video_file_analyzer.verify_or_repair(validate_file, optimize_file, file_path) + try: + file_path = await self._video_file_analyzer.verify_or_repair(validate_file, optimize_file, file_path) + except ValueError: + pass # it's not a video file claim = Claim() claim.stream.update(file_path=file_path, sd_hash='0' * 96, **kwargs) diff --git a/lbry/file_analysis.py b/lbry/file_analysis.py index 59abafa1c..c2106a896 100644 --- a/lbry/file_analysis.py +++ b/lbry/file_analysis.py @@ -257,12 +257,12 @@ class VideoFileAnalyzer: continue codec = stream["codec_name"].split(",") if "theora" in codec: - return "ogg" + return "ogv" if {"vp8", "vp9", "av1"}.intersection(codec): return "webm" if "theora" in video_encoder: - return "ogg" + return "ogv" elif re.search(r"vp[89x]|av1", video_encoder.split(" ", 1)[0]): return "webm" return "mp4" @@ -274,16 +274,15 @@ class VideoFileAnalyzer: scan_data = json.loads(result) except Exception as e: log.debug("Failure in JSON parsing ffprobe results. Message: %s", str(e)) - if validate: - raise Exception(f'Invalid video file: {file_path}') - log.info("Unable to optimize %s . FFmpeg output was unreadable.", file_path) - return + raise ValueError(f'Absent or unreadable video file: {file_path}') - if "format" not in scan_data: - if validate: - raise FileNotFoundError(f'Unexpected or absent video file contents at: {file_path}') - log.info("Unable to optimize %s . FFmpeg output is missing the format section.", file_path) - return + if "format" not in scan_data or "duration" not in scan_data["format"]: + log.debug("Format data is missing from ffprobe results for: %s", file_path) + raise ValueError(f'Media file does not appear to contain video content at: {file_path}') + + if float(scan_data["format"]["duration"]) < 0.1: + log.debug("Media file appears to be an image: %s", file_path) + raise ValueError(f'Assuming image file at: {file_path}') return scan_data diff --git a/lbry/schema/mime_types.py b/lbry/schema/mime_types.py index f873db897..00505e762 100644 --- a/lbry/schema/mime_types.py +++ b/lbry/schema/mime_types.py @@ -148,6 +148,7 @@ types_map = { '.mobi': ('application/x-mobipocket-ebook', 'document'), '.oga': ('audio/ogg', 'audio'), '.ogv': ('video/ogg', 'video'), + '.ogg': ('video/ogg', 'video'), '.pct': ('image/pict', 'image'), '.pic': ('image/pict', 'image'), '.pict': ('image/pict', 'image'), @@ -162,6 +163,7 @@ types_map = { def guess_media_type(path): + # should we be using "file --mime-type -b $filename" on linux? _, ext = os.path.splitext(path) extension = ext.strip().lower() if extension[1:]: diff --git a/scripts/check_video.py b/scripts/check_video.py index ee3a26899..61331142b 100755 --- a/scripts/check_video.py +++ b/scripts/check_video.py @@ -26,8 +26,8 @@ async def process_video(analyzer, video_file): try: await analyzer.verify_or_repair(True, False, video_file) print("No concerns. Ship it!") - except FileNotFoundError as e: - print(str(e)) + except (FileNotFoundError, ValueError) as e: + print("Analysis failed.", str(e)) except Exception as e: print(str(e)) transcode = input("Would you like to make a repaired clone now? [y/N] ") diff --git a/tests/integration/other/test_transcoding.py b/tests/integration/other/test_transcoding.py index c832ec4ec..60cad7992 100644 --- a/tests/integration/other/test_transcoding.py +++ b/tests/integration/other/test_transcoding.py @@ -130,7 +130,7 @@ class TranscodeValidation(ClaimTestCase): scan_data = await self.analyzer._get_scan_data(True, self.video_file_ogg) extension = self.analyzer._get_best_container_extension(scan_data, "") - self.assertEqual(extension, "ogg") + self.assertEqual(extension, "ogv") scan_data = await self.analyzer._get_scan_data(True, self.video_file_webm) extension = self.analyzer._get_best_container_extension(scan_data, "") @@ -143,7 +143,7 @@ class TranscodeValidation(ClaimTestCase): self.assertEqual("webm", extension) extension = self.analyzer._get_best_container_extension("", "libtheora") - self.assertEqual("ogg", extension) + self.assertEqual("ogv", extension) async def test_no_ffmpeg(self): self.conf.ffmpeg_folder = "I don't really exist/"