aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xautomediabin120760 -> 120760 bytes
-rwxr-xr-xopen_media.py2
-rw-r--r--src/html.c57
3 files changed, 51 insertions, 8 deletions
diff --git a/automedia b/automedia
index 36b88e9..0d36cc4 100755
--- a/automedia
+++ b/automedia
Binary files differ
diff --git a/open_media.py b/open_media.py
index f7a47cd..0e3fa99 100755
--- a/open_media.py
+++ b/open_media.py
@@ -11,7 +11,7 @@ def run_dmenu(input):
stdout, stderr = process.communicate(input.encode())
if process.returncode == 0:
return stdout
- else:
+ elif process.returncode != 1:
print("Failed to launch dmenu, error: {}".format(stderr))
return None
diff --git a/src/html.c b/src/html.c
index 15d5911..5a559e1 100644
--- a/src/html.c
+++ b/src/html.c
@@ -199,6 +199,45 @@ static int get_plugin_filepath(const char *program_dir, const char *plugin_name,
return 0;
}
+typedef struct {
+ const char *str;
+ size_t size;
+} string_view;
+
+static int is_hex_num(char c) {
+ return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
+}
+
+/* mangadex ids are in this format: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee */
+static int looks_like_mangadex_id(const char *str) {
+ const int len = strlen(str);
+ if(len != 36)
+ return 0;
+
+ string_view parts[] = {
+ { str, 8 },
+ { str + 9, 4 },
+ { str + 9 + 5, 4 },
+ { str + 9 + 5 + 5, 4 },
+ { str + 9 + 5 + 5 + 5, 12 }
+ };
+
+ for(size_t i = 0; i < 5; ++i) {
+ for(size_t j = 0; j < parts[i].size; ++j) {
+ const char c = parts[i].str[j];
+ if(!is_hex_num(c))
+ return 0;
+ }
+ }
+
+ for(size_t i = 0; i < 4; ++i) {
+ if(parts[i].str[parts[i].size] != '-')
+ return 0;
+ }
+
+ return 1;
+}
+
int add_html(const char *name, const char *url, char *html_config_dir, char *program_dir, const char *start_after) {
int result = 0;
@@ -208,14 +247,18 @@ int add_html(const char *name, const char *url, char *html_config_dir, char *pro
}
char domain[2086];
- if(url_extract_domain(url, domain, sizeof(domain)) != 0) {
- fprintf(stderr, "Url %s is too long\n", url);
- return -1;
- }
+ if(looks_like_mangadex_id(url)) {
+ strcpy(domain, "mangadex");
+ } else {
+ if(url_extract_domain(url, domain, sizeof(domain)) != 0) {
+ fprintf(stderr, "Url %s is too long\n", url);
+ return -1;
+ }
- if(domain[0] == '\0') {
- fprintf(stderr, "Invalid url: %s\n", url);
- return -1;
+ if(domain[0] == '\0') {
+ fprintf(stderr, "Invalid url: %s\n", url);
+ return -1;
+ }
}
char domain_plugin_path[PATH_MAX];