-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrab_torrent.py
More file actions
38 lines (32 loc) · 1.2 KB
/
grab_torrent.py
File metadata and controls
38 lines (32 loc) · 1.2 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
#!/usr/bin/env python3
import re
from time import time
import concurrent.futures
import caoliu
FORUM_URL = "http://t66y.com/thread0806.php?fid=25"
guochan_forum = caoliu.ForumPage(FORUM_URL)
posts = [post for post in guochan_forum.posts if re.search('fhd', post.title, re.I)]
print('Parsing posts to find torrents...')
torrent_urls = set()
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
futures = {executor.submit(caoliu.grab_torrent_url, post) for post in posts}
for future in concurrent.futures.as_completed(futures):
try:
result = future.result()
except Exception as exc:
print('ERR: %s' % exc)
else:
torrent_urls.add(result)
print('parsing...')
if None in torrent_urls:
torrent_urls.remove(None)
print('Downloading torrents')
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
futures = {executor.submit(caoliu.download_torrent, url) for url in torrent_urls}
for future in concurrent.futures.as_completed(futures):
try:
future.result()
except Exception as exc:
print('Failed %s' % exc)
else:
print('Done')