From c90eab0046f95b5ff20e85be46fa4d70d451f3b6 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 9 May 2021 12:59:07 +0200 Subject: Handle youtube cookies initialization failure, reorder youtube tabs --- src/plugins/Youtube.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 0f5e807..0fcf61d 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -384,11 +384,9 @@ namespace QuickMedia { Path cookies_filepath_p; if(get_cookies_filepath(cookies_filepath_p, "youtube") != 0) { show_notification("QuickMedia", "Failed to create youtube cookies file", Urgency::CRITICAL); - abort(); + return {}; } - cookies_filepath = cookies_filepath_p.data; - // TODO: Re-enable this if the api key ever changes in the future #if 0 //api_key = youtube_page_find_api_key(); @@ -396,12 +394,20 @@ namespace QuickMedia { api_key = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8"; #endif - if(get_file_type(cookies_filepath_p) != FileType::REGULAR) { + if(get_file_type(cookies_filepath_p) == FileType::REGULAR) { + cookies_filepath = cookies_filepath_p.data; + } else { + Path cookies_filepath_tmp = cookies_filepath_p; + cookies_filepath_tmp.append(".tmp"); + // TODO: Is there any way to bypass this? this is needed to set VISITOR_INFO1_LIVE which is required to read comments - const char *args[] = { "curl", "-I", "-s", "-b", cookies_filepath.c_str(), "-c", cookies_filepath.c_str(), "https://www.youtube.com/subscription_manager?disable_polymer=1", nullptr }; - if(exec_program(args, nullptr, nullptr) != 0) { + const char *args[] = { "curl", "-I", "-s", "-f", "-L", "-b", cookies_filepath_tmp.data.c_str(), "-c", cookies_filepath_tmp.data.c_str(), "https://www.youtube.com/subscription_manager?disable_polymer=1", nullptr }; + if(exec_program(args, nullptr, nullptr) == 0) { + rename_atomic(cookies_filepath_tmp.data.c_str(), cookies_filepath_p.data.c_str()); + cookies_filepath = cookies_filepath_p.data; + } else { show_notification("QuickMedia", "Failed to fetch cookies to view youtube comments", Urgency::CRITICAL); - abort(); + return {}; } } } -- cgit v1.2.3