-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
138 lines (86 loc) · 3.94 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import os
import time
ublock_extension_path = os.path.abspath('./uBlock0.chromium')
idm_extension_path = r"C:\Users\USER\AppData\Local\Google\Chrome\User Data\Default\Extensions\ngpampappnmepgilojfohadhhmbhlaek\6.42.11_0"
service = Service(executable_path="chromedriver.exe")
options = webdriver.ChromeOptions()
options.add_argument(f'--load-extension={idm_extension_path},{ublock_extension_path}')
driver = webdriver.Chrome(service=service, options=options)
url = 'https://animepahe.ru'
driver.get(url)
try:
search_bar = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//input[contains(@class, 'input-search')]"))
)
search_bar.click()
search = input('What anime are you looking for today ?\n')
search_bar.send_keys(search)
anime_search = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[contains(@data-index, '0')]"))
)
anime_search.click()
new_episode = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//a[contains(text(), 'Watch')]"))
)
driver.execute_script("arguments[0].scrollIntoView(true);", new_episode)
new_episode_number = new_episode.text.replace('Watch - ', '').replace('Online', '')
episode_numbers = input(f'Latest episode is {new_episode_number} \n What episodes (e.g 1,2,3,4,5) ?\n').split(',')
quality = input('What quality ? (e.g 360, 720, 1080)\n')
for episode_number in episode_numbers:
episode_number = episode_number.strip()
play_button_xpath = f"//a[contains(text(), 'Watch - {episode_number} Online')]"
# look through all the pages for the episodes
while True:
try:
play_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, play_button_xpath)))
break
except:
next_page = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(@class, 'page-link next-page')]")))
driver.execute_script("arguments[0].scrollIntoView(true);", next_page)
time.sleep(1)
next_page.click()
time.sleep(1)
driver.execute_script("arguments[0].scrollIntoView(true);", play_button)
time.sleep(3)
play_button.click()
download_menu = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, 'downloadMenu'))
)
download_menu.click()
download_item = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, f"//a[contains(text(),'{quality}p')]"))
)
download_item.click()
anime_url = download_item.get_attribute('href')
driver.get(anime_url)
continue_btn = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//a[contains(@class, 'btn-secondary btn-block redirect')]"))
)
time.sleep(10)
continue_btn.click()
download_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//button[@type='submit' and contains(@class, 'button is-uppercase is-success is-fullwidth')]"))
)
time.sleep(3)
download_btn.click()
print(f'Downloading episode {episode_number}')
# i had to use 3 drive.back() to redirect back to the anime episodes page
time.sleep(2)
driver.back()
time.sleep(2)
driver.back()
time.sleep(2)
driver.back()
time.sleep(2)
print('All download started!')
except TimeoutError:
print('Time out error')
except Exception as e:
print(f"An error occurred: {e}")
finally:
driver.quit()