aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/Youtube.cpp74
1 files changed, 61 insertions, 13 deletions
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index c7a9e5c..7a5f0d5 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -2167,9 +2167,46 @@ namespace QuickMedia {
return result_items;
}
+ static std::shared_ptr<BodyItem> video_details_to_body_item(const YoutubeVideoDetails &video_details) {
+ auto body_item = BodyItem::create(video_details.title);
+
+ std::string description;
+ if(!video_details.views.empty()) {
+ description = video_details.views + " view" + (video_details.views == "1" ? "" : "s");
+ }
+
+ if(!video_details.rating.empty()) {
+ if(!description.empty())
+ description += " • ";
+ description += "rated " + video_details.rating + "/5";
+ }
+
+ if(!video_details.author.empty()) {
+ if(!description.empty())
+ description += '\n';
+ description += video_details.author;
+ }
+
+ if(!video_details.description.empty()) {
+ if(!description.empty())
+ description += "\n\n";
+ description += video_details.description;
+ }
+
+ if(!description.empty())
+ body_item->set_description(std::move(description));
+
+ return body_item;
+ }
+
PluginResult YoutubeVideoPage::get_related_pages(const BodyItems &related_videos, const std::string &channel_url, std::vector<Tab> &result_tabs) {
+ auto description_page_body = create_body();
+ description_page_body->append_item(video_details_to_body_item(video_details));
+
auto related_page_body = create_body(false, true);
related_page_body->set_items(related_videos);
+
+ result_tabs.push_back(Tab{std::move(description_page_body), std::make_unique<YoutubeDescriptionPage>(program), nullptr});
result_tabs.push_back(Tab{create_body(), std::make_unique<YoutubeCommentsPage>(program, url, comments_continuation_token), nullptr});
result_tabs.push_back(Tab{std::move(related_page_body), std::make_unique<YoutubeRelatedVideosPage>(program), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
result_tabs.push_back(Tab{create_body(false, true), std::make_unique<YoutubeChannelPage>(program, channel_url, "", "Channel videos"), create_search_bar("Search...", 350)});
@@ -2342,6 +2379,14 @@ namespace QuickMedia {
}
}
+ static void video_details_clear(YoutubeVideoDetails &video_details) {
+ video_details.title.clear();
+ video_details.author.clear();
+ video_details.rating.clear();
+ video_details.views.clear();
+ video_details.description.clear();
+ }
+
PluginResult YoutubeVideoPage::parse_video_response(const Json::Value &json_root, std::string &title, std::string &channel_url, std::vector<MediaChapter> &chapters, std::string &err_str) {
livestream_url.clear();
video_formats.clear();
@@ -2350,6 +2395,7 @@ namespace QuickMedia {
title.clear();
channel_url.clear();
chapters.clear();
+ video_details_clear(video_details);
if(!json_root.isObject())
return PluginResult::ERR;
@@ -2392,19 +2438,25 @@ namespace QuickMedia {
const Json::Value &video_details_json = json_root["videoDetails"];
if(video_details_json.isObject()) {
- const Json::Value &title_json = video_details_json["title"];
- if(title_json.isString())
- title = title_json.asString();
-
const Json::Value &channel_id_json = video_details_json["channelId"];
if(channel_id_json.isString())
channel_url = "https://www.youtube.com/channel/" + channel_id_json.asString();
- const Json::Value &description_json = video_details_json["shortDescription"];
- if(description_json.isString()) {
- std::string description = description_json.asString();
- chapters = youtube_description_extract_chapters(description);
- }
+ const Json::Value &title_json = video_details_json["title"];
+ const Json::Value &author_json = video_details_json["author"];
+ const Json::Value &average_rating_json = video_details_json["averageRating"];
+ const Json::Value &view_count_json = video_details_json["viewCount"];
+ const Json::Value &short_description_json = video_details_json["shortDescription"];
+
+ if(title_json.isString()) video_details.title = title_json.asString();
+ if(author_json.isString()) video_details.author = author_json.asString();
+ if(average_rating_json.isDouble()) video_details.rating = std::to_string(average_rating_json.asDouble());
+ if(view_count_json.isString()) video_details.views = view_count_json.asString();
+ if(short_description_json.isString()) video_details.description = short_description_json.asString();
+
+ title = video_details.title;
+ if(!video_details.description.empty())
+ chapters = youtube_description_extract_chapters(video_details.description);
}
const Json::Value &captions_json = json_root["captions"];
@@ -2456,10 +2508,6 @@ namespace QuickMedia {
}
PluginResult YoutubeVideoPage::load(std::string &title, std::string &channel_url, std::vector<MediaChapter> &chapters, std::string &err_str) {
- livestream_url.clear();
- video_formats.clear();
- audio_formats.clear();
-
std::string video_id;
if(!youtube_url_extract_id(url, video_id)) {
fprintf(stderr, "Failed to extract youtube id from %s\n", url.c_str());