From 1ed4c2daf045e65d7028b178c7a5b6d5b1786f86 Mon Sep 17 00:00:00 2001 From: 0AwsD0 <64651813+0AwsD0@users.noreply.github.com> Date: Sun, 5 May 2024 23:37:25 +0200 Subject: [PATCH] advanced_download() Reday! -> not tested thoroughly | but seems to work just fine --- download.py | 216 +++++++++++++++++++++++++++++++++++++++++++++------- main.py | 153 +++++++++++++++++++++++-------------- test-1.py | 128 +++++++++++++++++++++++++++++++ test2.py | 207 +++++++++++++++++++++++++++++++++++++++++++++++++ todo.txt | 8 ++ 5 files changed, 626 insertions(+), 86 deletions(-) create mode 100644 test-1.py create mode 100644 test2.py create mode 100644 todo.txt diff --git a/download.py b/download.py index b694076..e74ab8b 100644 --- a/download.py +++ b/download.py @@ -1,23 +1,34 @@ import time from selenium import webdriver from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import Select + #BTW selenium 420 ~blaze it XD def download(**data): print("Download function invoked with arguments: ", data) #below code checks if the basic option is selected - if yes -> the universal function will be invoked | if no -> the advanced functions will be invoked - tailored to the data that is for set game type - try: - if data["mode"] == "basic": + if data["mode"] == "basic": + try: basic_download(data["url"], data["name"], data["tags"]) - else: - advanced_download(data) - except Exception: - print("ERROR - download function couldn't be invoked. Is website down?") - print("Exiting in 5 seconds.") - time.sleep(5) - exit(1) - + except: + print("basic_download() - failed") + print("Is website down?") + print("Did you input proper values?") + print("Exiting in 5 seconds.") + time.sleep(5) + exit(1) + else: + try: + advanced_download(**data) + except: + print("advanced_download() - failed") + print("Is website down?") + print("Did you input proper values?") + print("Exiting in 5 seconds.") + time.sleep(5) + exit(1) def basic_download(url, name, tags): @@ -56,6 +67,12 @@ def basic_download(url, name, tags): #base url - the url2 is for adding '&page='+i and than reseting it back to normal before adding next &page url = driver.current_url + except Exception: + print("Exception in basic_download() before loop: " + Exception) + print("Exiting in 5 seconds.") + time.sleep(5) + driver.quit() + exit(1) while (flag == 1): try: @@ -111,30 +128,171 @@ def basic_download(url, name, tags): i2 = 1 i += 1 except Exception: - print("The download failed. "+Exception) + print("The download failed. //loop "+Exception) print("Exiting in 5 seconds.") time.sleep(5) driver.quit() exit(1) - except Exception: - print("Exception in basic_download(): "+Exception) - print("Exiting in 5 seconds.") - time.sleep(5) - driver.quit() - exit(1) -def advanced_download(data): - print("Advanced download function invoked") - print("DATA: "+data) - #KK download(game = game, name = name, tags = tags, gender = gender, personality = personality, game_type = game_type, modded_content = modded_content, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) - #AA2 download(game = game, name = name, tags = tags, gender = gender, personality = personality, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) * - #HS download(game = game, name = name, tags = tags, gender = gender, personality = personality, game_type = game_type, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) - #PH download(game = game, name = name, tags = tags, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) - #AI_HS2 download(game = game, name = name, tags = tags, gender = gender, personality = personality, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) * - #COM3D2 download(game = game, name = name, tags = tags, preset_type = preset_type, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) - #SH download(game = game, name = name, tags = tags, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) - #HC download(game = game, name = name, tags = tags, gender = gender, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) - #AA2_&_AI_HS2 +#I tried to make below shorter since the download LOOP is same as in basic download, but the driver must be initialized in same method, so I can't do it without spawning additional unnecessary browsers +#But in other end it's easier to deal with code that is simpler, even if there is more of it. ~Terry would approve +def advanced_download(**data): + print("Advanced download function invoked.") + print("DATA: ", data) + ''' + ALL POSIBLE DATA: + game + name + tags + preset_type + gender + personality + game_type + modded_content + order_by + show_hidden + show_only_featured + ''' + #I need to let user config wait time and provide some values or idk explain it in documentation and readme.md + #OR + #I may try using watchdog or directory scan to check if file exists -> the card and waiting until it does so there is no need for download interval - it downloads only if previous card is downloaded + print("WARNING: Some cards weigh a lot, even over 25MB - if your intewrnet is slow CHANGE WAIT TIME between card downloads to even 10 seconds!") + + url = data["url"] + name = data["name"] + tags = data["tags"] + + show_hidden = data["show_hidden"] + show_only_featured = data["show_only_featured"] + order_by = data["order_by"] + + #selenium code below + + options = webdriver.FirefoxOptions() + #options.add_argument("-headless") + #driver = webdriver.Firefox(options=options) + driver = webdriver.Firefox() + driver.get(url) + + # I know I can just make up the link to the website since it's uses GET method like "https://db.bepis.moe/koikatsu?name=aaaa&tag=bbbb" but I want to try use the way below + name_input = driver.find_element(By.ID, "name") + name_input.send_keys(name) + tag_input = driver.find_element(By.ID, "tag") + tag_input.send_keys(tags) + + #below mess to detect if "varible" (key) exists, if yes -> create the varible -> than use it to fill the form field + try: + preset_type = data["preset_type"] + preset_type_input = Select(driver.find_element(By.ID, "type")) + if (preset_type != ""): + preset_type_input.select_by_value(preset_type) + except: + print("preset_type not found in datased - skipping") + + try: + gender = data["gender"] + gender_input = Select(driver.find_element(By.ID, "gender")) + if (gender != ""): + gender_input.select_by_value(gender) + else:#for test + print("gender > empty")#for test + except: + print("gender not found in datased - skipping") + + try: + personality = data["personality"] + personality_input = Select(driver.find_element(By.ID, "personality")) + if (personality != ""): + personality_input.select_by_value(personality) + except: + print("personality not found in datased - skipping") + + try: + game_type = data["game_type"] + game_type_input = Select(driver.find_element(By.ID, "type")) + if (game_type != ""): + game_type_input.select_by_value(game_type) + except: + print("game_type not found in datased - skipping") + + try: + modded_content = data["modded_content"] + except: + print("modded_content not found in datased - skipping") + + #submit whole form + tag_input.submit() + + print("Waiting 5 seconds for page to load...") + time.sleep(5) + + #just set the loop to be true until the "Next" button is "disabled" than flip the flag to exit loop // if Next button DISABLED flag = 0 + i = 2 + i2 = 1 + flag = 1 + + #base url - the url2 is for adding '&page='+i and than reseting it back to normal before adding next &page + url = driver.current_url + + while (flag == 1): + try: + try: + while (i2 <= 24): + print(f"Downloading card number: {i2}") + download_selector = "document.querySelector('#inner-card-body > div:nth-child(" + str(i2) + ") > div > div > a.btn.btn-primary.btn-sm').click();" + time.sleep(4) + driver.execute_script(download_selector) + i2 += 1 + except Exception: + print("The download FINISHED!") + print("There were less than 24 cards on last page.") + print(">>OR There is slight chance, that website got down.") + # flag == 0 + go back to main() // or leave like that to exit program + print("Exiting in 5 seconds.") + time.sleep(5) + driver.quit() + exit(0) + next_button_script = """ + xpath = "//a[contains(text(),'Next')]"; + var matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; + parentDiv = matchingElement.parentNode; + if(parentDiv.classList.contains('disabled') == true){ + var state = "Disabled"; + return state; + } + else{ + var state = "Enabled"; + return state; + } + """ + print("Getting 'Next' button state...") + button_state = driver.execute_script(next_button_script) + #sleep for script and mainly for last card/cards to download + time.sleep(5) + print("Button state = "+button_state) + if(button_state == "Disabled"): + print("Download FINISHED!") + # flag == 0 + go back to main() // or leave like that to exit program + print("-------------------") + print("Exiting in 5 seconds.") + driver.quit() + time.sleep(5) + exit(0) + print("Getting url...") + url2 = url + print("Got url - adding page number...") + url2 += "&page=" + str(i) + print("Waiting 5 seconds for page to load...") + driver.get(url2) + time.sleep(5) + i2 = 1 + i += 1 + except Exception: + print("The download failed. ", Exception) + print("Exiting in 5 seconds.") + time.sleep(5) + driver.quit() + exit(1) def main(): print("download.py") diff --git a/main.py b/main.py index efdcd3a..0210a5f 100644 --- a/main.py +++ b/main.py @@ -22,207 +22,246 @@ def menu(): print("If you wish to enter only name and/or tags press 1 or ENTER (or anything else really). For advance download press 2.") selected = input() if selected == "2": - KK(game, url) + mode = "advanced" + KK(game, url, mode) else: - basic(game, url) + mode = "basic" + basic(game, url, mode) elif selected == "2": game = "AA2" url = "https://db.bepis.moe/aa2" print("If you wish to enter only name and/or tags press 1 or ENTER (or anything else really). For advance download press 2.") selected = input() if selected == "2": - AA2_and_AI_HS2(game, url) + mode = "advanced" + AA2_and_AI_HS2(game, url, mode) else: - basic(game, url) + mode = "basic" + basic(game, url, mode) elif selected == "3": game = "HS" url = "https://db.bepis.moe/honeyselect" print("If you wish to enter only name and/or tags press 1 or ENTER (or anything else really). For advance download press 2.") selected = input() if selected == "2": - HS(game, url) + mode = "advanced" + HS(game, url, mode) else: - basic(game, url) + mode = "basic" + basic(game, url, mode) elif selected == "4": game = "PH" url = "https://db.bepis.moe/playhome" print("If you wish to enter only name and/or tags press 1 or ENTER (or anything else really). For advance download press 2.") selected = input() if selected == "2": - PH(game, url) + mode = "advanced" + PH(game, url, mode) else: - basic(game, url) + mode = "basic" + basic(game, url, mode) elif selected == "5": game = "AI_HS2" url = "https://db.bepis.moe/aishoujo" print("If you wish to enter only name and/or tags press 1 or ENTER (or anything else really). For advance download press 2.") selected = input() if selected == "2": - AA2_and_AI_HS2(game, url) + mode = "advanced" + AA2_and_AI_HS2(game, url, mode) else: - basic(game, url) + mode = "basic" + basic(game, url, mode) elif selected == "6": game = "COM3D2" url = "https://db.bepis.moe/com3d2" print("If you wish to enter only name and/or tags press 1 or ENTER (or anything else really). For advance download press 2.") selected = input() if selected == "2": - COM3D2(game, url) + mode = "advanced" + COM3D2(game, url, mode) else: - basic(game, url) + mode = "basic" + basic(game, url, mode) elif selected == "7": game = "SH" url = "https://db.bepis.moe/summerheat" print("If you wish to enter only name and/or tags press 1 or ENTER (or anything else really). For advance download press 2.") selected = input() if selected == "2": - SH(game, url) + mode = "advanced" + SH(game, url, mode) else: - basic(game, url) + mode = "basic" + basic(game, url, mode) elif selected == "8": game = "HC" url = "https://db.bepis.moe/honeycome" print("If you wish to enter only name and/or tags press 1 or ENTER (or anything else really). For advance download press 2.") selected = input() if selected == "2": - HC(game, url) + mode = "advanced" + HC(game, url, mode) else: - basic(game, url) + mode = "basic" + basic(game, url, mode) else: print("Please select one of the correct options (1-6):") main() -def KK(game, url): +def KK(game, url, mode): print("Enter in order (or use config file) the parameters or press enter to set default.") print("Name: (text) = blank") name = input() print("Tags: (text) = blank") tags = input() print("Gender: (text) = Unspecified") + print("Possible Gender: female | male") gender = input() - print("Personality: (text) = Unspecified") + print("Personality: (number) = Unspecified") + print("Possible Personality: 0 = Sexy | 1 = Ojousama | 2 = Snobby | 3 = Kouhai | 4 = Mysterious | 5 = Weirdo | 6 = Yamato Nadeshiko | 7 = Tomboy | 8 = Pure | 9 = Simple | 10 = Delusional | 11 = Motherly | 12 = Big Sisterly | 13 = Gyaru | 14 = Delinquent | 15 = Wild | 16 = Wannabe | 17 = Reluctant | 18 = Jinxed | 19 = Bookish | 20 = Timid | 21 = Typical Schoolgirl | 22 = Trendy | 23 = Otaku | 24 = Yandere | 25 = Lazy | 26 = Quiet | 27 = Stubborn | 28 = Old-Fashioned | 29 = Humble | 30 = Friendly | 31 = Willful | 32 = Honest | 33 = Glamorous | 34 = Returnee | 35 = Slangy | 36 = Sadistic | 37 = Emotionless | 38 = Perfectionist") personality = input() print("Gametype: (text) = Unspecified") + print("Possible Gametype: Base | Steam | Steam 18+ | Emotion Creators | Sunshine") game_type = input() - print("Does bit contain modded content: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Does not contain modded content: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") modded_content = input() - print("Order by: (enter 1 for 'Date Descending' | 2 for 'Date Ascending' | 3 for 'Popularity')") + print("Order by: (text) = Date Descending") + print("You can Order by: popularity | dateasc (Date Ascending)") order_by = input() - print("Show hidden: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show hidden: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_hidden = input() - print("Show only featured: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show only featured: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_only_featured = input() - download(game = game, url = url, name = name, tags = tags, gender = gender, personality = personality, game_type = game_type, modded_content = modded_content, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) + download(mode = mode, game = game, url = url, name = name, tags = tags, gender = gender, personality = personality, game_type = game_type, modded_content = modded_content, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) -def AA2_and_AI_HS2(game, url): +def AA2_and_AI_HS2(game, url, mode): print("Enter in order (or use config file) the parameters or press enter to set default.") print("Name: (text) = blank") name = input() print("Tags: (text) = blank") tags = input() print("Gender: (text) = Unspecified") + if(game == "AA2"): + print("Possible Gender: female | male") + else: + print("Possible Gender: Female | Male | Futanari") gender = input() - print("Personality: (text) = Unspecified") + print("Personality: (number) = Unspecified") + if(game == "AA2"): + print("Possible Personality: 0 = Lively | 1 = Delicate | 2 = Cheerful | 3 = Quiet | 4 = Playful | 5 = Frisky | 6 = Kind | 7 = Joyful | 8 = Ordinary | 9 = Irritated | 10 = Harsh | 11 = Sweet | 12 = Creepy | 13 = Reserved | 14 = Dignified | 15 = Aloof | 16 = Smart | 17 = Genuine | 18 = Mature | 19 = Lazy | 20 = Manly | 21 = Gentle | 22 = Positive | 23 = Otaku | 24 = Savage | 25 = Cadet | 26 = Caring | 27 = Schemer | 28 = Carefree | 29 = Warm | 30 = Cold (Male Aloof) | 31 = AA1 Quiet | 32 = Methodical | 33 = AA1 Empress (HF) | 34 = AA1 Big Sister | 35 = Silent | 36 = AA1 Empress (aa2g) | 37 = AA1 Brave | 38 = AA1 Pure | 40 = Robot | 41 = Sly | 42 = Russian | 43 = Timid | 44 = Whimsical | 45 = Salamanderman | 46 = Callous | 50 = Servent | 51 = OuterSpace | 52 = Apricot | 53 = Wise | 54 = Graceful | 55 = Trendy | 58 = AA1 Ditzy | 59 = AA1 Aloof | 60 = AA1 Affable | 61 = AA1 Calm | 62 = AA1 Tense | 63 = AA1 Rough | 64 = AA1 Sweet | 65 = AA1 Mistress | 66 = AA1 Selfish | 67 = Bekloppt | 68 = AA1 Casual | 69 = Open-eye Joyful | 70 = AA1 Pleasant | 71 = Gynoid (Sweet) | 72 = Open-eye Quiet | 73 = Scholarly | 75 = Cynical | 76 = AA1 Manly | 77 = AA1 Humble | 78 = Succubus (Mature) | 79 = AA1 Violent | 80 = Analytical | 81 = Despair | 82 = Future | 83 = Kuma | 84 = Liar | 85 = Robot (Male) | 90 = Big Brother | 95 = Polite | 96 = Energetic | 97 = Eccentric | 98 = AA1 Cold | 99 = AA1 Soft | 100 = AA1 Eloquent | 101 = AA1 Obscene | 102 = AA1 Faithful | 103 = Professor | 104 = AA1 Handsome | 105 = AA1 Dark | 106 = Twisted | 107 = Cowardly | 108 = Haughty | 110 = Ice | 111 = Hero | 112 = Artsy | 113 = Silent (Male) | 114 = Mute | 115 = Mute+ | 116 = Arrogant | 131 = Bael | 132 = Fumi | 133 = Space Case | 134 = Wild | 135 = Delinquent | 136 = Jinxed | 137 = Chuuni | 138 = Motherly | 139 = Tomboy | 140 = Yandere | 141 = Gyaru | 142 = Bookish | 143 = Archaic | 144 = Enigma | 145 = Kouhai | 146 = Emotionless | 147 = Bashful | 148 = Sadistic | 149 = Geek") + else: + print("Possible Personality: 0 = Emotionless | 1 = Friendly | 2 = Confident | 3 = Selfish | 4 = Lazy | 5 = Positive") personality = input() - print("Order by: (enter 1 for 'Date Descending' | 2 for 'Date Ascending' | 3 for 'Popularity')") + print("Order by: (text) = Date Descending") + print("You can Order by: popularity | dateasc (Date Ascending)") order_by = input() - print("Show hidden: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show hidden: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_hidden = input() - print("Show only featured: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show only featured: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_only_featured = input() - download(game = game, url = url, name = name, tags = tags, gender = gender, personality = personality, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) + download(mode = mode, game = game, url = url, name = name, tags = tags, gender = gender, personality = personality, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) -def HS(game, url): +def HS(game, url, mode): print("Enter in order (or use config file) the parameters or press enter to set default.") print("Name: (text) = blank") name = input() print("Tags: (text) = blank") tags = input() print("Gender: (text) = Unspecified") + print("Possible Gender: female | male") gender = input() - print("Personality: (text) = Unspecified") + print("Personality: (number) = Unspecified") + print("Possible Personality: 0 = Cheerful | 1 = Tsundere | 2 = Gentle | 3 = Withdrawn | 4 = Yandere | 5 = Easygoing | 6 = Strict | 7 = Boyish | 8 = Energetic | 9 = Diligent | 10 = Active | 11 = Sincere | 12 = Bewitching") personality = input() print("Gametype: (text) = Unspecified") + print("Possible Gametype: neo | Classic") game_type = input() - print("Order by: (enter 1 for 'Date Descending' | 2 for 'Date Ascending' | 3 for 'Popularity')") + print("Order by: (text) = Date Descending") + print("You can Order by: popularity | dateasc (Date Ascending)") order_by = input() - print("Show hidden: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show hidden: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_hidden = input() - print("Show only featured: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show only featured: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_only_featured = input() - download(game = game, url = url, name = name, tags = tags, gender = gender, personality = personality, game_type = game_type, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) + download(mode = mode, game = game, url = url, name = name, tags = tags, gender = gender, personality = personality, game_type = game_type, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) -def PH(game, url): +def PH(game, url, mode): print("Enter in order (or use config file) the parameters or press enter to set default.") print("Name: (text) = blank") name = input() print("Tags: (text) = blank") tags = input() - print("Order by: (enter 1 for 'Date Descending' | 2 for 'Date Ascending' | 3 for 'Popularity')") + print("Order by: (text) = Date Descending") + print("You can Order by: popularity | dateasc (Date Ascending)") order_by = input() - print("Show hidden: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show hidden: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_hidden = input() - print("Show only featured: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show only featured: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_only_featured = input() - download(game = game, url = url, name = name, tags = tags, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) + download(mode = mode, game = game, url = url, name = name, tags = tags, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) -def COM3D2(game, url): +def COM3D2(game, url, mode): print("Enter in order (or use config file) the parameters or press enter to set default.") print("Name: (text) = blank") name = input() print("Tags: (text) = blank") tags = input() print("Preset type: (text) = Unspecified") + print("Possible Preset type: outfit | body | all") preset_type = input() - print("Order by: (enter 1 for 'Date Descending' | 2 for 'Date Ascending' | 3 for 'Popularity')") + print("Order by: (text) = Date Descending") order_by = input() - print("Show hidden: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show hidden: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_hidden = input() - print("Show only featured: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show only featured: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_only_featured = input() - download(game = game, url = url, name = name, tags = tags, preset_type = preset_type, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) + download(mode = mode, game = game, url = url, name = name, tags = tags, preset_type = preset_type, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) -def SH(game, url): +def SH(game, url, mode): print("Enter in order (or use config file) the parameters or press enter to set default.") print("Name: (text) = blank") name = input() print("Tags: (text) = blank") tags = input() - print("Order by: (enter 1 for 'Date Descending' | 2 for 'Date Ascending' | 3 for 'Popularity')") + print("Order by: (text) = Date Descending") + print("You can Order by: popularity | dateasc (Date Ascending)") order_by = input() - print("Show hidden: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show hidden: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_hidden = input() - print("Show only featured: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show only featured: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_only_featured = input() - download(game = game, url = url, name = name, tags = tags, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) + download(mode = mode, game = game, url = url, name = name, tags = tags, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) -def HC(game, url): +def HC(game, url, mode): print("Enter in order (or use config file) the parameters or press enter to set default.") print("Name: (text) = blank") name = input() print("Tags: (text) = blank") tags = input() print("Gender: (text) = Unspecified") + print("Possible Gender: Female | Male | Futanari") gender = input() - print("Order by: (enter 1 for 'Date Descending' | 2 for 'Date Ascending' | 3 for 'Popularity')") + print("Order by: (text) = Date Descending") + print("You can Order by: popularity | dateasc (Date Ascending)") order_by = input() - print("Show hidden: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show hidden: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_hidden = input() - print("Show only featured: (checkbox - enter '1' to check - 0 or nothig to leave unchecked )") + print("Show only featured: (checkbox) - enter '1' to check - 0 or nothig to leave unchecked ") show_only_featured = input() - download(game = game, url = url, name = name, tags = tags, gender = gender, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) + download(mode = mode, game = game, url = url, name = name, tags = tags, gender = gender, order_by = order_by, show_hidden = show_hidden, show_only_featured = show_only_featured) -def basic(game, url): +def basic(game, url, mode): + mode = mode print("Enter in order (or use config file) the parameters or press enter to set default.") print("Name: (text) = blank") name = input() print("Tags: (text) = blank") tags = input() - download(mode = "basic", game = game, url = url, name=name, tags=tags) + download(mode = mode, game = game, url = url, name = name, tags = tags) def main(): menu() diff --git a/test-1.py b/test-1.py new file mode 100644 index 0000000..740a88e --- /dev/null +++ b/test-1.py @@ -0,0 +1,128 @@ +### THIS FILE EXISTS SO I CAN TEST THINGS -> Welcome at Nuclear Test Site NO. 1 +import time +from selenium import webdriver +from selenium.webdriver.common.by import By + +def main(): + print("test.py - Wellcome in test script!") + driver = webdriver.Firefox() + driver.get("https://db.bepis.moe/koikatsu") + name_input = driver.find_element(By.ID, "name") + name_input.send_keys("Ayaka") + tag_input = driver.find_element(By.ID, "tag") + tag_input.send_keys("") + tag_input.submit() + + time.sleep(5) + + #JS to check the Next button if it's parent dont have "disabled" attrib, than clikc if it does - download finished -> Raise flag - exit loop. + #it's arguably better solution than seeaking for nth-childs (depends on number of pages with cards) in the page navigation + + i = 2 + flag = 1 + url = driver.current_url + + while (flag == 1): + try: + while (i2 <= 24): + print(f"Downloading card number: {i2}") + download_selector = "document.querySelector('#inner-card-body > div:nth-child(" + str( + i2) + ") > div > div > a.btn.btn-primary.btn-sm').click();"; # selenium don't like that XD + time.sleep(3) + driver.execute_script(download_selector) + i2 += 1 + # JS to check the Next button if it's parent dont have "disabled" attrib, than click it and continue, if it does - download finished -> Raise flag - exit loop. exit(0) + ''' + JS CODE BELOW - now make it into selenium XD + 02:40:20.388 xpath = "//a[contains(text(),'Next')]"; + 02:40:20.405 "//a[contains(text(),'Next')]" + 02:40:34.097 var matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; + 02:40:34.114 undefined + 02:42:05.285 matchingElement + 02:42:05.304 + + 02:42:39.367 parentDiv = matchingElement.parentNode; + 02:42:39.389 +
  • + 02:42:43.478 parentDiv + 02:42:43.499 +
  • + ''' + + #if(parent div to (a - text=Next) have atrib 'Disabled'): + # print("Download finished! Exiting program in 5 seconds...") + # exit(0) + + print("Getting url...") + url2 = url + print("Got url - adding page number...") + url2 += "&page=" + str(i) + print("I got url - waiting 5 seconds for page to load...") + driver.get(url2) + time.sleep(5) + i2 = 1 + i += 1 + except Exception: + print("The download failed! Exiting in 5 seconds.") + time.sleep(5) + exit(1) + + +#Code below works + ''' + + i = 2 + i2 = 1 + + #I may try using watchdog or directory scan to check if file exists -> the card and waiting until it does so there is no need for download interval - it downloads only if previous card is downloaded + + + + #The code below don't check the next button but instead directly edits url + time.sleep(3) + #IT JUST WORKS - need to add functionality that checks the number of pages it will add 16x details // well the first thought was propably better, so I + while(i < 10): + try: + while(i2<=24): + print(f"Downloading card number: {i2}") + download_selector = "document.querySelector('#inner-card-body > div:nth-child("+str(i2)+") > div > div > a.btn.btn-primary.btn-sm').click();"; # selenium don't like that XD + time.sleep(3) + driver.execute_script(download_selector) + i2 += 1 + print("Getting url...") + url = driver.current_url + print("Got url - adding page number...") + #if statment checking if the '&page=' is present and adding if if int's not or cutting the number and adding new one + url += "&page=" + str(i) + print("I got url - waiting 5 seconds for page to load...") + driver.get(url) + time.sleep(5) + i2 = 1 + i += 1 + except Exception: + print("The download failed! Exiting in 5 seconds.") + time.sleep(5) + exit(1) + + ''' + + # the detection for the number of pages in JS - checking the number inside DIV + Try Catch (Except) for downloading images, since website can have less than (max of) 24 cards + ''' + i2 = 1 + + + #This works + download_selector = "document.querySelector('#inner-card-body > div:nth-child("+str(i2)+") > div > div > a.btn.btn-primary.btn-sm').click();";#selenium don't like that XD + time.sleep(3) + driver.execute_script(download_selector) + + #This works TOO + download_button = driver.find_element(By.CSS_SELECTOR, "#inner-card-body > div:nth-child("+str(i2)+") > div > div > a.btn.btn-primary.btn-sm") # + download_button.click() + ''' + +if __name__ == "__main__": + main() + + + diff --git a/test2.py b/test2.py new file mode 100644 index 0000000..4d5aed0 --- /dev/null +++ b/test2.py @@ -0,0 +1,207 @@ +import time +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import Select + +def advanced_download(**data): + print("Advanced download function invoked.") + print("DATA: ", data) + ''' + ALL POSIBLE DATA: + game + name + tags + preset_type + gender + personality + game_type + modded_content + order_by + show_hidden + show_only_featured + ''' + #I need to let user config wait time and provide some values or idk explain it in documentation and readme.md + #OR + #I may try using watchdog or directory scan to check if file exists -> the card and waiting until it does so there is no need for download interval - it downloads only if previous card is downloaded + print("WARNING: Some cards weigh a lot, even over 25MB - if your intewrnet is slow CHANGE WAIT TIME between card downloads to even 10 seconds!") + ''' + try: + ''' + url = data["url"] + name = data["name"] + tags = data["tags"] + + show_hidden = data["show_hidden"] + show_only_featured = data["show_only_featured"] + order_by = data["order_by"] + + #selenium code below + + options = webdriver.FirefoxOptions() + #options.add_argument("-headless") + #driver = webdriver.Firefox(options=options) + driver = webdriver.Firefox() + driver.get(url) + + # I know I can just make up the link to the website since it's uses GET method like "https://db.bepis.moe/koikatsu?name=aaaa&tag=bbbb" but I want to try use the way below + name_input = driver.find_element(By.ID, "name") + name_input.send_keys(name) + tag_input = driver.find_element(By.ID, "tag") + tag_input.send_keys(tags) + + #below mess to detect if "varible" (key) exists, if yes -> create the varible -> than use it to fill the form field + try: + preset_type = data["preset_type"] + preset_type_input = Select(driver.find_element(By.ID, "type")) + if (preset_type != ""): + preset_type_input.select_by_value(preset_type) + except: + print("preset_type not found in datased - skipping") + + try: + gender = data["gender"] + gender_input = Select(driver.find_element(By.ID, "gender")) + if (gender != ""): + gender_input.select_by_value(gender) + else:#for test + print("gender > empty")#for test + except: + print("gender not found in datased - skipping") + + try: + personality = data["personality"] + personality_input = Select(driver.find_element(By.ID, "personality")) + if (personality != ""): + personality_input.select_by_value(personality) + except: + print("personality not found in datased - skipping") + + try: + game_type = data["game_type"] + game_type_input = Select(driver.find_element(By.ID, "type")) + if (game_type != ""): + game_type_input.select_by_value(game_type) + except: + print("game_type not found in datased - skipping") + + try: + modded_content = data["modded_content"] + except: + print("modded_content not found in datased - skipping") + + #submit whole form + tag_input.submit() + + print("Waiting 5 seconds for page to load...") + time.sleep(5) + + #just set the loop to be true until the "Next" button is "disabled" than flip the flag to exit loop // if Next button DISABLED flag = 0 + i = 2 + i2 = 1 + flag = 1 + + #base url - the url2 is for adding '&page='+i and than reseting it back to normal before adding next &page + url = driver.current_url + + while (flag == 1): + try: + try: + while (i2 <= 24): + print(f"Downloading card number: {i2}") + download_selector = "document.querySelector('#inner-card-body > div:nth-child(" + str(i2) + ") > div > div > a.btn.btn-primary.btn-sm').click();" + time.sleep(4) + driver.execute_script(download_selector) + i2 += 1 + except Exception: + print("The download FINISHED!") + print("There were less than 24 cards on last page.") + print(">>OR There is slight chance, that website got down.") + # flag == 0 + go back to main() // or leave like that to exit program + print("Exiting in 5 seconds.") + time.sleep(5) + driver.quit() + exit(0) + next_button_script = """ + xpath = "//a[contains(text(),'Next')]"; + var matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; + parentDiv = matchingElement.parentNode; + if(parentDiv.classList.contains('disabled') == true){ + var state = "Disabled"; + return state; + } + else{ + var state = "Enabled"; + return state; + } + """ + print("Getting 'Next' button state...") + button_state = driver.execute_script(next_button_script) + #sleep for script and mainly for last card/cards to download + time.sleep(5) + print("Button state = "+button_state) + if(button_state == "Disabled"): + print("Download FINISHED!") + # flag == 0 + go back to main() // or leave like that to exit program + print("-------------------") + print("Exiting in 5 seconds.") + driver.quit() + time.sleep(5) + exit(0) + print("Getting url...") + url2 = url + print("Got url - adding page number...") + url2 += "&page=" + str(i) + print("Waiting 5 seconds for page to load...") + driver.get(url2) + time.sleep(5) + i2 = 1 + i += 1 + except Exception: + print("The download failed. ", Exception) + print("Exiting in 5 seconds.") + time.sleep(5) + driver.quit() + exit(1) + ''' + except Exception: + print("Exception in advanced_download(): ", Exception) + print("Exiting in 5 seconds.") + time.sleep(5) + driver.quit() + exit(1) + +''' +def main(): + print("test2.py") + + mode = "advanced" + game = "KK" + url = "https://db.bepis.moe/koikatsu" + name = "Ayaka" + tags = "Genshin_Impact" + gender = "" + personality = "1" + order_by = "" #<---- "" or 0 + show_hidden = "1" + show_only_featured = "" + advanced_download(mode= mode, game=game, url=url, name=name, tags=tags, gender=gender, personality=personality, order_by=order_by, show_hidden=show_hidden, show_only_featured=show_only_featured) + + #The Below Works TOO +''' + mode = "advanced" + game = "COM3D2" + url = "https://db.bepis.moe/com3d2" + name = "" + tags = "" + preset_type = "body" + order_by = "" # <---- "" or 0 + show_hidden = "1" + show_only_featured = "" + advanced_download(mode= mode, game=game, url=url, name=name, tags=tags,preset_type = preset_type, order_by=order_by, show_hidden=show_hidden, show_only_featured=show_only_featured) + ''' +if __name__ == "__main__": + main() + +#KEKW - that tests (.py) +#Do you read a code comments? If yes, then good for you! +#Should't I assert it?... get it? assert? XDDD \ No newline at end of file diff --git a/todo.txt b/todo.txt new file mode 100644 index 0000000..916f823 --- /dev/null +++ b/todo.txt @@ -0,0 +1,8 @@ +Are you certain game enjoyer? Do you fell annoyed selecting game (same one) every time on startup of the program? +I'll have solution for you! +The new function I planned will check if config file (txt?) exists to automatically choose game on startup! +It will be able to select the download mode too! +The plan is to even add auto download - you create file with all parameters and don't need to type it into console! +The program will do it for you! + +~Thats the plan will see when or if I'm gonna implement that