-
Notifications
You must be signed in to change notification settings - Fork 1
/
__main__.py
110 lines (85 loc) · 4 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
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import html.parser
import json
import os
import sys
import time
import asyncio
import aiohttp
import aiofiles
from colorama import init, Fore
import color
import modules
def cls():
os.system('cls' if os.name == 'nt' else 'clear')
async def main():
init()
crawl_new_torrent_only = True
cron_job = True
cron_job_interval = 2
cls()
while True:
print('Ohys-Raws Crawler Engine 4.17\nPython Version\n\nDeveloped By Cryental\n')
if not os.path.exists('torrents'):
os.makedirs('torrents')
if not os.path.exists('output'):
os.makedirs('output')
if crawl_new_torrent_only and cron_job:
color.color_print(Fore.YELLOW, '[!]', 'CRONJOB SET: INTERVAL TO {} SEC'.format(cron_job_interval) + '\n')
time.sleep(cron_job_interval)
color.color_print(Fore.YELLOW, '[DONE]', 'READING HEADERS')
color.color_print(Fore.YELLOW, '[DONE]', 'WEBCLIENT INIT')
color.color_print(Fore.YELLOW, '[DONE]', 'SET NORMAL HEADERS\n')
color.color_print(Fore.YELLOW, '[RUNNING]', 'TORRENT LIST LOADING\n')
if crawl_new_torrent_only:
color.color_print(Fore.YELLOW, '[DONE]', 'MODE SELECTED - NEW TORRENT ONLY MODE\n')
else:
color.color_print(Fore.YELLOW, '[DONE]', 'MODE SELECTED - FULL DUMP MODE\n')
if not crawl_new_torrent_only:
color.color_print(Fore.YELLOW, '[RUNNING]', 'ALL TORRENT LIST LOADING\n')
else:
color.color_print(Fore.YELLOW, '[RUNNING]', 'NEW TORRENT LIST LOADING\n')
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/80.0.3987.132 Safari/537.36"}
cancel_crawling_state = False
new_torrent_state = False
try:
for i in range(0, 150):
async with aiohttp.ClientSession() as session:
async with session.get('https://ohys.nl/tt/json.php?dir=disk&p={}'.format(str(i)),headers=headers) as req:
contents_array = json.loads(await req.text())
if len(contents_array) == 0:
break
for item in contents_array:
decoded_file_name = html.unescape(item['t'])
if not os.path.isfile('torrents/' + decoded_file_name) or os.stat(
'torrents/' + decoded_file_name).st_size == 0:
async with session.get('https://ohys.nl/tt/' + item['a']) as file_req:
file = await aiofiles.open('torrents/' + decoded_file_name, mode='wb')
await file.write(await file_req.read())
await file.close()
color.color_print(Fore.LIGHTGREEN_EX, '[DOWNLOADED]', decoded_file_name)
new_torrent_state = True
elif crawl_new_torrent_only:
cancel_crawling_state = True
else:
color.color_print(Fore.LIGHTRED_EX, '[SKIPPED]', decoded_file_name)
if cancel_crawling_state:
break
except:
pass
print('')
color.color_print(Fore.YELLOW, '[DONE]', 'TORRENT LOADED\n')
if new_torrent_state:
color.color_print(Fore.YELLOW, '[PROCESSING]', 'OUTPUT TO JSON TYPE\n')
time.sleep(2)
modules.database_builder()
color.color_print(Fore.YELLOW, '[DONE]', 'OUTPUT TO JSON TYPE')
if not cron_job:
sys.exit(0)
cls()
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()