-
Notifications
You must be signed in to change notification settings - Fork 15
/
start_app.py
195 lines (164 loc) · 8.19 KB
/
start_app.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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
"""
"""
# ------------------------------------------------------- #
# imports
# ------------------------------------------------------- #
from zk_tools.logging_handle import logger
import os
import time
import sys
from logic.language import LanguageError
from logic.search_for_links import redirect
from logic.search_for_links import find_cache_url
from logic.collect_all_seasons_and_episods import get_season
from logic.collect_all_seasons_and_episods import get_episodes
from logic.downloader import create_new_download_thread
from logic.captcha import open_captcha_window
# ------------------------------------------------------- #
# definitions
# ------------------------------------------------------- #
APP_VERSION = "v01-07-00"
MODULE_LOGGER_HEAD = "start_app -> "
# ------------------------------------------------------- #
# global variables
# ------------------------------------------------------- #
name = "Name-Goes-Here"
type = "anime" # choose 'serie' or 'anime'
language = "Deutsch"
site_url = {"serie": "https://s.to", # maybe you need another dns to be able to use this site
"anime": "https://aniworld.to"}
url = "{}/{}/stream/{}/".format(site_url[type], type, name)
season_override = 0 # 0 = no override. 1 = season 1. etc...
ddos_protection_calc = 4
ddos_wait_timer = 60
episode_interval_timer = ddos_wait_timer / ddos_protection_calc
ddos_start_value = 0
output_path = name
# ------------------------------------------------------- #
# functions
# ------------------------------------------------------- #
def setup_logging(debug_level):
logger.set_logging_level(debug_level)
logger.set_cmd_line_logging_output()
logger.add_global_except_hook()
def setup_arguments():
if len(sys.argv) < 4:
logger.info(MODULE_LOGGER_HEAD + "Usage: start_app.py <TYPE> <NAME> <LANGUAGE> [Season_overrider]")
sys.exit()
global type
type = sys.argv[1]
global name
name = sys.argv[2]
global language
language = sys.argv[3]
global url
url = "{}/{}/stream/{}/".format(site_url[type], type, name)
global output_path
output_path = name
if len(sys.argv) == 5:
global season_override
season_override = int(sys.argv[4])
logger.debug(MODULE_LOGGER_HEAD + "Season Override detected. Val: {}".format(season_override))
else:
logger.debug(MODULE_LOGGER_HEAD + "No Season Override.")
def button_failsave(site_url, internal_link, language):
provider = "Vidoza"
link_to_redirect = redirect(site_url, internal_link, language, provider)
logger.debug(MODULE_LOGGER_HEAD + "Link to redirect is: " + link_to_redirect)
internal_captcha_link = open_captcha_window(link_to_redirect)
logger.debug(MODULE_LOGGER_HEAD + "Return is: " + internal_captcha_link)
if internal_captcha_link:
return internal_captcha_link, provider
else:
provider = "VOE"
link_to_redirect = redirect(site_url, internal_link, language, provider)
logger.debug(MODULE_LOGGER_HEAD + "Link to redirect is: " + link_to_redirect)
internal_captcha_link = open_captcha_window(link_to_redirect)
logger.debug(MODULE_LOGGER_HEAD + "Return is: " + internal_captcha_link)
return internal_captcha_link, provider
def already_downloaded(file_name):
if os.path.exists(file_name) and os.path.getsize(file_name) > 0:
logger.info(MODULE_LOGGER_HEAD + "Episode {} already downloaded.".format(file_name))
return True
logger.debug(MODULE_LOGGER_HEAD + "File not downloaded. Downloading: {}".format(file_name))
return False
# ------------------------------------------------------- #
# classes
# ------------------------------------------------------- #
# ------------------------------------------------------- #
# main
# ------------------------------------------------------- #
if __name__ == "__main__":
setup_logging("info")
if name == "Name-Goes-Here":
setup_arguments()
try:
logger.info("------------- AnimeSerienScraper {} started ------------".format(APP_VERSION))
read_check = os.access('DO_NOT_DELETE.txt', os.R_OK)
if read_check:
logger.debug(MODULE_LOGGER_HEAD + "We have Read Permission")
else:
logger.error(MODULE_LOGGER_HEAD + "No Read Permission. Please check if you own the Folder and/or have "
"permissions to read.")
exit()
write_check = os.access('DO_NOT_DELETE.txt', os.W_OK)
if write_check:
logger.debug(MODULE_LOGGER_HEAD + "We have Write Permission")
else:
logger.error(MODULE_LOGGER_HEAD + "No Write Permission. Please check if you own the Folder and/or have "
"permissions to write.")
exit()
if os.path.exists(output_path):
logger.debug(MODULE_LOGGER_HEAD + "Output Path exists.")
else:
logger.info(MODULE_LOGGER_HEAD + "Output path does not exist. Creating now...")
os.mkdir(output_path)
if name == "Name-Goes-Here":
logger.error(MODULE_LOGGER_HEAD + "Name is Default. Please reade readme before starting.")
exit()
if season_override == 0:
logger.info(MODULE_LOGGER_HEAD + "No Season override detected.")
seasons = get_season(url)
logger.info(MODULE_LOGGER_HEAD + "We have this many seasons: {}".format(seasons))
else:
logger.info(MODULE_LOGGER_HEAD + "Season Override detected. Override set to: {}".format(season_override))
seasons = 1
for season in range(int(seasons)):
season = season + 1 if season_override == 0 else season_override
season_path = f"{output_path}/Season {season:02}"
os.makedirs(season_path, exist_ok=True)
episode_count = get_episodes(url, season)
logger.info(MODULE_LOGGER_HEAD + "Season {} has {} Episodes.".format(season, episode_count))
for episode in range(int(episode_count)):
episode = episode + 1
file_name = "{}/{} - s{:02}e{:02} - {}.mp4".format(season_path, name, season, episode, language)
logger.info(MODULE_LOGGER_HEAD + "File name will be: " + file_name)
if not already_downloaded(file_name):
link = url + "staffel-{}/episode-{}".format(season, episode)
try:
captcha_link, provider = button_failsave(site_url[type], link, language)
except LanguageError:
continue
if ddos_start_value < ddos_protection_calc:
logger.debug(MODULE_LOGGER_HEAD + "Entered DDOS var check and starting new downloader.")
ddos_start_value += 1
else:
logger.info(MODULE_LOGGER_HEAD + "Started {} Downloads. Waiting for {} Seconds to not trigger DDOS"
"Protection.".format(ddos_protection_calc, ddos_wait_timer))
time.sleep(ddos_wait_timer)
ddos_start_value = 1
cache_url = find_cache_url(captcha_link, provider)
logger.debug(MODULE_LOGGER_HEAD + "{} Cache URL is: ".format(provider) + cache_url)
create_new_download_thread(cache_url, file_name)
time.sleep(episode_interval_timer)
# except Exception as e:
# logger.error(MODULE_LOGGER_HEAD + "----------")
# logger.error(MODULE_LOGGER_HEAD + f"Exception: {e}")
# logger.error(MODULE_LOGGER_HEAD + "----------")
except KeyboardInterrupt:
logger.info("-----------------------------------------------------------")
logger.info(" AnimeSerienScraper Stopped")
logger.info("-----------------------------------------------------------")
logger.info("Downloads may still be running. Please dont close this Window until its done.")
logger.info(
"You will know its done once you see your primary prompt string. Example: C:\\XXX or username@hostname:")