diff --git a/.gitignore b/.gitignore index b6e4761..68aa797 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,15 @@ dmypy.json # Pyre type checker .pyre/ + +# My files + +.vscode + +dw/* +cookies/* +chromedriver +cfg/* +token.txt +lastdata.txt +dsfsdf.txt \ No newline at end of file diff --git a/README.md b/README.md index 8413d19..36237fd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # manga-parser hlib and ylib parser + +## Requer + +- selenium +- requests +- colorama +- pyperclip +- webbrowser \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..ac7a78d --- /dev/null +++ b/main.py @@ -0,0 +1,184 @@ +from itertools import count +from colorama import Fore, Back, Style +from selenium import webdriver +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.common.action_chains import ActionChains +from PIL import Image +import PIL +import requests +import time +import pickle +import os +import ctypes + +def make_folder(folder): + if not os.path.isdir(os.getcwd()+"\\"+folder): + os.mkdir(os.getcwd()+"\\"+folder) + +def make_file(file): + if not os.path.isfile(os.getcwd()+"\\"+file): + open(os.getcwd()+"\\"+file, "w") + +def pprint(text, colors): + dict_color = {"g": Back.GREEN, "y": Back.YELLOW, "r": Back.RED, "b": Back.BLUE} + print(dict_color[colors] + str(text) + Style.RESET_ALL) + +def pprintr(text, colors): + dict_color = {"g": Back.GREEN, "y": Back.YELLOW, "r": Back.RED, "b": Back.BLUE} + return dict_color[colors] + str(text) + Style.RESET_ALL + +def get_name(num, source_name): + ext_name = source_name.split(".")[-1] + return ((3-len(str(num))) * "0") + str(num) + "." + ext_name + +url_root = { + "hentailib.me":{"img":"https://img.yaoi-chan.me/", "root":"https://hentailib.me"}, + "yaoilib.me":{"img":"https://img.yaoi-chan.me/", "root":"https://yaoilib.me/"}, + "mangalib.me":{"img":"https://img.yaoi-chan.me/", "root":"https://mangalib.me"} +} +exe_drive = os.getcwd()+"\\chromedriver\\chromedriver.exe" +make_folder("dw") +make_folder("cookies") +make_folder("chromedriver") +make_folder("cfg") +make_file("cfg\\list_load.txt") +make_file("cfg\\list_url.txt") +if not os.path.isfile(os.getcwd()+"\\chromedriver\\chromedriver.exe"): + pprint("[ERROR] chromedriver not found! Please download for you Chrome version from https://chromedriver.storage.googleapis.com/index.html", "r") + exit() +driver = webdriver.Chrome(executable_path=exe_drive) +driver.set_window_position(0, 0) +user32 = ctypes.windll.user32 +screensize = [user32.GetSystemMetrics(78), user32.GetSystemMetrics(79)] +driver.set_window_size(screensize[0], screensize[1]) +ddd = input(pprintr("URL or Enter> ", "y")) +if ddd == "": + url_gets = open("cfg/list_url.txt", "r").readlines() + urls_gets = [] + for kk in url_gets: + urls_gets.append(kk.replace("\n", "")) +else: + urls_gets = [ddd] +for url_get in urls_gets: + url_load = open("cfg/list_load.txt", "r").readlines() + urls_load = [] + for kk in url_load: + urls_load.append(kk.replace("\n", "")) + if url_get not in url_load: + dw_folder_root = os.getcwd() + "\dw\(" + url_get.split("//")[1].split("/")[0] + ") " + url_get.split("/")[-1].split("?")[0] + pprint(dw_folder_root, "g") + if not os.path.isdir(dw_folder_root): + os.mkdir(dw_folder_root) + url_domain = url_get.split("//")[1].split("/")[0] + driver.get(url_get) + pprint(url_domain, "g") + if url_domain not in url_root.keys(): + pprint("Not support....", "r") + exit() + if os.path.isfile("cookies\\" + url_domain+".pkl"): + cookies = pickle.load(open("cookies\\" + url_domain+".pkl", "rb")) + pprint(cookies, "b") + for cookie in cookies: + driver.add_cookie(cookie) + else: + url_go = url_root[url_domain]["root"] + driver.get(url_go) + ddd = input(pprintr("Wait login....", "y")) + cookies = driver.get_cookies() + pickle.dump(cookies, open("cookies\\" + url_domain+".pkl","wb")) + pprint(cookies, "b") + driver.get(url_get) + driver.save_screenshot("dw\(" + url_get.split("//")[1].split("/")[0] + ") " + url_get.split("/")[-1].split("?")[0] + ".png") + if url_domain == "hentailib.me" or url_domain == "yaoilib.me" or url_domain == "mangalib.me": + action_chains = ActionChains(driver) + all_button = driver.find_elements_by_tag_name("li") + manga_id = url_get.split("/")[-1].split("?")[0] + pprint(manga_id, "g") + for oo in all_button: + try: + if "chapters" in str(oo.get_attribute("data-key")): + oo.click() + except: + pass + pages_np = driver.find_elements_by_tag_name("a") + pages = [] + for ii in pages_np: + if manga_id in str(ii.get_attribute("href")): + if "/v" in str(ii.get_attribute("href")): + pages.append(str(ii.get_attribute("href")).split("?")[0]) + pages = list(dict.fromkeys(pages)) + pprint(pages, "b") + for page_cur in pages: + driver.get(page_cur) + name_ch = page_cur.split("/")[-2].replace("v", "") + "-" + page_cur.split("/")[-1].replace("c", "") + dw_folder = dw_folder_root + "\\" + name_ch + if not os.path.isdir(dw_folder): + os.mkdir(dw_folder) + pprint(dw_folder, "g") + all_button = driver.find_elements_by_tag_name("button") + for oo in all_button: + try: + if "Мне есть 18 лет" in str(oo.text): + oo.click() + except: + pass + all_button = driver.find_elements_by_tag_name("i") + for oo in all_button: + try: + if "fa-cog" in str(oo.get_attribute("class")): + oo.click() + except: + pass + all_button = driver.find_elements_by_tag_name("label") + for oo in all_button: + try: + if "Вертикальный" in str(oo.text): + oo.click() + except: + pass + all_button = driver.find_elements_by_tag_name("div") + for oo in all_button: + try: + if "modal__close" in str(oo.get_attribute("class")): + oo.click() + except: + pass + continue_scroll = 1 + all_button = driver.find_elements_by_tag_name("select") + for oo in all_button: + try: + if "reader-pages" in str(oo.get_attribute("id")): + all_frame_base = oo + except: + pass + all_frame = all_frame_base.find_elements_by_tag_name("option") + for oo in all_frame: + oo.click() + time.sleep(0.1) + list_img = [] + all_img = driver.find_elements_by_tag_name("img") + for oo in all_img: + try: + if manga_id in str(oo.get_attribute("src")): + list_img.append(oo.get_attribute("src")) + action_chains.send_keys_to_element(oo, Keys.CONTROL, "c") + except: + pass + cookie_req = {} + for dd in cookies: + cookie_req[dd["name"]] = dd["value"] + count_img = 1 + for img_url in list_img: + file_name_head = get_name(count_img, img_url.split("/")[-1]) + pprint("[Downloading] "+file_name_head, "g") + req = requests.get(img_url, cookies=cookie_req, headers={'referer': page_cur}) + file_name = dw_folder + "/" + file_name_head + file = open(file_name, "wb") + file.write(req.content) + file.close() + count_img += 1 + pprint("[READY]", "g") + else: + pprint("URL not support", "r") + urls_load_w = "\n".join(urls_load) + "\n" + url_get + open("cfg/list_load.txt", "w").write(urls_load_w) \ No newline at end of file diff --git a/telegraphgen.py b/telegraphgen.py new file mode 100644 index 0000000..aec2b4b --- /dev/null +++ b/telegraphgen.py @@ -0,0 +1,164 @@ +from tkinter import filedialog +from tkinter import * +from tkinter.ttk import Combobox +from tkinter import messagebox +from telegraph import Telegraph, upload_file +import os.path +import time +from tkinter import scrolledtext +import os +import pyperclip +import webbrowser + +global title_root +global folder + +def save_last_data(): + last_data_f = open("lastdata.txt", "w") + last_data = usernamew.get() + "\n" + last_data = last_data + usernamesw.get() + "\n" + last_data = last_data + urlw.get() + "\n" + last_data = last_data + "0" + "\n" + last_data = last_data + folder + "\n" + last_data = last_data + titlew.get() + last_data_f.write(last_data) + +def clicked_ex(): + messagebox.showinfo('Заголовок', 'Текст') + messagebox.showwarning('Заголовок', 'Текст') + messagebox.showerror('Заголовок', 'Текст') + res = messagebox.askquestion('Заголовок', 'Текст') + res = messagebox.askyesno('Заголовок', 'Текст') + res = messagebox.askyesnocancel('Заголовок', 'Текст') + res = messagebox.askokcancel('Заголовок', 'Текст') + res = messagebox.askretrycancel('Заголовок', 'Текст') + print() + +def title_gen(text): + window.title("Telegra.ph gen - " + text) + +def save_token(tlph): + if os.path.isfile('token.txt'): + pass + else: + token = tlph.get_access_token() + open("token.txt", "w").write(token) + +def select_folder(): + global folder + folder = str(filedialog.askdirectory()) + folderw.configure(text=folder) + btnok['state'] = 'normal' + title_gen("Готово") + +def main_start(): + btnok['state'] = 'disabled' + title_gen("Иницилизация") + save_last_data() + if combotype.get() == "mix": + type_file = ["png", "jpg", "jpeg", "gif"] + else: + type_file = [combotype.get()] + username = usernamew.get() + usernames = usernamesw.get() + url_credit = urlw.get() + if os.path.isfile(folder+'/info.txt'): + info = open(folder+'/info.txt', "r").read() + else: + info = "" + title = titlew.get() + title_gen("Генерация файлов") + list_file = os.listdir(path=folder) + list_file.sort() + list_file_ready = [] + for ii in list_file: + if ii.split(".")[-1] in type_file: + list_file_ready.append(folder+"/"+ii) + title_gen("Загрузка файлов "+str(len(list_file_ready))) + list_url_ready = [] + count = 1 + for tt in list_file_ready: + print("Загрузка файла "+str(count)+"/"+str(len(list_file_ready))) + list_url_ready.append("https://te.legra.ph"+str(upload_file(tt)[0])) + count += 1 + title_gen("Генерация страницы") + htmlc = "
" + info.replace("\n", "
") + "