-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcrawler.py
166 lines (122 loc) · 5.2 KB
/
crawler.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
import filehandler
import userhandler
import logger
import config
import re
from classes import Anime
def simple_download(site):
import sites.torrenthandler as torrenthandler
module_path = "sites."+site
importlib = __import__("importlib")
site = importlib.import_module(module_path)
site.open_all_anime_page()
torrenthandler.open_qbittorrent()
torrenthandler.log_in()
anime = Anime()
anime.title = userhandler.ask_for_anime().replace('–', '-')
downloadAnime(anime, site, torrenthandler)
torrenthandler.torrent_driver.quit()
site.sp_driver.quit()
def download_from_schedule(site):
import sites.torrenthandler as torrenthandler
module_path = "sites."+site
importlib = __import__("importlib")
site = importlib.import_module(module_path)
site.open_schedule_page()
torrenthandler.open_qbittorrent()
torrenthandler.log_in()
anime_list = site.get_every_anime_from_schedule()
site.open_all_anime_page()
for anime in anime_list:
downloadAnime(anime, site, torrenthandler)
torrenthandler.torrent_driver.quit()
site.sp_driver.quit()
def update_seasonal(site):
import sites.torrenthandler as torrenthandler
module_path = "sites."+site
importlib = __import__("importlib")
site = importlib.import_module(module_path)
site.open_overview_page()
torrenthandler.open_qbittorrent()
torrenthandler.log_in()
anime_list = site.get_every_anime_with_new_ep()
site.open_all_anime_page()
for anime in anime_list:
downloadAnime(anime, site, torrenthandler)
torrenthandler.torrent_driver.quit()
site.sp_driver.quit()
def get_all_anime(site):
import sites.torrenthandler as torrenthandler
module_path = "sites."+site
importlib = __import__("importlib")
site = importlib.import_module(module_path)
site.open_all_anime_page()
torrenthandler.open_qbittorrent()
torrenthandler.log_in()
anime_list = site.get_every_anime()
site.open_all_anime_page()
for anime in anime_list:
downloadAnime(anime, site, torrenthandler)
torrenthandler.torrent_driver.quit()
site.sp_driver.quit()
def standardize_downloaded():
for directory in config.directories:
path_list = filehandler.select_paths(directory)
filehandler.rename(path_list)
def downloadAnime(anime, site, torrenthandler):
if re.search("Movie", anime.title) or re.search("OVA", anime.title):
logger.info("This Anime is a Movie and has to be downloaded manually")
return
if anime.title in config.blacklist_do_not_download:
logger.info("Anime " + anime.title +
" is on Blacklist and will not be downloaded\n")
return
site.go_to_anime(anime.title)
if site.episode_check():
anime.title = site.detect_title(anime.title)
anime.batched = site.detect_batched()
anime.latest_title_on_overview = site.extract_latest_title()
anime.season = site.detect_season(anime.latest_title_on_overview)
if anime.batched is True:
logger.info("This anime is batched")
logger.info("Collecting batch-links for {} | Season {}".format(
anime.title, anime.season))
anime.amount_of_episodes = site.extract_amount_of_episodes_from_batch()
anime.episodes = site.extract_episodes_from_batch()
logger.info("Collected batch-link".format(
anime.title, anime.season))
else:
logger.info("Collecting links for {} | Season {}".format(
anime.title, anime.season))
anime.episodes = site.get_magnet_links()
anime.amount_of_episodes = len(anime.episodes)
logger.info('Starting Download-Process...')
logger.info("The anime {} has {} episodes so far".format(
anime.title, anime.amount_of_episodes))
episode_difference = filehandler.check_if_anime_up_to_date(
anime.title, anime.season, anime.amount_of_episodes)
logger.info("{} of which are not on the server yet".format(
episode_difference))
download_path = filehandler.check_directory_for_anime(
anime.title, anime.season)
logger.info("Downloading them to {}".format(download_path))
if episode_difference is not None and anime.batched is True:
logger.info("Deleting out of date files")
filehandler.remove_episodes(
anime.title, anime.season)
links_to_download = anime.episodes
torrenthandler.queue(links_to_download, download_path)
logger.info('Process finished for ' + anime.title)
logger.newline()
site.leave_anime()
elif episode_difference is not None and anime.batched is False:
links_to_download = anime.episodes[:episode_difference]
torrenthandler.queue(links_to_download, download_path)
logger.info('Process finished for ' + anime.title)
logger.newline()
site.leave_anime()
else:
logger.info(anime.title + ' is already up to date')
logger.info('Process finished for ' + anime.title)
logger.newline()
site.leave_anime()