From a13c19e31cb033730fa179a90f0bc5bd961bd3dc Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 4 Mar 2022 00:06:11 +0100 Subject: Fix xv video and related page, fix possible crash when going back from related video --- src/plugins/MediaGeneric.cpp | 56 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/MediaGeneric.cpp b/src/plugins/MediaGeneric.cpp index adbac0d..5ee5fbc 100644 --- a/src/plugins/MediaGeneric.cpp +++ b/src/plugins/MediaGeneric.cpp @@ -37,7 +37,12 @@ namespace QuickMedia { } } - static PluginResult fetch_page_results(const std::string &url, const std::string &website_url, const std::vector &text_queries, const std::vector &thumbnail_queries, mgl::vec2i thumbnail_max_size, MediaRelatedCustomHandler *custom_handler, BodyItems &result_items, bool cloudflare_bypass, const std::vector &extra_commands) { + static PluginResult fetch_page_results( + const std::string &url, const std::string &website_url, const std::vector &text_queries, + const std::vector &thumbnail_queries, mgl::vec2i thumbnail_max_size, + MediaRelatedCustomHandler *related_custom_handler, + BodyItems &result_items, bool cloudflare_bypass, const std::vector &extra_commands) + { std::vector args = extra_commands; if(!website_url.empty()) args.push_back({ "--header", "referer: " + website_url }); @@ -49,8 +54,8 @@ namespace QuickMedia { if(website_data.empty()) return PluginResult::OK; - if(custom_handler && *custom_handler) { - std::vector media_related_items = (*custom_handler)(website_data); + if(related_custom_handler && *related_custom_handler) { + std::vector media_related_items = (*related_custom_handler)(website_data); for(MediaRelatedItem &media_related_item : media_related_items) { auto body_item = BodyItem::create(media_related_item.title); body_item->url = std::move(media_related_item.url); @@ -163,6 +168,11 @@ namespace QuickMedia { return *this; } + MediaGenericSearchPage& MediaGenericSearchPage::video_url_custom_handler(MediaVideoUrlCustomHandler handler) { + video_custom_handler = std::move(handler); + return *this; + } + MediaGenericSearchPage& MediaGenericSearchPage::related_media_text_handler(std::vector queries) { related_media_text_queries = std::move(queries); related_custom_handler = nullptr; @@ -176,7 +186,7 @@ namespace QuickMedia { } MediaGenericSearchPage& MediaGenericSearchPage::related_media_custom_handler(MediaRelatedCustomHandler handler) { - related_custom_handler = handler; + related_custom_handler = std::move(handler); related_media_text_queries.clear(); related_media_thumbnail_queries.clear(); return *this; @@ -199,4 +209,42 @@ namespace QuickMedia { result_tabs.push_back(Tab{std::move(related_page_body), std::make_unique(program, search_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); return PluginResult::OK; } + + std::string MediaGenericVideoPage::get_download_url(int max_height) { + // TODO: Use max_height, if possible + (void)max_height; + return video_url; + } + + std::string MediaGenericVideoPage::get_video_url(int max_height, bool &has_embedded_audio, std::string &ext) { + // TODO: Use max_height, if possible + (void)max_height; + has_embedded_audio = true; + ext = "m3u8"; + return video_url; + } + + PluginResult MediaGenericVideoPage::load(std::string&, std::string&, std::vector&, std::string &err_msg) { + video_url.clear(); + if(!search_page->video_custom_handler) { + video_url = url; + return PluginResult::OK; + } + + std::vector args = search_page->extra_commands; + if(!url.empty()) + args.push_back({ "--header", "referer: " + url }); + + std::string website_data; + if(download_to_string(url, website_data, args, true, true, search_page->cloudflare_bypass) != DownloadResult::OK) + return PluginResult::NET_ERR; + + video_url = search_page->video_custom_handler(website_data); + if(video_url.empty()) { + err_msg = "Failed to extract video url"; + return PluginResult::ERR; + } else { + return PluginResult::OK; + } + } } \ No newline at end of file -- cgit v1.2.3