-
Notifications
You must be signed in to change notification settings - Fork 2
/
latest_megas.py
64 lines (51 loc) · 1.58 KB
/
latest_megas.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
#!/usr/bin/env python
# Grabs the latest N mega links from the output of hdg_archive.py, for adding to
# JDownloader2 or similar
import os
import os.path
import re
import argparse
parser = argparse.ArgumentParser(description="Optional app description")
parser.add_argument("path", type=str, help="Path to input directory")
parser.add_argument(
"--num-threads",
"-n",
type=int,
default=5,
help="Find only the N most recent threads",
)
args = parser.parse_args()
txts = []
for site in os.listdir(args.path):
bp = os.path.join(args.path, site)
try:
for board in os.listdir(bp):
try:
bp2 = os.path.join(bp, board)
i = 0
threads = sorted(os.listdir(bp2), key=int, reverse=True)
for thread in threads:
mega = os.path.join(bp2, thread, "mega.txt")
if os.path.isfile(mega):
txts.append(mega)
i += 1
if i > args.num_threads:
break
except Exception as ex:
print(ex)
break
except Exception as ex:
print(ex)
continue
folder_re = re.compile(r"^(http.*/folder/.*)/(folder|file)/.*") # strip mega subfolders
links = set()
for txt in txts:
with open(txt, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
m = folder_re.search(line)
if m:
line = m.group(1)
links.add(line.strip())
for link in links:
print(link)