aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Matrix.cpp2
-rw-r--r--src/plugins/Youtube.cpp15
2 files changed, 15 insertions, 2 deletions
diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp
index 77d8f32..6f8b30b 100644
--- a/src/plugins/Matrix.cpp
+++ b/src/plugins/Matrix.cpp
@@ -3278,7 +3278,7 @@ namespace QuickMedia {
int tmp_file = mkstemp(tmp_filename);
if(tmp_file != -1) {
std::string thumbnail_path;
- if(create_thumbnail(filepath, tmp_filename, thumbnail_max_size))
+ if(create_thumbnail(filepath, tmp_filename, thumbnail_max_size, file_analyzer.get_content_type()))
thumbnail_path = tmp_filename;
else
thumbnail_path = filepath;
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index 993c861..cf3bbe4 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -53,10 +53,10 @@ namespace QuickMedia {
enum class ThumbnailSize {
SMALLEST,
+ MEDIUM,
LARGEST
};
- // TODO: Use this in |parse_common_video_item| when QuickMedia supports webp
static std::optional<Thumbnail> yt_json_get_thumbnail(const Json::Value &thumbnail_json, ThumbnailSize thumbnail_size) {
if(!thumbnail_json.isObject())
return std::nullopt;
@@ -85,6 +85,9 @@ namespace QuickMedia {
thumbnails.push_back({ url_json.asCString(), width_json.asInt(), height_json.asInt() });
}
+ if(thumbnails.empty())
+ return std::nullopt;
+
switch(thumbnail_size) {
case ThumbnailSize::SMALLEST:
return *std::min_element(thumbnails.begin(), thumbnails.end(), [](const Thumbnail &thumbnail1, const Thumbnail &thumbnail2) {
@@ -92,6 +95,14 @@ namespace QuickMedia {
int size2 = thumbnail2.width * thumbnail2.height;
return size1 < size2;
});
+ case ThumbnailSize::MEDIUM: {
+ std::sort(thumbnails.begin(), thumbnails.end(), [](const Thumbnail &thumbnail1, const Thumbnail &thumbnail2) {
+ int size1 = thumbnail1.width * thumbnail1.height;
+ int size2 = thumbnail2.width * thumbnail2.height;
+ return size1 < size2;
+ });
+ return thumbnails[thumbnails.size() / 2];
+ }
case ThumbnailSize::LARGEST:
return *std::max_element(thumbnails.begin(), thumbnails.end(), [](const Thumbnail &thumbnail1, const Thumbnail &thumbnail2) {
int size1 = thumbnail1.width * thumbnail1.height;
@@ -184,8 +195,10 @@ namespace QuickMedia {
body_item->set_description_color(sf::Color(179, 179, 179));
if(scheduled_text.empty())
body_item->url = "https://www.youtube.com/watch?v=" + video_id_str;
+
body_item->thumbnail_url = "https://img.youtube.com/vi/" + video_id_str + "/hqdefault.jpg";
body_item->thumbnail_size = sf::Vector2i(175, 131);
+
added_videos.insert(video_id_str);
return body_item;
}