aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-09-17 02:02:58 +0200
committerdec05eba <dec05eba@protonmail.com>2020-09-17 02:02:58 +0200
commit95baa4316c127d65c46d2226dbeeae690340c4d6 (patch)
tree339ea7e172930ef5307820f63ac71c6294114c46
parentb95298d79eee764c48dfec9d329026548392484c (diff)
Show youtube videos length
-rw-r--r--src/plugins/Youtube.cpp34
1 files changed, 32 insertions, 2 deletions
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<BodyItem>(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<BodyItem>(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);