-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
171 lines (138 loc) · 5.13 KB
/
main.py
File metadata and controls
171 lines (138 loc) · 5.13 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import os
import time
import _thread
from tkinter import *
from tkinter.ttk import Progressbar
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.chrome.options import Options
# Global variables
links = []
path = ''
main_path = "D:\\TeraBoxDownload\\animes\\"
name = ''
progress = ''
list_results = []
# threads
def search_th(text_search):
clear_list()
title["text"] = "Procurando... Por favor aguarde."
_thread.start_new_thread(search, (text_search,))
def open_th(link):
title["text"] = "Capturando links... Por favor aguarde."
clear_list()
_thread.start_new_thread(capture_links, (link,))
def clear_list():
global list_results
for item in list_results:
item.destroy()
list_results = []
def capture_links(link):
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--log-level=1')
browser = webdriver.Chrome(options=chrome_options)
browser.get(link)
global name
name = browser.find_element(By.ID, 'page-title').text
create_directory()
downloader = "zippyshare"
WebDriverWait(browser, 20).until(
ec.presence_of_element_located((By.XPATH, '//a[contains(@href, "%s")]' % downloader))).click()
try:
WebDriverWait(browser, 20).until(
ec.visibility_of_element_located((By.CLASS_NAME, 'list'))).click()
lista = WebDriverWait(browser, 20).until(
ec.visibility_of_element_located((By.TAG_NAME, 'textarea'))).get_attribute('value')
global links
links = lista.split("\n")
except Exception as ex:
list_elem = browser.find_element(By.CLASS_NAME, 'zippyshare')
links_elem = list_elem.find_elements(By.TAG_NAME, 'a')
links = []
for elem in links_elem:
lk = elem.get_attribute('href')
if lk != 'http://tasks.anbient.com/' and lk is not None:
links.append(elem.get_attribute('href'))
global progress
progress = Progressbar(
window,
orient='horizontal',
mode='determinate',
length=100
)
progress.grid(column=0, row=4)
progress.pack_forget()
browser.close()
title["text"] = "Iniciando download... Por favor aguarde."
_thread.start_new_thread(execute, ())
def create_directory():
global name
global path
name = name.replace(":", " - ").title()
path = main_path + name
if not os.path.exists(path):
os.makedirs(path)
def check_download(file_name):
while not os.path.exists(path + '\\' + file_name):
time.sleep(5)
def execute():
count = 0
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--log-level=1')
prefs = {'download.default_directory': path}
chrome_options.add_experimental_option('prefs', prefs)
browser = webdriver.Chrome(options=chrome_options)
while count < (len(links) - 1):
progress['value'] = 100 * count / (len(links) - 1)
browser.get(links[count])
try:
download = WebDriverWait(browser, 20).until(
ec.visibility_of_element_located((By.ID, 'dlbutton'))).get_attribute('href')
browser.get(download)
file = browser.find_elements(By.TAG_NAME, 'font')
file_name = file[3].get_attribute('innerHTML')
check_download(file_name)
count = count + 1
except:
title["text"] = "O arquivo solicitado esta com link quebrado! Seguindo para o proximo arquivo"
time.sleep(5)
title["text"] = "Iniciando download... Por favor aguarde."
count = count + 1
browser.close()
progress['value'] = 100
title["text"] = "Download Concluido com sucesso!"
progress.destroy()
def search(text_search):
global list_results
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--log-level=1')
browser = webdriver.Chrome(options=chrome_options)
browser.get('https://www.anbient.com/search?search_api_views_fulltext=' + text_search)
result = browser.find_elements(By.XPATH, "//a[@rel='bookmark']")
count = 1
window.update()
title["text"] = "Encontramos estes animes, clique no que deseja baixar."
for value in result:
window.update()
list_results.append(Label(window, text=value.text, fg="blue", cursor="hand2"))
list_results[count - 1].grid(column=0, row=count + 3)
href_value = value.get_attribute('href')
list_results[count - 1].bind("<Button-1>", lambda e, url=href_value: open_th(url))
count = count + 1
browser.close()
window = Tk()
window.title('Anbient Bot Donwloader')
text = Label(window, text="Pesquise o anime no campo abaixo")
text.grid(column=0, row=0)
input = Entry(window, width=50)
input.grid(column=0, row=1)
button = Button(window, text="Buscar", command=lambda: search_th(input.get()))
button.grid(column=0, row=2)
title = Label(window, text="")
title.grid(column=0, row=3)
window.mainloop()