diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-07-29 05:16:57 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-07-29 05:16:57 +0200 |
commit | 43e7de19358f730ee18d690a993e97a5195b80c9 (patch) | |
tree | a132a8cf5784d7a62a58dc08acf9a0e062bc5539 | |
parent | da9836a92ef69bb93e521985976db0322e2d5316 (diff) |
Faster video loading/error when not using xxx plugin (disable ytdl)
-rw-r--r-- | include/QuickMedia.hpp | 1 | ||||
-rw-r--r-- | include/VideoPlayer.hpp | 5 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 6 | ||||
-rw-r--r-- | src/StringUtils.cpp | 2 | ||||
-rw-r--r-- | src/VideoPlayer.cpp | 10 | ||||
-rw-r--r-- | src/plugins/Matrix.cpp | 2 |
6 files changed, 17 insertions, 9 deletions
diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index 765a346..0cd65b4 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -210,5 +210,6 @@ namespace QuickMedia { std::filesystem::path file_manager_start_dir; std::string youtube_url; std::unique_ptr<VideoPlayer> video_player; + bool use_youtube_dl = false; }; }
\ No newline at end of file diff --git a/include/VideoPlayer.hpp b/include/VideoPlayer.hpp index bdf3344..cd1e979 100644 --- a/include/VideoPlayer.hpp +++ b/include/VideoPlayer.hpp @@ -41,7 +41,7 @@ namespace QuickMedia { VideoPlayer& operator=(const VideoPlayer&) = delete; // |audio_path| is only set when video and audio are separate files/urls. - Error load_video(const char *path, const char *audio_path, sf::WindowHandle parent_window, bool is_youtube, const std::string &title, const std::string &start_time = "", const std::vector<MediaChapter> &chapters = {}); + Error load_video(const char *path, const char *audio_path, sf::WindowHandle parent_window, bool use_youtube_dl, const std::string &title, const std::string &start_time = "", const std::vector<MediaChapter> &chapters = {}); // Should be called every update frame Error update(); @@ -54,13 +54,14 @@ namespace QuickMedia { int exit_status; private: Error send_command(const char *cmd, size_t size); - Error launch_video_process(const char *path, const char *audio_path, sf::WindowHandle parent_window, bool is_youtube, const std::string &title, const std::string &start_time); + Error launch_video_process(const char *path, const char *audio_path, sf::WindowHandle parent_window, const std::string &title, const std::string &start_time); VideoPlayer::Error read_ipc_func(); private: std::string plugin_name; bool no_video; bool use_system_mpv_config; bool keep_open; + bool use_youtube_dl; pid_t video_process_id; bool connected_to_ipc; sf::Clock retry_timer; diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 6069cf9..a48234e 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1225,21 +1225,25 @@ namespace QuickMedia { auto search_page = std::make_unique<MediaGenericSearchPage>(this, "https://www.pornhub.com/", sf::Vector2i(320/1.5f, 180/1.5f), false); 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; } else if(strcmp(plugin_name, "spankbang") == 0) { check_youtube_dl_installed(plugin_name); auto search_page = std::make_unique<MediaGenericSearchPage>(this, "https://spankbang.com/", sf::Vector2i(500/2.5f, 281/2.5f), true); add_spankbang_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, "xvideos") == 0) { check_youtube_dl_installed(plugin_name); auto search_page = std::make_unique<MediaGenericSearchPage>(this, "https://www.xvideos.com/", sf::Vector2i(352/1.5f, 198/1.5f), false); 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<MediaGenericSearchPage>(this, "https://xhamster.com/", sf::Vector2i(240, 135), false); 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; } else if(strcmp(plugin_name, "soundcloud") == 0) { tabs.push_back(Tab{create_body(false, true), std::make_unique<SoundcloudSearchPage>(this), create_search_bar("Search...", 500)}); no_video = true; @@ -2753,7 +2757,7 @@ namespace QuickMedia { } video_player = std::make_unique<VideoPlayer>(is_audio_only, use_system_mpv_config, is_matrix && !is_youtube, video_event_callback, on_window_create, resources_root, largest_monitor_height, plugin_name); - VideoPlayer::Error err = video_player->load_video(v.c_str(), a.c_str(), window.getSystemHandle(), is_youtube, video_title, start_time, media_chapters); + VideoPlayer::Error err = video_player->load_video(v.c_str(), a.c_str(), window.getSystemHandle(), use_youtube_dl, video_title, start_time, media_chapters); if(err != VideoPlayer::Error::OK) { std::string err_msg = "Failed to play url: "; err_msg += video_page->get_url(); diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 96fdaeb..9820d29 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -103,7 +103,7 @@ namespace QuickMedia { size_t str_find_case_insensitive(const std::string &str, size_t start_index, const char *substr, size_t substr_len) { auto it = std::search(str.begin() + start_index, str.end(), substr, substr + substr_len, [](char c1, char c2) { - return std::toupper(c1) == std::toupper(c2); + return to_upper(c1) == to_upper(c2); }); if(it == str.end()) return std::string::npos; diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index 98d215d..7f01912 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -70,6 +70,7 @@ namespace QuickMedia { no_video(no_video), use_system_mpv_config(use_system_mpv_config), keep_open(keep_open), + use_youtube_dl(true), video_process_id(-1), connected_to_ipc(false), connect_tries(0), @@ -115,7 +116,7 @@ namespace QuickMedia { remove(tmp_chapters_filepath); } - VideoPlayer::Error VideoPlayer::launch_video_process(const char *path, const char *audio_path, sf::WindowHandle _parent_window, bool is_youtube, const std::string &title, const std::string &start_time) { + VideoPlayer::Error VideoPlayer::launch_video_process(const char *path, const char *audio_path, sf::WindowHandle _parent_window, const std::string &title, const std::string &start_time) { parent_window = _parent_window; if(!tmpnam(ipc_server_path)) { @@ -166,7 +167,7 @@ namespace QuickMedia { else ytdl_format = "--ytdl-format=bestvideo[height<=?" + std::to_string(monitor_height) + "]+bestaudio/best"; - if(is_youtube) + if(!use_youtube_dl) args.push_back("--no-ytdl"); else args.push_back(ytdl_format.c_str()); @@ -232,17 +233,18 @@ namespace QuickMedia { return Error::OK; } - VideoPlayer::Error VideoPlayer::load_video(const char *path, const char *audio_path, sf::WindowHandle _parent_window, bool is_youtube, const std::string &title, const std::string &start_time, const std::vector<MediaChapter> &chapters) { + VideoPlayer::Error VideoPlayer::load_video(const char *path, const char *audio_path, sf::WindowHandle _parent_window, bool use_youtube_dl, const std::string &title, const std::string &start_time, const std::vector<MediaChapter> &chapters) { // This check is to make sure we dont change window that the video belongs to. This is not a usecase we will have so // no need to support it for now at least. assert(parent_window == 0 || parent_window == _parent_window); assert(path); + this->use_youtube_dl = use_youtube_dl; if(!create_tmp_file_with_chapters_data(tmp_chapters_filepath, chapters)) fprintf(stderr, "Warning: failed to create chapters file. Chapters will not be displayed\n"); fprintf(stderr, "Playing video: %s, audio: %s\n", path ? path : "", audio_path ? audio_path : ""); if(video_process_id == -1) - return launch_video_process(path, audio_path, _parent_window, is_youtube, title, start_time); + return launch_video_process(path, audio_path, _parent_window, title, start_time); // TODO: When these are used, add audio_path, title and start_time. Also handle is_youtube Json::Value command_data(Json::arrayValue); diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 68b9524..ca211e1 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -34,7 +34,7 @@ static const char* CONTINUE_FILTER = "{\"presence\":{\"limit\":0,\"types\":[\"\" static std::string capitalize(const std::string &str) { if(str.size() >= 1) - return (char)std::toupper(str[0]) + str.substr(1); + return QuickMedia::to_upper(str[0]) + str.substr(1); else return ""; } |