Update sites/pixiv.py
Browse files- sites/pixiv.py +26 -17
sites/pixiv.py
CHANGED
@@ -44,9 +44,9 @@ def getOrderedPixivImages(driver,exec_path,user_search,num_pics,num_pages,search
|
|
44 |
driver.get(link)
|
45 |
|
46 |
# Will use those when not logged in
|
47 |
-
bar_search =
|
48 |
-
li_search = "//h3
|
49 |
-
premium_search = "//h3
|
50 |
search_param = {
|
51 |
"bar_search": bar_search,
|
52 |
"li_search": li_search,
|
@@ -55,19 +55,21 @@ def getOrderedPixivImages(driver,exec_path,user_search,num_pics,num_pages,search
|
|
55 |
|
56 |
# Check if logged in otherwise log in with credentials
|
57 |
try:
|
58 |
-
#
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
if driver.find_elements(By.XPATH, "//button[contains(text(), 'Add to your favorites')]"):
|
63 |
success_login = True
|
|
|
|
|
|
|
|
|
64 |
|
65 |
if not success_login:
|
66 |
print("Failed! You are not logged in...")
|
67 |
|
68 |
-
except:
|
69 |
-
print("Failed! You are not logged in...")
|
70 |
-
pass
|
71 |
|
72 |
if 1 not in imageControl:
|
73 |
searchQuery(user_search, driver, search_param["bar_search"], isLoggedIn=success_login)
|
@@ -87,7 +89,7 @@ def getOrderedPixivImages(driver,exec_path,user_search,num_pics,num_pages,search
|
|
87 |
r_18 = 1 if 1 in viewRestriction else 0
|
88 |
ultimatium = 1 if 0 in imageControl else 0
|
89 |
order_by_oldest = 1 if 2 in imageControl else 0
|
90 |
-
ai_mode = 1
|
91 |
|
92 |
if not contains_works(driver, search_param["li_search"]):
|
93 |
print("No works found...")
|
@@ -133,9 +135,9 @@ def getOrderedPixivImages(driver,exec_path,user_search,num_pics,num_pages,search
|
|
133 |
# Click show all results
|
134 |
try:
|
135 |
time.sleep(1)
|
136 |
-
show_all_div = driver.find_element(By.XPATH, "//div
|
137 |
if show_all_div:
|
138 |
-
|
139 |
except:
|
140 |
pass
|
141 |
|
@@ -145,7 +147,7 @@ def getOrderedPixivImages(driver,exec_path,user_search,num_pics,num_pages,search
|
|
145 |
if freemiumSearch:
|
146 |
while len(image_locations) < num_pics*num_pages:
|
147 |
search_image(driver,exec_path,filters,search_param=search_param,searchLimit=searchLimit)
|
148 |
-
if
|
149 |
print("Reached end of search results")
|
150 |
break
|
151 |
driver.quit()
|
@@ -169,7 +171,6 @@ def search_image(driver,exec_path,filters,search_param,searchLimit={"pagecount":
|
|
169 |
images = search_image_type(search_type, driver, search_param=search_param)
|
170 |
|
171 |
for image in images:
|
172 |
-
time.sleep(2)
|
173 |
if len(image_locations) - prev_search >= searchLimit["imagecount"]*searchLimit["pagecount"] or len(image_locations) - temp_img_len >= searchLimit["imagecount"]:
|
174 |
break
|
175 |
image = image.find_element(By.XPATH, "." + "/" + "/a")
|
@@ -241,7 +242,7 @@ def login_handler(driver, exec_path, user_name, pass_word):
|
|
241 |
actions.click(user_btn[1]).send_keys(pass_word).perform()
|
242 |
|
243 |
# Log in button
|
244 |
-
driver.find_element(By.XPATH,"//button[contains(text(), '
|
245 |
|
246 |
return True
|
247 |
|
@@ -392,3 +393,11 @@ def process_ai_mode(imageLink, image, driver, exec_path):
|
|
392 |
os.remove(img_loc)
|
393 |
except:
|
394 |
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
driver.get(link)
|
45 |
|
46 |
# Will use those when not logged in
|
47 |
+
bar_search = generate_xpath_query("//input", "@placeholder", "search works")
|
48 |
+
li_search = generate_xpath_query("//h3", "text()", "works", "illustrations and manga", "illustrations") + "/ancestor::section[1]/div[2]//li"
|
49 |
+
premium_search = generate_xpath_query("//h3", 'text()', 'popular works') + "/ancestor::section[1]/div[2]//li"
|
50 |
search_param = {
|
51 |
"bar_search": bar_search,
|
52 |
"li_search": li_search,
|
|
|
55 |
|
56 |
# Check if logged in otherwise log in with credentials
|
57 |
try:
|
58 |
+
# Check for favorite button (only appears for logged in users)
|
59 |
+
favorite_buttons = driver.find_elements(By.XPATH, case_insensitive_xpath_contains("//button", 'Add to your favorites'))
|
60 |
+
|
61 |
+
if favorite_buttons:
|
|
|
62 |
success_login = True
|
63 |
+
elif user_name and pass_word:
|
64 |
+
print("Logging in...")
|
65 |
+
if login_handler(driver, exec_path, user_name, pass_word):
|
66 |
+
success_login = True
|
67 |
|
68 |
if not success_login:
|
69 |
print("Failed! You are not logged in...")
|
70 |
|
71 |
+
except Exception as e:
|
72 |
+
print(f"Failed! You are not logged in... Exception: {e}")
|
|
|
73 |
|
74 |
if 1 not in imageControl:
|
75 |
searchQuery(user_search, driver, search_param["bar_search"], isLoggedIn=success_login)
|
|
|
89 |
r_18 = 1 if 1 in viewRestriction else 0
|
90 |
ultimatium = 1 if 0 in imageControl else 0
|
91 |
order_by_oldest = 1 if 2 in imageControl else 0
|
92 |
+
ai_mode = 1 if 3 in imageControl else 0
|
93 |
|
94 |
if not contains_works(driver, search_param["li_search"]):
|
95 |
print("No works found...")
|
|
|
135 |
# Click show all results
|
136 |
try:
|
137 |
time.sleep(1)
|
138 |
+
show_all_div = driver.find_element(By.XPATH, case_insensitive_xpath_contains("//div", 'Show all'))
|
139 |
if show_all_div:
|
140 |
+
show_all_div.click()
|
141 |
except:
|
142 |
pass
|
143 |
|
|
|
147 |
if freemiumSearch:
|
148 |
while len(image_locations) < num_pics*num_pages:
|
149 |
search_image(driver,exec_path,filters,search_param=search_param,searchLimit=searchLimit)
|
150 |
+
if len(image_locations) < num_pics*num_pages and not valid_page(driver):
|
151 |
print("Reached end of search results")
|
152 |
break
|
153 |
driver.quit()
|
|
|
171 |
images = search_image_type(search_type, driver, search_param=search_param)
|
172 |
|
173 |
for image in images:
|
|
|
174 |
if len(image_locations) - prev_search >= searchLimit["imagecount"]*searchLimit["pagecount"] or len(image_locations) - temp_img_len >= searchLimit["imagecount"]:
|
175 |
break
|
176 |
image = image.find_element(By.XPATH, "." + "/" + "/a")
|
|
|
242 |
actions.click(user_btn[1]).send_keys(pass_word).perform()
|
243 |
|
244 |
# Log in button
|
245 |
+
driver.find_element(By.XPATH,"//button[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'log in')]").click()
|
246 |
|
247 |
return True
|
248 |
|
|
|
393 |
os.remove(img_loc)
|
394 |
except:
|
395 |
return True
|
396 |
+
|
397 |
+
|
398 |
+
def case_insensitive_xpath_contains(xpath, text):
|
399 |
+
return f"{xpath}[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '{text.lower()}')]"
|
400 |
+
|
401 |
+
|
402 |
+
def generate_xpath_query(base_xpath, attribute, *args):
|
403 |
+
return base_xpath + "[" + " or ".join(f"translate({attribute}, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = '{arg.lower()}'" for arg in args) + "]"
|