aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-05-09 12:59:07 +0200
committerdec05eba <dec05eba@protonmail.com>2021-05-09 13:01:45 +0200
commitc90eab0046f95b5ff20e85be46fa4d70d451f3b6 (patch)
treec8f779edb66a2ff60c9be0b95f0940cee6a36180
parent7492c9aa0df61e7bd7e136679a0ef90414ed1283 (diff)
Handle youtube cookies initialization failure, reorder youtube tabs
-rw-r--r--TODO3
-rw-r--r--src/QuickMedia.cpp12
-rw-r--r--src/plugins/Youtube.cpp20
3 files changed, 22 insertions, 13 deletions
diff --git a/TODO b/TODO
index 289316d..9d40983 100644
--- a/TODO
+++ b/TODO
@@ -130,4 +130,5 @@ Support webp directly without using ffmpeg to convert it to a png.
Add client side 4chan file size limit (note, webm has different limit than images).
Add client side 4chan max comment chars limit.
Use a directory icon and a file icon for non-media files in the file manager.
-Dynamically fetch 4chan api key, if it ever changes in the future. Same for youtube. \ No newline at end of file
+Dynamically fetch 4chan api key, if it ever changes in the future. Same for youtube.
+Set curl download limits everywhere (when saving to file, downloading to json, etc...). \ No newline at end of file
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 0e4ba22..abfbc7c 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -1024,12 +1024,12 @@ namespace QuickMedia {
tabs.push_back(Tab{create_body(), std::make_unique<YoutubeSubscriptionsPage>(this), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
tabs.push_back(Tab{create_body(), std::make_unique<YoutubeSearchPage>(this), create_search_bar("Search...", 350)});
+ auto recommended_page = std::make_unique<YoutubeRecommendedPage>(this);
+ tabs.push_back(Tab{create_body(), std::move(recommended_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
+
auto history_body = create_body();
auto history_page = std::make_unique<HistoryPage>(this, tabs.front().page.get(), HistoryType::YOUTUBE);
tabs.push_back(Tab{std::move(history_body), std::move(history_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
-
- auto recommended_page = std::make_unique<YoutubeRecommendedPage>(this);
- tabs.push_back(Tab{create_body(), std::move(recommended_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
} else if(strcmp(plugin_name, "pornhub") == 0) {
auto search_page = std::make_unique<MediaGenericSearchPage>(this, "https://www.pornhub.com/", sf::Vector2i(320/1.5f, 180/1.5f));
add_pornhub_handlers(search_page.get());
@@ -1712,7 +1712,9 @@ namespace QuickMedia {
BodyItem *selected_item = tabs[selected_tab].body->get_selected();
if(selected_item && tabs[selected_tab].page && tabs[selected_tab].page->is_trackable()) {
TrackablePage *trackable_page = dynamic_cast<TrackablePage*>(tabs[selected_tab].page.get());
- trackable_page->track(selected_item->get_title());
+ run_task_with_loading_screen([trackable_page, selected_item](){
+ return trackable_page->track(selected_item->get_title()) == TrackResult::OK;
+ });
}
} else if(event.key.code == sf::Keyboard::C && event.key.control) {
BodyItem *selected_item = tabs[selected_tab].body->get_selected();
@@ -1773,7 +1775,7 @@ namespace QuickMedia {
if(tabs[selected_tab].page->is_lazy_fetch_page() && tab_associated_data[selected_tab].fetch_status == FetchStatus::NONE && !tab_associated_data[selected_tab].lazy_fetch_finished) {
tab_associated_data[selected_tab].fetch_status = FetchStatus::LOADING;
tab_associated_data[selected_tab].fetch_type = FetchType::LAZY;
- tab_associated_data[selected_tab].search_result_text.setString("Fetching page...");
+ tab_associated_data[selected_tab].search_result_text.setString("Loading...");
LazyFetchPage *lazy_fetch_page = static_cast<LazyFetchPage*>(tabs[selected_tab].page.get());
tab_associated_data[selected_tab].fetch_future = AsyncTask<FetchResult>([lazy_fetch_page]() {
FetchResult fetch_result;
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 {};
}
}
}