From 0603980988beda54847edf8924f91be820f0532f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 15 Oct 2020 01:56:41 +0200 Subject: Youtube: make video order match youtube more... --- src/plugins/Youtube.cpp | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'src/plugins/Youtube.cpp') diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index b34a873..9e84903 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -101,36 +101,39 @@ namespace QuickMedia { if(!item_contents_json.isArray()) return; - for(const Json::Value &content_item_json : item_contents_json) { - std::shared_ptr body_item = parse_content_video_renderer(content_item_json, added_videos); - if(body_item) - result_items.push_back(std::move(body_item)); - } - for(const Json::Value &content_item_json : item_contents_json) { if(!content_item_json.isObject()) continue; - const Json::Value &shelf_renderer_json = content_item_json["shelfRenderer"]; - if(!shelf_renderer_json.isObject()) - continue; + for(Json::Value::const_iterator it = content_item_json.begin(); it != content_item_json.end(); ++it) { + Json::Value key = it.key(); + if(key.isString() && strcmp(key.asCString(), "shelfRenderer") == 0) { + const Json::Value &shelf_renderer_json = *it; + if(!shelf_renderer_json.isObject()) + continue; - const Json::Value &item_content_json = shelf_renderer_json["content"]; - if(!item_content_json.isObject()) - continue; + const Json::Value &item_content_json = shelf_renderer_json["content"]; + if(!item_content_json.isObject()) + continue; - const Json::Value &vertical_list_renderer_json = item_content_json["verticalListRenderer"]; - if(!vertical_list_renderer_json.isObject()) - continue; + const Json::Value &vertical_list_renderer_json = item_content_json["verticalListRenderer"]; + if(!vertical_list_renderer_json.isObject()) + continue; - const Json::Value &items_json = vertical_list_renderer_json["items"]; - if(!items_json.isArray()) - continue; - - for(const Json::Value &item_json : items_json) { - std::shared_ptr body_item = parse_content_video_renderer(item_json, added_videos); - if(body_item) - result_items.push_back(std::move(body_item)); + const Json::Value &items_json = vertical_list_renderer_json["items"]; + if(!items_json.isArray()) + continue; + + for(const Json::Value &item_json : items_json) { + std::shared_ptr body_item = parse_content_video_renderer(item_json, added_videos); + if(body_item) + result_items.push_back(std::move(body_item)); + } + } else { + std::shared_ptr body_item = parse_content_video_renderer(content_item_json, added_videos); + if(body_item) + result_items.push_back(std::move(body_item)); + } } } } -- cgit v1.2.3