aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp78
1 files changed, 62 insertions, 16 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 99e8f1b..33bab93 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -2,6 +2,7 @@
#include "../plugins/Manganelo.hpp"
#include "../plugins/Mangadex.hpp"
#include "../plugins/LocalManga.hpp"
+#include "../plugins/LocalAnime.hpp"
#include "../plugins/MangaGeneric.hpp"
#include "../plugins/MangaCombined.hpp"
#include "../plugins/MediaGeneric.hpp"
@@ -44,7 +45,6 @@
#include "../external/hash-library/sha256.h"
#include <assert.h>
-#include <cmath>
#include <string.h>
#include <signal.h>
#include <malloc.h>
@@ -52,6 +52,7 @@
#include <libgen.h>
#include <limits.h>
#include <sys/stat.h>
+#include <cmath>
#include <mglpp/graphics/Rectangle.hpp>
#include <mglpp/graphics/Sprite.hpp>
@@ -82,6 +83,7 @@ static const std::pair<const char*, const char*> valid_plugins[] = {
std::make_pair("onimanga", nullptr),
std::make_pair("readm", "readm_logo.png"),
std::make_pair("local-manga", nullptr),
+ std::make_pair("local-anime", nullptr),
std::make_pair("manga", nullptr),
std::make_pair("youtube", "yt_logo_rgb_dark_small.png"),
std::make_pair("peertube", "peertube_logo.png"),
@@ -283,7 +285,7 @@ namespace QuickMedia {
static void usage() {
fprintf(stderr, "usage: quickmedia [plugin] [--no-video] [--dir <directory>] [-e <window>] [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, 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, 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");
@@ -983,6 +985,7 @@ namespace QuickMedia {
create_launcher_body_item("AniList", "anilist", resources_root + "images/anilist_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", ""),
create_launcher_body_item("Local manga", "local-manga", ""),
create_launcher_body_item("Manga (all)", "manga", ""),
create_launcher_body_item("Mangadex", "mangadex", resources_root + "icons/mangadex_launcher.png"),
@@ -1079,13 +1082,28 @@ namespace QuickMedia {
} else if(strcmp(plugin_name, "local-manga") == 0) {
auto search_page = std::make_unique<LocalMangaSearchPage>(this, true);
- tabs.push_back(Tab{create_body(), std::make_unique<BookmarksPage>(this, search_page.get(), true), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
- tabs.push_back(Tab{create_body(), std::move(search_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
+ tabs.push_back(Tab{create_body(false, true), std::make_unique<BookmarksPage>(this, search_page.get(), true), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
+ tabs.push_back(Tab{create_body(false, true), std::move(search_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
auto history_page = std::make_unique<HistoryPage>(this, tabs.back().page.get(), HistoryType::MANGA, true);
- tabs.push_back(Tab{create_body(), std::move(history_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
+ tabs.push_back(Tab{create_body(false, true), std::move(history_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
start_tab_index = 1;
+ } else if(strcmp(plugin_name, "local-anime") == 0) {
+ if(get_config().local_anime.directory.empty()) {
+ show_notification("QuickMedia", "local_anime.directory config is not set", Urgency::CRITICAL);
+ exit(1);
+ }
+
+ if(get_file_type(get_config().local_anime.directory) != FileType::DIRECTORY) {
+ show_notification("QuickMedia", "local_anime.directory config is not set to a valid directory", Urgency::CRITICAL);
+ exit(1);
+ }
+
+ auto search_page = std::make_unique<LocalAnimeSearchPage>(this, get_config().local_anime.directory, LocalAnimeSearchPageType::DIRECTORY);
+ tabs.push_back(Tab{create_body(false, true), std::move(search_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
+
+ start_tab_index = 0;
} else if(strcmp(plugin_name, "manga") == 0) {
auto mangadex = std::make_unique<MangadexSearchPage>(this);
@@ -2684,6 +2702,9 @@ namespace QuickMedia {
PageType previous_page = pop_page_stack();
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.
+ bool update_time_pos = false;
+ mgl::Clock video_time_pos_clock;
std::string youtube_video_id_dummy;
const bool is_youtube = youtube_url_extract_id(video_page->get_url(), youtube_video_id_dummy);
@@ -2700,7 +2721,7 @@ namespace QuickMedia {
}
mgl::WindowHandle video_player_window = None;
- auto on_window_create = [this, &video_player_window, &video_page](mgl::WindowHandle _video_player_window) mutable {
+ auto on_window_create = [&](mgl::WindowHandle _video_player_window) mutable {
video_player_window = _video_player_window;
XSelectInput(disp, video_player_window, KeyPressMask | PointerMotionMask);
XSync(disp, False);
@@ -2709,6 +2730,9 @@ namespace QuickMedia {
video_page->get_subtitles(subtitle_data);
if(!subtitle_data.url.empty())
video_player->add_subtitle(subtitle_data.url, subtitle_data.title, "eng");
+
+ if(video_page->is_local())
+ update_time_pos = true;
};
std::unique_ptr<YoutubeMediaProxy> youtube_video_media_proxy;
@@ -2897,12 +2921,13 @@ namespace QuickMedia {
startup_args.audio_path = a;
startup_args.parent_window = window.get_system_handle();
startup_args.no_video = is_audio_only;
- startup_args.use_system_mpv_config = get_config().use_system_mpv_config;
- startup_args.use_system_input_config = false;
+ startup_args.use_system_mpv_config = get_config().use_system_mpv_config || video_page->is_local();
+ startup_args.use_system_input_config = video_page->is_local();
startup_args.keep_open = is_matrix && !is_youtube;
+ startup_args.resume = false;
startup_args.resource_root = resources_root;
startup_args.monitor_height = video_max_height;
- startup_args.use_youtube_dl = use_youtube_dl;
+ 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);
@@ -2959,7 +2984,7 @@ namespace QuickMedia {
}
};
- video_event_callback = [&video_loaded](const char *event_name) mutable {
+ video_event_callback = [&](const char *event_name) mutable {
if(strcmp(event_name, "pause") == 0) {
//double time_remaining = 9999.0;
//if(video_player->get_time_remaining(&time_remaining) == VideoPlayer::Error::OK && time_remaining <= 1.0)
@@ -2968,10 +2993,15 @@ namespace QuickMedia {
//video_player->set_paused(false);
} else if(strcmp(event_name, "start-file") == 0) {
video_loaded = true;
+ if(video_page->is_local())
+ update_time_pos = true;
} else if(strcmp(event_name, "file-loaded") == 0) {
video_loaded = true;
} else if(strcmp(event_name, "video-reconfig") == 0 || strcmp(event_name, "audio-reconfig") == 0) {
video_loaded = true;
+ } else if(strcmp(event_name, "seek") == 0) {
+ if(video_page->is_local())
+ update_time_pos = true;
}
//fprintf(stderr, "event name: %s\n", event_name);
@@ -3018,9 +3048,9 @@ namespace QuickMedia {
}
} else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::F && event.key.control) {
window_set_fullscreen(disp, window.get_system_handle(), WindowFullscreenState::TOGGLE);
- } else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::C && event.key.control) {
+ } else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::C && event.key.control && !video_page->is_local()) {
save_video_url_to_clipboard();
- } else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::F5) {
+ } else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::F5 && !video_page->is_local()) {
load_video_error_check();
}
}
@@ -3044,13 +3074,13 @@ namespace QuickMedia {
}
} else if(pressed_keysym == XK_f && pressing_ctrl) {
window_set_fullscreen(disp, window.get_system_handle(), WindowFullscreenState::TOGGLE);
- } else if(pressed_keysym == XK_s && pressing_ctrl) {
+ } else if(pressed_keysym == XK_s && pressing_ctrl && !video_page->is_local()) {
video_page_download_video(video_page->get_download_url(video_get_max_height()), video_player_window);
- } else if(pressed_keysym == XK_F5) {
+ } else if(pressed_keysym == XK_F5 && !video_page->is_local()) {
double resume_start_time = 0.0;
video_player->get_time_in_file(&resume_start_time);
load_video_error_check(std::to_string((int)resume_start_time));
- } else if(pressed_keysym == XK_r && pressing_ctrl) {
+ } else if(pressed_keysym == XK_r && pressing_ctrl && !video_page->is_local()) {
bool cancelled = false;
if(video_tasks.valid()) {
XUnmapWindow(disp, video_player_window);
@@ -3201,7 +3231,8 @@ namespace QuickMedia {
// If there are no videos to play, then dont play any...
if(new_video_url.empty()) {
- show_notification("QuickMedia", "No more related videos to play");
+ if(!video_page->is_local())
+ show_notification("QuickMedia", "No more related videos to play");
current_page = previous_page;
go_to_previous_page = true;
break;
@@ -3250,6 +3281,18 @@ namespace QuickMedia {
continue;
}
+ if(video_player) {
+ if(video_time_pos_clock.get_elapsed_time_seconds() >= 5.0) {
+ video_time_pos_clock.restart();
+ update_time_pos = true;
+ }
+
+ if(update_time_pos) {
+ update_time_pos = false;
+ video_player->get_time_in_file(&video_time_pos);
+ }
+ }
+
if(video_player_window) {
if(!cursor_visible) {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
@@ -3272,6 +3315,9 @@ namespace QuickMedia {
auto window_size_u = window.get_size();
window_size.x = window_size_u.x;
window_size.y = window_size_u.y;
+
+ if(video_page->is_local())
+ video_page->set_watch_progress(video_time_pos);
}
void Program::select_episode(BodyItem *item, bool start_from_beginning) {