aboutsummaryrefslogtreecommitdiff
path: root/src/FileAnalyzer.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-03-04 01:43:44 +0100
committerdec05eba <dec05eba@protonmail.com>2022-03-04 01:43:44 +0100
commitd037e38d8e65e8dc20e783e03fdb7474ed93cf4c (patch)
treebd3cccacd29c6a102ad99d9760720a0c2752673d /src/FileAnalyzer.cpp
parenta13c19e31cb033730fa179a90f0bc5bd961bd3dc (diff)
Do not call ffprobe for thumbnails unless its guaranteed to be a local video file
Diffstat (limited to 'src/FileAnalyzer.cpp')
-rw-r--r--src/FileAnalyzer.cpp35
1 files changed, 26 insertions, 9 deletions
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;
}