aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp63
1 files changed, 59 insertions, 4 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 64f326b..aebe86e 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -61,6 +61,7 @@ static const std::pair<const char*, const char*> valid_plugins[] = {
std::make_pair("mangatown", "mangatown_logo.png"),
std::make_pair("mangakatana", "mangakatana_logo.png"),
std::make_pair("mangadex", "mangadex_logo.png"),
+ std::make_pair("readm", "readm_logo.png"),
std::make_pair("manga", nullptr),
std::make_pair("youtube", "yt_logo_rgb_dark_small.png"),
std::make_pair("spotify", "spotify_logo.png"),
@@ -446,7 +447,7 @@ namespace QuickMedia {
static void usage() {
fprintf(stderr, "usage: quickmedia <plugin> [--no-video] [--use-system-mpv-config] [--dir <directory>] [-e <window>]\n");
fprintf(stderr, "OPTIONS:\n");
- fprintf(stderr, " plugin The plugin to use. Should be either launcher, 4chan, manga, manganelo, manganelos, mangatown, mangakatana, mangadex, pornhub, spankbang, xvideos, xhamster, youtube, spotify, soundcloud, nyaa.si, matrix, file-manager or stdin\n");
+ fprintf(stderr, " plugin The plugin to use. Should be either launcher, 4chan, manga, manganelo, manganelos, mangatown, mangakatana, mangadex, readm, youtube, spotify, soundcloud, nyaa.si, matrix, 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, " --use-system-mpv-config Use system mpv config instead of no config. Disabled by default\n");
fprintf(stderr, " --upscale-images Upscale low-resolution manga pages using waifu2x-ncnn-vulkan. Disabled by default\n");
@@ -461,7 +462,7 @@ namespace QuickMedia {
}
static bool is_manga_plugin(const char *plugin_name) {
- return strcmp(plugin_name, "manga") == 0 || strcmp(plugin_name, "manganelo") == 0 || strcmp(plugin_name, "manganelos") == 0 || strcmp(plugin_name, "mangatown") == 0 || strcmp(plugin_name, "mangakatana") == 0 || strcmp(plugin_name, "mangadex") == 0;
+ return strcmp(plugin_name, "manga") == 0 || strcmp(plugin_name, "manganelo") == 0 || strcmp(plugin_name, "manganelos") == 0 || strcmp(plugin_name, "mangatown") == 0 || strcmp(plugin_name, "mangakatana") == 0 || strcmp(plugin_name, "mangadex") == 0 || strcmp(plugin_name, "readm") == 0;
}
static std::shared_ptr<BodyItem> create_launcher_body_item(const char *title, const char *plugin_name, const std::string &thumbnail_url) {
@@ -823,6 +824,42 @@ namespace QuickMedia {
.manga_id_handler("/manga/", nullptr);
}
+ static void add_readm_handlers(MangaGenericSearchPage *manga_generic_search_page) {
+ manga_generic_search_page->search_post_handler("https://readm.org/service/search", {{"dataType", "json"}, {"phrase", "%s"}},
+ [](Json::Value &json_root) {
+ BodyItems result_items;
+ if(!json_root.isObject())
+ return result_items;
+
+ const Json::Value &manga_json = json_root["manga"];
+ if(!manga_json.isArray())
+ return result_items;
+
+ for(const Json::Value &item_json : manga_json) {
+ if(!item_json.isObject())
+ continue;
+
+ const Json::Value &title_json = item_json["title"];
+ const Json::Value &url_json = item_json["url"];
+ const Json::Value &image_json = item_json["image"];
+ if(!title_json.isString() || !url_json.isString())
+ continue;
+
+ auto body_item = BodyItem::create(strip(title_json.asString()));
+ body_item->url = strip(url_json.asString());
+ if(image_json.isString())
+ body_item->thumbnail_url = strip(image_json.asString());
+ result_items.push_back(std::move(body_item));
+ }
+
+ return result_items;
+ })
+ .list_chapters_handler("//div[class='episodes-list']//a", "text", "href", "/manga/")
+ .list_chapters_uploaded_time_handler("//div[class='episodes-list']//td[class='episode-date']", "text", nullptr)
+ .list_page_images_handler("//div[id='content']//img", "src", "/chapter_files/")
+ .manga_id_handler("/manga/", "/");
+ }
+
static void add_pornhub_handlers(MediaGenericSearchPage *media_generic_search_page) {
media_generic_search_page->search_handler("https://www.pornhub.com/video/search?search=%s&page=%p", 1)
.text_handler({{"//div[class='nf-videos']//div[class='phimage']//a", "title", "href", "/view_video.php"}})
@@ -873,13 +910,14 @@ namespace QuickMedia {
const Json::Value &title_json = json_item["tf"];
const Json::Value &url_json = json_item["u"];
const Json::Value &thumbnail_url_json = json_item["i"];
- if(!title_json.isString() || !url_json.isString() || !thumbnail_url_json.isString())
+ if(!title_json.isString() || !url_json.isString())
continue;
MediaRelatedItem related_item;
related_item.title = title_json.asString();
related_item.url = url_json.asString();
- related_item.thumbnail_url = thumbnail_url_json.asString();
+ if(thumbnail_url_json.isString())
+ related_item.thumbnail_url = thumbnail_url_json.asString();
related_items.push_back(std::move(related_item));
}
@@ -929,6 +967,7 @@ namespace QuickMedia {
pipe_body->items.push_back(create_launcher_body_item("Manganelo", "manganelo", resources_root + "icons/manganelo_launcher.png"));
pipe_body->items.push_back(create_launcher_body_item("Manganelos", "manganelos", resources_root + "icons/manganelos_launcher.png"));
pipe_body->items.push_back(create_launcher_body_item("Mangatown", "mangatown", resources_root + "icons/mangatown_launcher.png"));
+ pipe_body->items.push_back(create_launcher_body_item("Readm", "readm", resources_root + "icons/readm_launcher.png"));
pipe_body->items.push_back(create_launcher_body_item("Matrix", "matrix", resources_root + "icons/matrix_launcher.png"));
pipe_body->items.push_back(create_launcher_body_item("Nyaa.si", "nyaa.si", resources_root + "icons/nyaa_si_launcher.png"));
pipe_body->items.push_back(create_launcher_body_item("Soundcloud", "soundcloud", resources_root + "icons/soundcloud_launcher.png"));
@@ -972,6 +1011,14 @@ namespace QuickMedia {
auto search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER);
auto history_page = std::make_unique<HistoryPage>(this, tabs.front().page.get(), search_bar.get(), HistoryType::MANGA);
tabs.push_back(Tab{create_body(), std::move(history_page), std::move(search_bar)});
+ } else if(strcmp(plugin_name, "readm") == 0) {
+ auto search_page = std::make_unique<MangaGenericSearchPage>(this, plugin_name, "https://readm.org/");
+ add_readm_handlers(search_page.get());
+ tabs.push_back(Tab{create_body(), std::move(search_page), create_search_bar("Search...", 400)});
+
+ auto search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER);
+ auto history_page = std::make_unique<HistoryPage>(this, tabs.front().page.get(), search_bar.get(), HistoryType::MANGA);
+ tabs.push_back(Tab{create_body(), std::move(history_page), std::move(search_bar)});
} else if(strcmp(plugin_name, "manga") == 0) {
auto manganelo = std::make_unique<ManganeloSearchPage>(this);
auto manganelos = std::make_unique<MangaGenericSearchPage>(this, "manganelos", "http://manganelos.com/");
@@ -980,12 +1027,15 @@ namespace QuickMedia {
add_mangatown_handlers(mangatown.get());
auto mangakatana = std::make_unique<MangaGenericSearchPage>(this, "mangakatana", "https://mangakatana.com/", false);
add_mangakatana_handlers(mangakatana.get());
+ auto readm = std::make_unique<MangaGenericSearchPage>(this, "readm", "https://readm.org/");
+ add_readm_handlers(readm.get());
std::vector<MangaPlugin> pages;
pages.push_back({std::move(manganelo), "Manganelo", "manganelo", resources_root + "images/" + get_plugin_logo_name("manganelo")});
pages.push_back({std::move(manganelos), "Manganelos", "manganelos", resources_root + "images/" + get_plugin_logo_name("manganelos")});
pages.push_back({std::move(mangatown), "Mangatown", "mangatown", resources_root + "images/" + get_plugin_logo_name("mangatown")});
pages.push_back({std::move(mangakatana), "Mangakatana", "mangakatana", resources_root + "images/" + get_plugin_logo_name("mangakatana")});
+ pages.push_back({std::move(readm), "Readm", "readm", resources_root + "images/" + get_plugin_logo_name("readm")});
// TODO: Add mangadex
tabs.push_back(Tab{create_body(), std::make_unique<MangaCombinedSearchPage>(this, std::move(pages)), create_search_bar("Search...", 400)});
@@ -1271,6 +1321,8 @@ namespace QuickMedia {
body_item->url = "https://mangatown.com/manga/" + base64_decode(filename.string());
else if(strcmp(plugin_name, "mangakatana") == 0)
body_item->url = "https://mangakatana.com/manga/" + base64_decode(filename.string());
+ else if(strcmp(plugin_name, "readm") == 0)
+ body_item->url = "https://readm.org/manga/" + base64_decode(filename.string());
else
fprintf(stderr, "Error: Not implemented: filename to manga chapter list\n");
history_items.push_back(std::move(body_item));
@@ -3102,6 +3154,9 @@ namespace QuickMedia {
} else if(post_result == PostResult::FILE_TYPE_NOT_ALLOWED) {
show_notification("QuickMedia", "Failed to post comment because you are trying to upload a file of a type that is not allowed", Urgency::CRITICAL);
navigation_stage = NavigationStage::VIEWING_COMMENTS;
+ } else if(post_result == PostResult::UPLOAD_FAILED) {
+ show_notification("QuickMedia", "Failed to post comment because file upload failed", Urgency::CRITICAL);
+ navigation_stage = NavigationStage::VIEWING_COMMENTS;
} else if(post_result == PostResult::ERR) {
show_notification("QuickMedia", "Failed to post comment", Urgency::CRITICAL);
navigation_stage = NavigationStage::VIEWING_COMMENTS;