From 87c8a2986d468a3fc897169c1b00fc4695e09d39 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 4 Sep 2022 05:01:36 +0200 Subject: Add dramacool --- src/QuickMedia.cpp | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 7a18f47..2ac6f90 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -8,6 +8,7 @@ #include "../plugins/MediaGeneric.hpp" #include "../plugins/Youtube.hpp" #include "../plugins/Peertube.hpp" +#include "../plugins/DramaCool.hpp" #include "../plugins/Fourchan.hpp" #include "../plugins/NyaaSi.hpp" #include "../plugins/Matrix.hpp" @@ -88,6 +89,7 @@ static const std::pair valid_plugins[] = { std::make_pair("manga", nullptr), std::make_pair("youtube", "yt_logo_rgb_dark_small.png"), std::make_pair("peertube", "peertube_logo.png"), + std::make_pair("dramacool", "dramacool_logo.png"), std::make_pair("soundcloud", "soundcloud_logo.png"), std::make_pair("lbry", "lbry_logo.png"), std::make_pair("pornhub", "pornhub_logo.png"), @@ -319,7 +321,7 @@ namespace QuickMedia { static void usage() { fprintf(stderr, "usage: quickmedia [plugin] [--no-video] [--dir ] [-e ] [youtube-url]\n"); fprintf(stderr, "OPTIONS:\n"); - fprintf(stderr, " plugin The plugin to use. Should be either launcher, 4chan, manga, manganelo, manganelos, mangatown, mangakatana, mangadex, readm, onimanga, local-manga, local-anime, youtube, peertube, lbry, soundcloud, nyaa.si, matrix, saucenao, hotexamples, anilist, file-manager, stdin, pornhub, spankbang, xvideos or xhamster\n"); + fprintf(stderr, " plugin The plugin to use. Should be either launcher, 4chan, manga, manganelo, manganelos, mangatown, mangakatana, mangadex, readm, onimanga, local-manga, local-anime, youtube, peertube, lbry, soundcloud, nyaa.si, matrix, saucenao, hotexamples, anilist, dramacool, file-manager, stdin, pornhub, spankbang, xvideos or xhamster\n"); fprintf(stderr, " --no-video Only play audio when playing a video. Disabled by default\n"); fprintf(stderr, " --upscale-images Upscale low-resolution manga pages using waifu2x-ncnn-vulkan. Disabled by default\n"); fprintf(stderr, " --upscale-images-always Upscale manga pages using waifu2x-ncnn-vulkan, no matter what the original image resolution is. Disabled by default\n"); @@ -1054,6 +1056,7 @@ namespace QuickMedia { pipe_body->set_items({ create_launcher_body_item("4chan", "4chan", resources_root + "icons/4chan_launcher.png"), create_launcher_body_item("AniList", "anilist", resources_root + "images/anilist_logo.png"), + create_launcher_body_item("DramaCool", "dramacool", resources_root + "images/dramacool_logo.png"), create_launcher_body_item("Hot Examples", "hotexamples", ""), create_launcher_body_item("Lbry", "lbry", resources_root + "icons/lbry_launcher.png"), create_launcher_body_item("Local anime", "local-anime", ""), @@ -1282,6 +1285,8 @@ namespace QuickMedia { } else { tabs.push_back(Tab{create_body(false, true), std::make_unique(this, instance), create_search_bar("Search...", 500)}); } + } else if(strcmp(plugin_name, "dramacool") == 0) { + tabs.push_back(Tab{create_body(false, true), std::make_unique(this), create_search_bar("Search...", 350)}); } 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), true); @@ -3105,7 +3110,7 @@ namespace QuickMedia { bool video_loaded = false; double video_time_pos = 0.0; // Time in media in seconds. Updates every 5 seconds and when starting to watch the video and when seeking. - double video_duration = 0.0; // Time in seconds. 0 if unknown + VideoInfo video_info; // Duration time in seconds. 0 if unknown bool successfully_fetched_video_duration = false; bool successfully_fetched_time_pos = false; bool update_time_pos = false; @@ -3153,7 +3158,6 @@ namespace QuickMedia { int64_t youtube_video_content_length = 0; int64_t youtube_audio_content_length = 0; - std::string channel_url; AsyncTask related_videos_task; EventCallbackFunc video_event_callback; bool go_to_previous_page = false; @@ -3162,16 +3166,14 @@ namespace QuickMedia { std::string audio_url; bool has_embedded_audio = true; - std::vector media_chapters; - auto load_video_error_check = [&](std::string start_time = "", bool reuse_media_source = false) mutable { video_player.reset(); - channel_url.clear(); + video_info.channel_url.clear(); video_loaded = false; successfully_fetched_video_duration = false; successfully_fetched_time_pos = false; video_player_window = None; - video_duration = 0.0; + video_info.duration = 0.0; bool is_audio_only = no_video; const int video_max_height = video_get_max_height(); @@ -3200,11 +3202,15 @@ namespace QuickMedia { for(int i = 0; i < num_retries; ++i) { bool cancelled = false; TaskResult load_result = run_task_with_loading_screen([&]() { - video_duration = 0.0; - if(video_page->load(submit_args, new_title, channel_url, video_duration, media_chapters, err_str) != PluginResult::OK) + video_info.duration = 0.0; + video_info.chapters.clear(); + + if(video_page->load(submit_args, video_info, err_str) != PluginResult::OK) return false; - if(video_duration > 0.001) + new_title = video_info.title; + + if(video_info.duration > 0.001) successfully_fetched_video_duration = true; std::string ext; @@ -3304,9 +3310,10 @@ namespace QuickMedia { startup_args.use_youtube_dl = use_youtube_dl && !video_page->is_local(); startup_args.title = video_title; startup_args.start_time = start_time; - startup_args.chapters = std::move(media_chapters); + startup_args.chapters = std::move(video_info.chapters); startup_args.plugin_name = plugin_name; startup_args.cache_on_disk = !video_page->is_local(); + startup_args.referer = video_info.referer; video_player = std::make_unique(std::move(startup_args), video_event_callback, on_window_create); VideoPlayer::Error err = video_player->load_video(); @@ -3519,8 +3526,8 @@ namespace QuickMedia { XFlush(disp); std::vector related_pages; - TaskResult related_pages_result = run_task_with_loading_screen([&video_page, &related_videos, &channel_url, &related_pages]{ - return video_page->get_related_pages(related_videos, channel_url, related_pages) == PluginResult::OK; + TaskResult related_pages_result = run_task_with_loading_screen([&video_page, &related_videos, &video_info, &related_pages]{ + return video_page->get_related_pages(related_videos, video_info.channel_url, related_pages) == PluginResult::OK; }); if(related_pages_result == TaskResult::FALSE) { @@ -3528,7 +3535,7 @@ namespace QuickMedia { show_notification("QuickMedia", "Failed to get related pages", Urgency::CRITICAL); } else if(related_pages_result == TaskResult::TRUE && !related_pages.empty()) { if(successfully_fetched_time_pos && successfully_fetched_video_duration) - video_page->set_watch_progress(video_time_pos, video_duration); + video_page->set_watch_progress(video_time_pos, video_info.duration); bool page_changed = false; double resume_start_time = 0.0; @@ -3720,8 +3727,8 @@ namespace QuickMedia { successfully_fetched_video_duration = true; double file_duration = 0.0; video_player->get_duration_in_file(&file_duration); - video_duration = std::max(video_duration, file_duration); - if(video_duration > 0.001) + video_info.duration = std::max(video_info.duration, file_duration); + if(video_info.duration > 0.001) successfully_fetched_video_duration = true; } } @@ -3750,7 +3757,7 @@ namespace QuickMedia { window_size.y = window_size_u.y; if(successfully_fetched_time_pos && successfully_fetched_video_duration) - video_page->set_watch_progress(video_time_pos, video_duration); + video_page->set_watch_progress(video_time_pos, video_info.duration); } void Program::select_episode(BodyItem *item, bool start_from_beginning) { @@ -7644,14 +7651,12 @@ namespace QuickMedia { std::string err_str; for(int i = 0; i < 3; ++i) { task_result = run_task_with_loading_screen([&]{ - std::string channel_url; - std::vector chapters; - filename.clear(); - double duration; + VideoInfo video_info; SubmitArgs submit_args; - if(youtube_video_page->load(submit_args, filename, channel_url, duration, chapters, err_str) != PluginResult::OK) + if(youtube_video_page->load(submit_args, video_info, err_str) != PluginResult::OK) return false; + filename = video_info.title; std::string ext; bool has_embedded_audio = true; video_url = no_video ? "" : youtube_video_page->get_video_url(video_max_height, has_embedded_audio, ext); -- cgit v1.2.3