From 2030684b16004a4f6c60f499584366ae5ad57bc9 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 15 Feb 2022 21:52:40 +0100 Subject: Finish video player --- src/plugins/LocalManga.cpp | 48 +++++++++++-------------------- src/plugins/Youtube.cpp | 2 +- src/plugins/youtube/YoutubeMediaProxy.cpp | 34 +--------------------- 3 files changed, 19 insertions(+), 65 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/LocalManga.cpp b/src/plugins/LocalManga.cpp index 83dd983..8ab8cd1 100644 --- a/src/plugins/LocalManga.cpp +++ b/src/plugins/LocalManga.cpp @@ -163,13 +163,7 @@ namespace QuickMedia { return manga_list; } - enum class ReadStatus { - READ, - UNREAD - }; - - // Returns the new read status - static bool toggle_read_save_to_file(Program *program, const std::string &manga_name, const std::string &thumbnail_url, ReadStatus &read_status) { + static bool validate_local_manga_dir_config_is_set() { if(get_config().local_manga_directory.empty()) { show_notification("QuickMedia", "local_manga_directory config is not set", Urgency::CRITICAL); return false; @@ -180,6 +174,19 @@ namespace QuickMedia { return false; } + return true; + } + + enum class ReadStatus { + READ, + UNREAD + }; + + // Returns the new read status + static bool toggle_read_save_to_file(Program *program, const std::string &manga_name, const std::string &thumbnail_url, ReadStatus &read_status) { + if(!validate_local_manga_dir_config_is_set()) + return false; + Path manga_url = Path(get_config().local_manga_directory).join(manga_name); std::vector chapters = get_chapters_in_manga(manga_name, manga_url, true, true); if(chapters.empty() || chapters.front().pages.empty()) @@ -327,15 +334,8 @@ namespace QuickMedia { } PluginResult LocalMangaSearchPage::submit(const SubmitArgs &args, std::vector &result_tabs) { - if(get_config().local_manga_directory.empty()) { - show_notification("QuickMedia", "local_manga_directory config is not set", Urgency::CRITICAL); + if(!validate_local_manga_dir_config_is_set()) return PluginResult::OK; - } - - if(get_file_type(get_config().local_manga_directory) != FileType::DIRECTORY) { - show_notification("QuickMedia", "local_manga_directory config is not set to a valid directory", Urgency::CRITICAL); - return PluginResult::OK; - } Path manga_url = Path(get_config().local_manga_directory).join(args.url); std::vector chapters = get_chapters_in_manga(args.url, manga_url, false, false); @@ -371,15 +371,8 @@ namespace QuickMedia { manga_list.clear(); finished_reading_manga.clear(); - if(get_config().local_manga_directory.empty()) { - show_notification("QuickMedia", "local_manga_directory config is not set", Urgency::CRITICAL); + if(!validate_local_manga_dir_config_is_set()) return PluginResult::OK; - } - - if(get_file_type(get_config().local_manga_directory) != FileType::DIRECTORY) { - show_notification("QuickMedia", "local_manga_directory config is not set to a valid directory", Urgency::CRITICAL); - return PluginResult::OK; - } manga_list = get_manga_in_directory(get_config().local_manga_directory, true); @@ -467,15 +460,8 @@ namespace QuickMedia { } PluginResult LocalMangaChaptersPage::submit(const SubmitArgs &args, std::vector &result_tabs) { - if(get_config().local_manga_directory.empty()) { - show_notification("QuickMedia", "local_manga_directory config is not set", Urgency::CRITICAL); - return PluginResult::OK; - } - - if(get_file_type(get_config().local_manga_directory) != FileType::DIRECTORY) { - show_notification("QuickMedia", "local_manga_directory config is not set to a valid directory", Urgency::CRITICAL); + if(!validate_local_manga_dir_config_is_set()) return PluginResult::OK; - } result_tabs.push_back(Tab{nullptr, std::make_unique(program, content_title, args.url, args.url, thumbnail_url), nullptr}); return PluginResult::OK; diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index d6035f2..a4212ae 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -2606,7 +2606,7 @@ R"END( std::string response; DownloadResult download_result = download_to_string(playback_url + "&ver=2&cpn=" + cpn + "&gl=US&hl=en", response, std::move(additional_args), true); if(download_result != DownloadResult::OK) { - fprintf(stderr, "Failed to mark video as watched because http request failed\n"); + fprintf(stderr, "Failed to mark video as watched because the http request failed\n"); return; } } diff --git a/src/plugins/youtube/YoutubeMediaProxy.cpp b/src/plugins/youtube/YoutubeMediaProxy.cpp index b33c122..9efd7ac 100644 --- a/src/plugins/youtube/YoutubeMediaProxy.cpp +++ b/src/plugins/youtube/YoutubeMediaProxy.cpp @@ -47,8 +47,6 @@ static ssize_t write_all(int fd, const void *buffer, size_t size) { namespace QuickMedia { static const int MAX_BUFFER_SIZE = 65536; static const int64_t RANGE = 5242870; - static const int64_t THROTTLED_DOWNLOAD_LIMIT_KB = 80; // TODO: What about people with really slow internet? What if the video player cache is not working and download is stuck, leading to false download speed calculation? - static const int64_t THROTTLED_DURATION_SECS = 3; static const char download_error_response_msg[] = "HTTP/1.1 500 Internal Server Error\r\n" "Content-Length: 0\r\n\r\n"; @@ -101,7 +99,7 @@ namespace QuickMedia { return true; } - YoutubeStaticMediaProxy::YoutubeStaticMediaProxy(ThrottleHandler throttle_handler) : throttle_handler(std::move(throttle_handler)) { + YoutubeStaticMediaProxy::YoutubeStaticMediaProxy() { } @@ -226,7 +224,6 @@ namespace QuickMedia { client_request_buffer.clear(); client_request_finished = false; download_started = false; - throttle_started = false; if(client_fd != -1) { close(client_fd); @@ -283,7 +280,6 @@ namespace QuickMedia { client_request_buffer.erase(header_end + 4); client_request_finished = true; download_started = false; - throttle_started = false; download_read_buffer_offset = 0; const int64_t new_start_range = header_extract_start_range(client_request_buffer); @@ -489,40 +485,12 @@ namespace QuickMedia { if(!download_started) { total_downloaded_bytes = 0; download_started = true; - throttle_started = false; download_start_time = get_boottime_milliseconds(); } total_downloaded_bytes += downloader_num_read_bytes; } } -#if 0 - if(download_started) { - const int64_t time_elapsed_sec = (get_boottime_milliseconds() - download_start_time) / 1000; - int64_t download_speed_kb_sec = 0; - if(time_elapsed > 0) - download_speed_kb_sec = (total_downloaded_bytes / time_elapsed) / 1024; - - if(download_speed_kb_sec < THROTTLED_DOWNLOAD_LIMIT_KB) { - if(throttle_started) { - if(tp.tv_sec - throttle_start_time >= THROTTLED_DURATION_SECS && !throttle_callback_called) { - total_downloaded_bytes = 0; - download_started = false; - throttle_started = false; - throttle_callback_called = true; - if(throttle_handler) - throttle_handler(); - } - } else { - throttle_started = true; - throttle_start_time = tp.tv_sec; - } - } else { - throttle_started = false; - } - } -#endif - // TODO: Remove this code and instead create the header ourselves and send it to the client. Then pipe the curl output directly to the client input. if(!download_header_finished) { download_header.append(download_read_buffer, downloader_num_read_bytes); -- cgit v1.2.3