good progress
This commit is contained in:
@ -1,11 +1,84 @@
|
||||
import subprocess
|
||||
import sqlite3
|
||||
|
||||
db_link = r"https://rule34.xxx/index.php\?page=post\&s\=list\&tags\=meeewchi"
|
||||
db_artist = "meeewchi"
|
||||
conn = sqlite3.connect("Hentai.sqlite3")
|
||||
conn.executescript("""
|
||||
DROP TABLE IF EXISTS artist;
|
||||
DROP TABLE IF EXISTS website;
|
||||
DROP TABLE IF EXISTS links;
|
||||
""")
|
||||
conn.executescript("""
|
||||
CREATE TABLE IF NOT EXISTS artist (
|
||||
id integer NOT NULL CONSTRAINT artist_pk PRIMARY KEY AUTOINCREMENT,
|
||||
name text NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS website (
|
||||
id integer NOT NULL CONSTRAINT website_pk PRIMARY KEY AUTOINCREMENT,
|
||||
name text NOT NULL
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS links (
|
||||
id integer NOT NULL CONSTRAINT links_pk PRIMARY KEY AUTOINCREMENT,
|
||||
url text NOT NULL,
|
||||
website_id integer NOT NULL,
|
||||
artist_id integer NOT NULL,
|
||||
CONSTRAINT links_artist FOREIGN KEY (artist_id)
|
||||
REFERENCES artist (id),
|
||||
CONSTRAINT links_website FOREIGN KEY (website_id)
|
||||
REFERENCES website (id)
|
||||
);
|
||||
""")
|
||||
|
||||
def galleryDl(link, artist):
|
||||
command = f"gallery-dl --config gallery-dl/config.json --directory Artists/{artist}/Kemono {link}"
|
||||
process = subprocess.run(command, shell=True, check=True, capture_output=False, encoding="utf-8")
|
||||
|
||||
def insert_into_db(website_name, url, artist):
|
||||
conn.execute(f"INSERT INTO website(name) VALUES('{website_name}')")
|
||||
conn.execute(f"INSERT INTO artist(name) VALUES('{artist}')")
|
||||
sql = f"SELECT id FROM artist WHERE name like '{artist}'"
|
||||
artist_id = conn.execute(sql).fetchone()[0]
|
||||
sql = f"SELECT id FROM website WHERE name like '{website_name}'"
|
||||
website_id = conn.execute(sql).fetchone()[0]
|
||||
values = f"'{url}', '{website_id}', '{artist_id}'"
|
||||
sql = f"INSERT INTO links(url, website_id, artist_id) VALUES({values})"
|
||||
conn.execute(sql)
|
||||
|
||||
|
||||
def import_website(website_name):
|
||||
file_name = f"downloaded_{website_name.lower()}.txt"
|
||||
file_contents = open(file_name).readlines()
|
||||
for line in file_contents:
|
||||
url = line.split("# ")[0].rstrip()
|
||||
artist = line.split("# ")[1].rstrip("\n")
|
||||
insert_into_db(website_name, url, artist)
|
||||
|
||||
|
||||
def read_db():
|
||||
result = conn.execute("""
|
||||
SELECT
|
||||
l.url,
|
||||
w.name,
|
||||
a.name
|
||||
FROM links l
|
||||
INNER JOIN website w ON l.website_id = w.id
|
||||
INNER JOIN artist a ON l.artist_id = a.id
|
||||
""")
|
||||
return result.fetchall()
|
||||
|
||||
|
||||
def galleryDl(url, website_name, artist_name):
|
||||
directory = f"--directory Artists/{artist_name}/{website_name}"
|
||||
command = f"gallery-dl --config gallery-dl/config.json {directory} {url}"
|
||||
print(f"command: {command}")
|
||||
return
|
||||
process = subprocess.run(command, shell=True)
|
||||
print(f'Command \'{process.args}\' exited with {process.returncode} code')
|
||||
|
||||
galleryDl(db_link, db_artist)
|
||||
|
||||
# This will not work with Rule34 as is
|
||||
# Rule34 will need it's artists to be added like the others
|
||||
import_website("Kemono")
|
||||
conn.commit()
|
||||
db_contents = read_db()
|
||||
conn.close()
|
||||
|
||||
for row in db_contents:
|
||||
# print(row)
|
||||
galleryDl(row[0], row[1], row[2])
|
||||
|
Reference in New Issue
Block a user