diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Page.cpp | 4 | ||||
-rw-r--r-- | src/plugins/Youtube.cpp | 54 |
2 files changed, 43 insertions, 15 deletions
diff --git a/src/plugins/Page.cpp b/src/plugins/Page.cpp index 48efeff..e444ecd 100644 --- a/src/plugins/Page.cpp +++ b/src/plugins/Page.cpp @@ -16,8 +16,10 @@ namespace QuickMedia { return DownloadResult::NET_ERR; } - if(server_response.empty()) + if(server_response.empty()) { + result = Json::Value::nullSingleton(); return DownloadResult::OK; + } Json::CharReaderBuilder json_builder; std::unique_ptr<Json::CharReader> json_reader(json_builder.newCharReader()); diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index a9a2811..bff0592 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -31,18 +31,35 @@ namespace QuickMedia { length = text_json.asCString(); } + const char *view_count_text = nullptr; + const Json::Value &view_count_text_json = video_item_json["viewCountText"]; + if(view_count_text_json.isObject()) { + const Json::Value &text_json = view_count_text_json["simpleText"]; + if(text_json.isString()) + view_count_text = text_json.asCString(); + } + + const char *owner_text = nullptr; + const Json::Value &owner_text_json = video_item_json["shortBylineText"]; + if(owner_text_json.isObject()) { + const Json::Value &runs_json = owner_text_json["runs"]; + if(runs_json.isArray() && !runs_json.empty()) { + const Json::Value &first_runs_json = runs_json[0]; + if(first_runs_json.isObject()) { + const Json::Value &text_json = first_runs_json["text"]; + if(text_json.isString()) + owner_text = text_json.asCString(); + } + } + } + const char *title = nullptr; const Json::Value &title_json = video_item_json["title"]; if(title_json.isObject()) { const Json::Value &simple_text_json = title_json["simpleText"]; if(simple_text_json.isString()) { title = simple_text_json.asCString(); - } - } - - if(!title) { - const Json::Value &title_json = video_item_json["title"]; - if(title_json.isObject()) { + } else { const Json::Value &runs_json = title_json["runs"]; if(runs_json.isArray() && !runs_json.empty()) { const Json::Value &first_runs_json = runs_json[0]; @@ -59,16 +76,25 @@ namespace QuickMedia { return nullptr; auto body_item = BodyItem::create(title); - /* TODO: Make date a different color */ - std::string date_str; - if(date) - date_str += date; + std::string desc; + if(view_count_text) + desc += view_count_text; + if(date) { + if(!desc.empty()) + desc += " • "; + desc += date; + } if(length) { - if(!date_str.empty()) - date_str += '\n'; - date_str += length; + if(!desc.empty()) + desc += '\n'; + desc += length; + } + if(owner_text) { + if(!desc.empty()) + desc += '\n'; + desc += owner_text; } - body_item->set_description(std::move(date_str)); + body_item->set_description(std::move(desc)); 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); |