-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_assets.py
More file actions
33 lines (29 loc) · 1.09 KB
/
Copy pathfetch_assets.py
File metadata and controls
33 lines (29 loc) · 1.09 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
"""Download the public browser release, preserving its relative asset paths."""
from html.parser import HTMLParser
from pathlib import Path
from urllib.request import urlopen
import re
BASE = 'https://games2.gamefools.com/onlinegames/TextTwist2/'
class Links(HTMLParser):
def __init__(self):
super().__init__()
self.links = []
def handle_starttag(self, tag, attrs):
href = dict(attrs).get('href', '')
if tag == 'a' and re.fullmatch(r'[A-Za-z0-9_.-]+/?', href) and href not in ('..', '../'):
self.links.append(href)
def fetch(path='root/'):
data = urlopen(BASE + path, timeout=30).read()
if path.endswith('/'):
parser = Links()
parser.feed(data.decode())
for link in parser.links:
fetch(path + link)
else:
dest = Path('assets') / path
dest.parent.mkdir(parents=True, exist_ok=True)
dest.write_bytes(data)
print(path, len(data), flush=True)
if __name__ == '__main__':
for path in ('root/game.swf', 'root/soundLibrary.swf', 'root/global/', 'root/localized/'):
fetch(path)