almost done
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
import subprocess
|
||||
import sqlite3
|
||||
import os
|
||||
import urllib.parse
|
||||
import shutil
|
||||
|
||||
# conn = sqlite3.connect("Hentai.sqlite3")
|
||||
conn = sqlite3.connect(":memory:")
|
||||
@ -30,6 +33,44 @@ conn.executescript("""
|
||||
""")
|
||||
|
||||
|
||||
def get_artist_from_url(url):
|
||||
if "rule34.xxx" in url:
|
||||
return urllib.parse.unquote(url)[51:]
|
||||
if "kemono.su" in url or "coomer.su" in url:
|
||||
return url.split("/")[5]
|
||||
return ""
|
||||
|
||||
|
||||
def mv(source, destination):
|
||||
if not os.path.isdir(source):
|
||||
return
|
||||
if os.path.isfile(source):
|
||||
shutil.copy(source, destination)
|
||||
shutil.rmtree(source)
|
||||
return
|
||||
|
||||
for item in os.listdir(source):
|
||||
if not os.path.isdir(destination):
|
||||
os.rename(source, destination)
|
||||
return
|
||||
|
||||
if os.path.isdir(f"{source}/{item}"):
|
||||
mv(f"{source}/{item}", f"{destination}/{item}")
|
||||
elif os.path.isfile(f"{destination}/{item}"):
|
||||
shutil.copy(f"{source}/{item}", f"{destination}/{item}")
|
||||
else:
|
||||
shutil.copy(f"{source}/{item}", f"{destination}")
|
||||
shutil.rmtree(source)
|
||||
|
||||
|
||||
# existing folder names may be not what is wanted, so this will take care of it
|
||||
def name_needed(url, artist):
|
||||
artist_from_url = get_artist_from_url(url)
|
||||
if artist_from_url == "":
|
||||
exit(1)
|
||||
mv(f"Artists/{artist_from_url}", f"Artists/{artist}")
|
||||
|
||||
|
||||
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}')")
|
||||
@ -51,9 +92,13 @@ def import_website(website_name):
|
||||
for line in file_contents:
|
||||
if line.startswith("#"):
|
||||
continue
|
||||
if "#" not in line:
|
||||
continue
|
||||
url = line.split("# ")[0].rstrip()
|
||||
artist = line.split("# ")[1].rstrip("\n")
|
||||
artist = line.split("# ")[1].rstrip()
|
||||
name_needed(url, artist)
|
||||
insert_into_db(website_name, url, artist)
|
||||
break # do only on for now
|
||||
|
||||
|
||||
def read_db():
|
||||
@ -80,11 +125,11 @@ def galleryDl(url, website_name, artist_name):
|
||||
|
||||
# This will not work with Rule34 as is
|
||||
# Rule34 will need it's artists to be added like the others
|
||||
import_website("Coomer")
|
||||
import_website("Rule34")
|
||||
# conn.commit()
|
||||
db_contents = read_db()
|
||||
conn.close()
|
||||
|
||||
for row in db_contents:
|
||||
# print(row)
|
||||
galleryDl(row[0], row[1], row[2])
|
||||
print(row)
|
||||
# galleryDl(row[0], row[1], row[2])
|
||||
|
Reference in New Issue
Block a user