switched to sqlite
This commit is contained in:
@ -1,29 +0,0 @@
|
|||||||
CREATE OR REPLACE FUNCTION public.convert_artist_name(artist_name text) RETURNS text
|
|
||||||
LANGUAGE plpgsql IMMUTABLE STRICT
|
|
||||||
AS $$
|
|
||||||
BEGIN
|
|
||||||
artist_name = trim(artist_name);
|
|
||||||
|
|
||||||
-- only partially deal with url encoding
|
|
||||||
artist_name = regexp_replace(artist_name, '%(20|21|22|23|24|26|27|28|29|2A|2C|2E|2F|3B|3C|3E|3F|5B|5C|5D|5E|60|7B|7C|7D|7E)|artist', '', 'g');
|
|
||||||
artist_name = regexp_replace(artist_name, '%25', '%', 'g');
|
|
||||||
artist_name = regexp_replace(artist_name, '%2B', '+', 'g');
|
|
||||||
artist_name = regexp_replace(artist_name, '%2D', '-', 'g');
|
|
||||||
artist_name = regexp_replace(artist_name, '%2E', '.', 'g');
|
|
||||||
artist_name = regexp_replace(artist_name, '%2F', '/', 'g');
|
|
||||||
artist_name = regexp_replace(artist_name, '%3A', ':', 'g');
|
|
||||||
artist_name = regexp_replace(artist_name, '%3D', '=', 'g');
|
|
||||||
artist_name = regexp_replace(artist_name, '%40', '@', 'g');
|
|
||||||
artist_name = regexp_replace(artist_name, '%5F', '_', 'g');
|
|
||||||
|
|
||||||
-- check if any other url encoding still exists
|
|
||||||
IF regexp_count(artist_name, '%[0-9A-Fa-f]{2}') <> 0 THEN
|
|
||||||
RETURN NULL;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
artist_name = rtrim(artist_name, '-_');
|
|
||||||
artist_name = lower(artist_name);
|
|
||||||
|
|
||||||
RETURN artist_name;
|
|
||||||
END;
|
|
||||||
$$;
|
|
@ -1,30 +0,0 @@
|
|||||||
CREATE OR REPLACE PROCEDURE public.create_tables()
|
|
||||||
LANGUAGE SQL
|
|
||||||
AS $$
|
|
||||||
DROP TABLE IF EXISTS artist_website;
|
|
||||||
DROP TABLE IF EXISTS website;
|
|
||||||
DROP TABLE IF EXISTS artist;
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS artist (
|
|
||||||
id serial PRIMARY KEY,
|
|
||||||
name text NOT NULL,
|
|
||||||
CONSTRAINT a_name UNIQUE(name)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS website (
|
|
||||||
id serial PRIMARY KEY,
|
|
||||||
name text NOT NULL,
|
|
||||||
CONSTRAINT w_name UNIQUE(name)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS artist_website (
|
|
||||||
id serial PRIMARY KEY,
|
|
||||||
url text NOT NULL,
|
|
||||||
folder_path text,
|
|
||||||
website_id integer,
|
|
||||||
artist_id integer,
|
|
||||||
CONSTRAINT aw_url UNIQUE(url),
|
|
||||||
CONSTRAINT aw_artist FOREIGN KEY (artist_id) REFERENCES artist (ID),
|
|
||||||
CONSTRAINT aw_website FOREIGN KEY (website_id) REFERENCES website (ID)
|
|
||||||
);
|
|
||||||
$$;
|
|
@ -1,24 +0,0 @@
|
|||||||
CREATE OR REPLACE FUNCTION public.get_all_convertable_paths() RETURNS Table (bad_path text, good_path text)
|
|
||||||
LANGUAGE plpgsql STRICT
|
|
||||||
AS $$
|
|
||||||
DECLARE
|
|
||||||
url text;
|
|
||||||
artist_name text;
|
|
||||||
temp_bad_path text;
|
|
||||||
temp_good_path text;
|
|
||||||
BEGIN
|
|
||||||
FOR url IN
|
|
||||||
SELECT aw.url FROM artist_website aw
|
|
||||||
LOOP
|
|
||||||
artist_name = get_artist_name(url);
|
|
||||||
temp_bad_path = concat('Artists/', artist_name);
|
|
||||||
temp_good_path = concat('Artists/', convert_artist_name(artist_name));
|
|
||||||
|
|
||||||
PERFORM * FROM artist WHERE artist.name = artist_name;
|
|
||||||
|
|
||||||
IF NOT FOUND THEN
|
|
||||||
RETURN QUERY SELECT temp_bad_path,temp_good_path;
|
|
||||||
END IF;
|
|
||||||
END LOOP;
|
|
||||||
END;
|
|
||||||
$$;
|
|
@ -1,27 +0,0 @@
|
|||||||
CREATE OR REPLACE FUNCTION public.get_artist_name(in_url text) RETURNS text
|
|
||||||
LANGUAGE plpgsql IMMUTABLE STRICT
|
|
||||||
AS $$
|
|
||||||
DECLARE
|
|
||||||
artist_name text;
|
|
||||||
BEGIN
|
|
||||||
in_url = trim(in_url);
|
|
||||||
|
|
||||||
IF regexp_like(in_url, 'rule34\.xxx') THEN
|
|
||||||
artist_name = substring(in_url from 52);
|
|
||||||
ELSIF regexp_like(in_url, 'allthefallen\.moe') THEN
|
|
||||||
artist_name = substring(in_url from 43);
|
|
||||||
ELSIF regexp_like(in_url, 'e621\.net') THEN
|
|
||||||
artist_name = substring(in_url from 29);
|
|
||||||
ELSIF regexp_like(in_url, 'gelbooru\.com') THEN
|
|
||||||
artist_name = substring(in_url from 54);
|
|
||||||
ELSIF regexp_like(in_url, 'hypnohub\.net') THEN
|
|
||||||
artist_name = substring(in_url from 54);
|
|
||||||
ELSIF regexp_like(in_url, 'konachan\.com') THEN
|
|
||||||
artist_name = substring(in_url from 32);
|
|
||||||
ELSE
|
|
||||||
RETURN NULL;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
RETURN artist_name;
|
|
||||||
END;
|
|
||||||
$$;
|
|
@ -1,16 +0,0 @@
|
|||||||
CREATE OR REPLACE FUNCTION public.get_urls_and_paths(website_name text) RETURNS TABLE (out_url text, out_website_name text)
|
|
||||||
LANGUAGE plpgsql
|
|
||||||
AS $$
|
|
||||||
BEGIN
|
|
||||||
RETURN QUERY SELECT aw.url, aw.folder_path
|
|
||||||
FROM artist_website aw
|
|
||||||
INNER JOIN website w ON aw.website_id = w.id
|
|
||||||
WHERE w.name ILIKE website_name;
|
|
||||||
|
|
||||||
IF NOT FOUND THEN
|
|
||||||
RAISE EXCEPTION 'No urls and paths found for website: %', website_name;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
RETURN;
|
|
||||||
END;
|
|
||||||
$$;
|
|
@ -1,37 +0,0 @@
|
|||||||
CREATE OR REPLACE FUNCTION public.get_website_name(in_url text) RETURNS text
|
|
||||||
LANGUAGE plpgsql IMMUTABLE STRICT
|
|
||||||
AS $$
|
|
||||||
DECLARE
|
|
||||||
website_name text;
|
|
||||||
BEGIN
|
|
||||||
in_url = trim(in_url);
|
|
||||||
|
|
||||||
IF regexp_like(in_url, 'rule34\.xxx') THEN
|
|
||||||
website_name = 'Rule34';
|
|
||||||
ELSIF regexp_like(in_url, 'kemono\.su') THEN
|
|
||||||
website_name = 'Kemono';
|
|
||||||
ELSIF regexp_like(in_url, 'coomer\.su') THEN
|
|
||||||
website_name = 'Coomer';
|
|
||||||
ELSIF regexp_like(in_url, 'gofile\.io') THEN
|
|
||||||
website_name = 'GoFile';
|
|
||||||
ELSIF regexp_like(in_url, 'allthefallen\.moe') THEN
|
|
||||||
website_name = 'ATF';
|
|
||||||
ELSIF regexp_like(in_url, 'e621\.net') THEN
|
|
||||||
website_name = 'e621';
|
|
||||||
ELSIF regexp_like(in_url, 'gelbooru\.com') THEN
|
|
||||||
website_name = 'Gelbooru';
|
|
||||||
ELSIF regexp_like(in_url, 'hypnohub\.net') THEN
|
|
||||||
website_name = 'HypnoHub';
|
|
||||||
ELSIF regexp_like(in_url, 'konachan\.com') THEN
|
|
||||||
website_name = 'Konachan';
|
|
||||||
ELSIF regexp_like(in_url, 'pixiv\.net') THEN
|
|
||||||
website_name = 'Pixiv';
|
|
||||||
ELSIF regexp_like(in_url, 'fantia\.jp') THEN
|
|
||||||
website_name = 'Fantia';
|
|
||||||
ELSE
|
|
||||||
RETURN NULL;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
RETURN website_name;
|
|
||||||
END;
|
|
||||||
$$;
|
|
@ -1,39 +0,0 @@
|
|||||||
CREATE OR REPLACE FUNCTION public.insert_url(in_url text) RETURNS text
|
|
||||||
LANGUAGE plpgsql STRICT
|
|
||||||
AS $$
|
|
||||||
DECLARE
|
|
||||||
ret_value integer;
|
|
||||||
temp_folder_path text;
|
|
||||||
BEGIN
|
|
||||||
PERFORM * FROM artist_website aw
|
|
||||||
WHERE aw.url = in_url;
|
|
||||||
|
|
||||||
IF FOUND THEN
|
|
||||||
RAISE EXCEPTION 'url already exists';
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
INSERT INTO artist_website (url) VALUES (in_url);
|
|
||||||
|
|
||||||
SELECT * INTO ret_value FROM set_artist_name(in_url);
|
|
||||||
IF ret_value <> 0 THEN
|
|
||||||
DELETE FROM artist_website WHERE url = in_url;
|
|
||||||
RAISE EXCEPTION 'could not set artist_name';
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
SELECT * INTO ret_value FROM set_website_name(in_url);
|
|
||||||
IF ret_value <> 0 THEN
|
|
||||||
DELETE FROM artist_website WHERE url = in_url;
|
|
||||||
RAISE EXCEPTION 'could not set website_name';
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
SELECT * INTO ret_value FROM set_folder_path(in_url);
|
|
||||||
IF ret_value <> 0 THEN
|
|
||||||
DELETE FROM artist_website WHERE url = in_url;
|
|
||||||
RAISE EXCEPTION 'could not set folder_path';
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
SELECT folder_path INTO temp_folder_path FROM artist_website WHERE url ILIKE in_url;
|
|
||||||
|
|
||||||
RETURN concat(in_url, ' # ', temp_folder_path);
|
|
||||||
END;
|
|
||||||
$$;
|
|
@ -1,44 +0,0 @@
|
|||||||
CREATE OR REPLACE FUNCTION public.insert_url_with_custom_artist(in_url text, in_artist_name text) RETURNS text
|
|
||||||
LANGUAGE plpgsql STRICT
|
|
||||||
AS $$
|
|
||||||
DECLARE
|
|
||||||
ret_value integer;
|
|
||||||
temp_artist_id integer;
|
|
||||||
temp_folder_path text;
|
|
||||||
BEGIN
|
|
||||||
PERFORM * FROM artist_website aw
|
|
||||||
WHERE aw.url = in_url;
|
|
||||||
|
|
||||||
IF FOUND THEN
|
|
||||||
RAISE EXCEPTION 'url already exists';
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
PERFORM * FROM artist a
|
|
||||||
WHERE a.name = in_artist_name;
|
|
||||||
|
|
||||||
IF NOT FOUND THEN
|
|
||||||
INSERT INTO artist (name) VALUES (in_artist_name);
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
SELECT artist.id INTO temp_artist_id FROM artist
|
|
||||||
WHERE artist.name = in_artist_name;
|
|
||||||
|
|
||||||
INSERT INTO artist_website (url, artist_id) VALUES (in_url, temp_artist_id);
|
|
||||||
|
|
||||||
SELECT * INTO ret_value FROM set_website_name(in_url);
|
|
||||||
IF ret_value <> 0 THEN
|
|
||||||
DELETE FROM artist_website WHERE url = in_url;
|
|
||||||
RAISE EXCEPTION 'could not set website_name';
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
SELECT * INTO ret_value FROM set_folder_path(in_url);
|
|
||||||
IF ret_value <> 0 THEN
|
|
||||||
DELETE FROM artist_website WHERE url = in_url;
|
|
||||||
RAISE EXCEPTION 'could not set folder_path';
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
SELECT folder_path INTO temp_folder_path FROM artist_website WHERE url ILIKE in_url;
|
|
||||||
|
|
||||||
RETURN concat(in_url, ' # ', temp_folder_path);
|
|
||||||
END;
|
|
||||||
$$;
|
|
@ -1,29 +0,0 @@
|
|||||||
CREATE OR REPLACE FUNCTION public.set_artist_name(in_url text) RETURNS integer
|
|
||||||
LANGUAGE plpgsql STRICT
|
|
||||||
AS $$
|
|
||||||
DECLARE
|
|
||||||
temp_artist_id integer;
|
|
||||||
temp_artist_name text;
|
|
||||||
BEGIN
|
|
||||||
temp_artist_name = get_artist_name(in_url);
|
|
||||||
temp_artist_name = convert_artist_name(temp_artist_name);
|
|
||||||
|
|
||||||
IF temp_artist_name IS NULL THEN
|
|
||||||
RETURN 1;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
PERFORM * FROM artist WHERE artist.name = temp_artist_name;
|
|
||||||
|
|
||||||
IF NOT FOUND THEN
|
|
||||||
INSERT INTO artist (name) VALUES (temp_artist_name);
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
SELECT artist.id INTO temp_artist_id FROM artist
|
|
||||||
WHERE artist.name = temp_artist_name;
|
|
||||||
|
|
||||||
UPDATE artist_website SET artist_id = temp_artist_id
|
|
||||||
WHERE url = in_url;
|
|
||||||
|
|
||||||
RETURN 0;
|
|
||||||
END;
|
|
||||||
$$;
|
|
@ -1,38 +0,0 @@
|
|||||||
CREATE OR REPLACE FUNCTION public.set_folder_path(in_url text) RETURNS integer
|
|
||||||
LANGUAGE plpgsql STRICT
|
|
||||||
AS $$
|
|
||||||
DECLARE
|
|
||||||
temp_folder_path text;
|
|
||||||
aw_artist_id integer;
|
|
||||||
aw_website_id integer;
|
|
||||||
artist_name text;
|
|
||||||
website_name text;
|
|
||||||
BEGIN
|
|
||||||
SELECT aw.artist_id INTO aw_artist_id FROM artist_website aw
|
|
||||||
WHERE aw.url = in_url;
|
|
||||||
|
|
||||||
IF aw_artist_id IS NULL THEN
|
|
||||||
RETURN 1;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
SELECT aw.website_id INTO aw_website_id FROM artist_website aw
|
|
||||||
WHERE aw.url = in_url;
|
|
||||||
|
|
||||||
IF aw_website_id IS NULL THEN
|
|
||||||
RETURN 1;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
SELECT artist.name INTO artist_name FROM artist
|
|
||||||
WHERE artist.id = aw_artist_id;
|
|
||||||
|
|
||||||
SELECT website.name INTO website_name FROM website
|
|
||||||
WHERE website.id = aw_website_id;
|
|
||||||
|
|
||||||
temp_folder_path = concat('Artists/', artist_name, '/', website_name);
|
|
||||||
|
|
||||||
UPDATE artist_website SET folder_path = temp_folder_path
|
|
||||||
WHERE url = in_url;
|
|
||||||
|
|
||||||
RETURN 0;
|
|
||||||
END;
|
|
||||||
$$;
|
|
@ -1,28 +0,0 @@
|
|||||||
CREATE OR REPLACE FUNCTION public.set_website_name(in_url text) RETURNS integer
|
|
||||||
LANGUAGE plpgsql STRICT
|
|
||||||
AS $$
|
|
||||||
DECLARE
|
|
||||||
temp_website_id integer;
|
|
||||||
temp_website_name text;
|
|
||||||
BEGIN
|
|
||||||
temp_website_name = get_website_name(in_url);
|
|
||||||
|
|
||||||
IF temp_website_name IS NULL THEN
|
|
||||||
RETURN 1;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
PERFORM * FROM website WHERE website.name = temp_website_name;
|
|
||||||
|
|
||||||
IF NOT FOUND THEN
|
|
||||||
INSERT INTO website (name) VALUES (temp_website_name);
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
SELECT website.id INTO temp_website_id FROM website
|
|
||||||
WHERE website.name = temp_website_name;
|
|
||||||
|
|
||||||
UPDATE artist_website SET website_id = temp_website_id
|
|
||||||
WHERE url = in_url;
|
|
||||||
|
|
||||||
RETURN 0;
|
|
||||||
END;
|
|
||||||
$$;
|
|
@ -1,14 +0,0 @@
|
|||||||
CREATE OR REPLACE FUNCTION public.website_exists(in_website_name text) RETURNS boolean
|
|
||||||
LANGUAGE plpgsql STRICT
|
|
||||||
AS $$
|
|
||||||
BEGIN
|
|
||||||
PERFORM * FROM website w
|
|
||||||
WHERE w.name = in_website_name;
|
|
||||||
|
|
||||||
IF FOUND THEN
|
|
||||||
RETURN 1;
|
|
||||||
ELSE
|
|
||||||
RETURN 0;
|
|
||||||
END IF;
|
|
||||||
END;
|
|
||||||
$$;
|
|
Reference in New Issue
Block a user