From d037e38d8e65e8dc20e783e03fdb7474ed93cf4c Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 4 Mar 2022 01:43:44 +0100 Subject: Do not call ffprobe for thumbnails unless its guaranteed to be a local video file --- src/FileAnalyzer.cpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'src/FileAnalyzer.cpp') diff --git a/src/FileAnalyzer.cpp b/src/FileAnalyzer.cpp index 5b67b8d..976d2cf 100644 --- a/src/FileAnalyzer.cpp +++ b/src/FileAnalyzer.cpp @@ -207,7 +207,7 @@ namespace QuickMedia { return true; } - FileAnalyzer::FileAnalyzer() : content_type(ContentType::UNKNOWN), file_size(0), loaded(false) { + FileAnalyzer::FileAnalyzer() : content_type(ContentType::UNKNOWN), file_size(0), loaded(false), metadata_loaded(false) { } @@ -263,20 +263,37 @@ namespace QuickMedia { } } - if(load_file_metadata && content_type != ContentType::UNKNOWN) { - if(!ffprobe_extract_metadata(filepath, dimensions, duration_seconds)) { - // This is not an error, matrix allows files to be uploaded without metadata - fprintf(stderr, "Failed to extract metadata from file: %s, is ffprobe not installed?\n", filepath); - } - if(is_content_type_image(content_type)) - duration_seconds = std::nullopt; - } + if(load_file_metadata && content_type != ContentType::UNKNOWN) + load_metadata(); this->filepath = filepath; loaded = true; return true; } + bool FileAnalyzer::load_metadata() { + if(!loaded) { + fprintf(stderr, "File not loaded\n"); + return false; + } + + if(metadata_loaded) + return true; + + metadata_loaded = true; + + if(!ffprobe_extract_metadata(filepath.c_str(), dimensions, duration_seconds)) { + // This is not an error, matrix allows files to be uploaded without metadata + fprintf(stderr, "Failed to extract metadata from file: %s, is ffprobe not installed?\n", filepath.c_str()); + return false; + } + + if(is_content_type_image(content_type)) + duration_seconds = std::nullopt; + + return true; + } + const std::string& FileAnalyzer::get_filepath() const { return filepath; } -- cgit v1.2.3