From 95baa4316c127d65c46d2226dbeeae690340c4d6 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 17 Sep 2020 02:02:58 +0200 Subject: Show youtube videos length --- src/plugins/Youtube.cpp | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 3b4a752..2827d83 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -43,6 +43,14 @@ namespace QuickMedia { date = text_json.asCString(); } + const char *length = nullptr; + const Json::Value &length_text_json = video_renderer_json["lengthText"]; + if(length_text_json.isObject()) { + const Json::Value &text_json = length_text_json["simpleText"]; + if(text_json.isString()) + length = text_json.asCString(); + } + const char *title = nullptr; const Json::Value &title_json = video_renderer_json["title"]; if(title_json.isObject()) { @@ -62,8 +70,15 @@ namespace QuickMedia { auto body_item = std::make_unique(title); /* TODO: Make date a different color */ + std::string date_str; if(date) - body_item->set_description(date); + date_str += date; + if(length) { + if(!date_str.empty()) + date_str += '\n'; + date_str += length; + } + body_item->set_description(std::move(date_str)); body_item->url = "https://www.youtube.com/watch?v=" + video_id_str; body_item->thumbnail_url = std::move(thumbnail_url); added_videos.insert(video_id_str); @@ -452,6 +467,14 @@ namespace QuickMedia { date = text_json.asCString(); } + const char *length = nullptr; + const Json::Value &length_text_json = compact_video_renderer_json["lengthText"]; + if(length_text_json.isObject()) { + const Json::Value &text_json = length_text_json["simpleText"]; + if(text_json.isString()) + length = text_json.asCString(); + } + const char *title = nullptr; const Json::Value &title_json = compact_video_renderer_json["title"]; if(title_json.isObject()) { @@ -466,8 +489,15 @@ namespace QuickMedia { auto body_item = std::make_unique(title); /* TODO: Make date a different color */ + std::string date_str; if(date) - body_item->set_description(date); + date_str += date; + if(length) { + if(!date_str.empty()) + date_str += '\n'; + date_str += length; + } + body_item->set_description(std::move(date_str)); body_item->url = "https://www.youtube.com/watch?v=" + video_id_str; body_item->thumbnail_url = std::move(thumbnail_url); added_videos.insert(video_id_str); -- cgit v1.2.3