From 8497b3daea44fe26fbc2d089a55e75a219e8d603 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 3 Mar 2022 22:48:54 +0100 Subject: Fix related videos window not showing for generic media, fix ph related videos always same (anti-curl website) --- src/DownloadUtils.cpp | 49 ++++++++++++++++++++++++++++++-------------- src/QuickMedia.cpp | 29 +++++++++++++++----------- src/plugins/MediaGeneric.cpp | 2 +- 3 files changed, 52 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/DownloadUtils.cpp b/src/DownloadUtils.cpp index 584d4a3..a4557d2 100644 --- a/src/DownloadUtils.cpp +++ b/src/DownloadUtils.cpp @@ -197,22 +197,41 @@ namespace QuickMedia { result.clear(); mgl::Clock timer; std::vector args; - args.insert(args.end(), { "curl", "-H", "Accept-Language: en-US,en;q=0.5", "-H", "Connection: keep-alive", "--compressed", "-g", "-s", "-L" }); - if(fail_on_error) - args.push_back("-f"); - for(const CommandArg &arg : additional_args) { - args.push_back(arg.option.c_str()); - if(!arg.value.empty()) - args.push_back(arg.value.c_str()); - } - if(!cloudflare_bypass && use_browser_useragent) { - args.push_back("-H"); - args.push_back(useragent_str); + + if(cloudflare_bypass) { + args.insert(args.end(), { "wget", "--header", "Accept-Language: en-US,en;q=0.5", "-q", "-O", "-" }); + // TODO: + //if(fail_on_error) + // args.push_back("-f"); + // TODO: May not be compatible + for(const CommandArg &arg : additional_args) { + args.push_back(arg.option.c_str()); + if(!arg.value.empty()) + args.push_back(arg.value.c_str()); + } + if(use_browser_useragent) { + args.push_back("--header"); + args.push_back(useragent_str); + } + // TODO: + //if(headers) + // args.push_back("-i"); + } else { + args.insert(args.end(), { "curl", "-H", "Accept-Language: en-US,en;q=0.5", "-H", "Connection: keep-alive", "--compressed", "-g", "-s", "-L" }); + if(fail_on_error) + args.push_back("-f"); + for(const CommandArg &arg : additional_args) { + args.push_back(arg.option.c_str()); + if(!arg.value.empty()) + args.push_back(arg.value.c_str()); + } + if(use_browser_useragent) { + args.push_back("-H"); + args.push_back(useragent_str); + } + if(headers) + args.push_back("-i"); } - if(cloudflare_bypass) - args.insert(args.end(), { "--tls-max", "1.1", "-A", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; FSL 7.0.6" }); - if(headers) - args.push_back("-i"); args.push_back("--"); args.push_back(url.c_str()); args.push_back(nullptr); diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index d49aa32..1ee0816 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1239,7 +1239,7 @@ namespace QuickMedia { } } else if(strcmp(plugin_name, "pornhub") == 0) { check_youtube_dl_installed(plugin_name); - auto search_page = std::make_unique(this, "https://www.pornhub.com/", mgl::vec2i(320/1.5f, 180/1.5f), false); + auto search_page = std::make_unique(this, "https://www.pornhub.com/", mgl::vec2i(320/1.5f, 180/1.5f), true); add_pornhub_handlers(search_page.get()); tabs.push_back(Tab{create_body(false, true), std::move(search_page), create_search_bar("Search...", 500)}); use_youtube_dl = true; @@ -1253,15 +1253,15 @@ namespace QuickMedia { check_youtube_dl_installed(plugin_name); std::vector extra_commands = { - { "-H", "Cookie: last_views=%5B%2236247565-" + std::to_string(time(nullptr)) + "%22%5D" } + { "--header", "Cookie: last_views=%5B%2236247565-" + std::to_string(time(nullptr)) + "%22%5D" } }; - auto search_page = std::make_unique(this, "https://www.xvideos.com/", mgl::vec2i(352/1.5f, 198/1.5f), false, std::move(extra_commands)); + auto search_page = std::make_unique(this, "https://www.xvideos.com/", mgl::vec2i(352/1.5f, 198/1.5f), true, std::move(extra_commands)); add_xvideos_handlers(search_page.get()); tabs.push_back(Tab{create_body(false, true), std::move(search_page), create_search_bar("Search...", 500)}); use_youtube_dl = true; } else if(strcmp(plugin_name, "xhamster") == 0) { check_youtube_dl_installed(plugin_name); - auto search_page = std::make_unique(this, "https://xhamster.com/", mgl::vec2i(240, 135), false); + auto search_page = std::make_unique(this, "https://xhamster.com/", mgl::vec2i(240, 135), true); add_xhamster_handlers(search_page.get()); tabs.push_back(Tab{create_body(false, true), std::move(search_page), create_search_bar("Search...", 500)}); use_youtube_dl = true; @@ -3234,16 +3234,16 @@ namespace QuickMedia { if(video_page->autoplay_next_item()) return; - // TODO: Make this also work for other video plugins - if(strcmp(plugin_name, "youtube") != 0 || is_resume_go_back) - return; - std::string url = video_page->get_url(); related_videos_task = AsyncTask([&related_videos, url, video_page]() { video_page->mark_watched(); related_videos = video_page->get_related_media(url); }); + // TODO: Make this also work for other video plugins + if(strcmp(plugin_name, "youtube") != 0 || is_resume_go_back) + return; + std::string video_id; if(!youtube_url_extract_id(video_page->get_url(), video_id)) { std::string err_msg = "Failed to extract id of youtube url "; @@ -3371,6 +3371,11 @@ namespace QuickMedia { video_player->get_time_in_file(&resume_start_time); load_video_error_check(std::to_string((int)resume_start_time)); } else if(pressed_keysym == XK_r && pressing_ctrl && !video_page->is_local()) { + cursor_hide_timer.restart(); + if(!cursor_visible) + window.set_cursor_visible(true); + cursor_visible = true; + bool cancelled = false; if(related_videos_task.valid()) { XUnmapWindow(disp, video_player_window); @@ -3396,9 +3401,9 @@ namespace QuickMedia { } if(!cancelled) { - if(!cursor_visible) - window.set_cursor_visible(true); - cursor_visible = true; + XUnmapWindow(disp, video_player_window); + XSync(disp, False); + XFlush(disp); std::vector related_pages; TaskResult related_pages_result = run_task_with_loading_screen([&video_page, &related_videos, &channel_url, &related_pages]{ @@ -3409,7 +3414,7 @@ namespace QuickMedia { XMapWindow(disp, video_player_window); XSync(disp, False); show_notification("QuickMedia", "Failed to get related pages", Urgency::CRITICAL); - } else if(related_pages_result == TaskResult::TRUE) { + } else if(related_pages_result == TaskResult::TRUE && !related_pages.empty()) { bool page_changed = false; double resume_start_time = 0.0; page_loop(related_pages, video_page->get_related_pages_first_tab(), [&](const std::vector &new_tabs) { diff --git a/src/plugins/MediaGeneric.cpp b/src/plugins/MediaGeneric.cpp index 0b69556..adbac0d 100644 --- a/src/plugins/MediaGeneric.cpp +++ b/src/plugins/MediaGeneric.cpp @@ -40,7 +40,7 @@ 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) { std::vector args = extra_commands; if(!website_url.empty()) - args.push_back({ "-H", "referer: " + website_url }); + args.push_back({ "--header", "referer: " + website_url }); std::string website_data; if(download_to_string(url, website_data, args, true, true, cloudflare_bypass) != DownloadResult::OK) -- cgit v1.2.3