-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdata.py
More file actions
89 lines (72 loc) · 2.82 KB
/
data.py
File metadata and controls
89 lines (72 loc) · 2.82 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
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
# Copyright (C) 2001 - 2024 David Fillmore
#
# This file is part of Viola.
#
# Viola is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Viola is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import re
from urllib.request import urlopen
ifdb_url = "https://ifdb.org/search?searchgo=Search+Games&searchfor=ifid:"
legacy_serials = ("00", "01", "02", "03", "04", "05")
def getcode(gamedata):
release = (gamedata[2] << 8) + gamedata[3]
serial = gamedata[0x12:0x18].decode('latin-1')
return str(release) + '.' + serial
def getifid(gamedata):
serial: list[str] = list(gamedata[0x12:0x18].decode('latin-1'))
if serial[0] == "8" or serial[0] == "9" or ''.join(serial[0:2]) in legacy_serials:
pass
else:
expr = r"(?<=UUID:\/\/)[a-zA-z\d\-]+(?=\/\/)"
r = re.compile(expr, re.M | re.S)
match = r.search(gamedata.decode('latin-1'))
if match is not None:
return match.string[match.start():match.end()]
for a in range(len(serial)):
if not serial[a].isalnum():
serial[a] = "-"
release = int.from_bytes(gamedata[2:4], byteorder="big")
checksum = int.from_bytes(gamedata[0x1c:0x1e], byteorder="big")
i = "ZCODE-" + str(release) + "-" + ''.join(serial)
if serial[0].isnumeric() and serial[0] != "8" and ''.join(serial) not in ("000000", "999999", "------"):
i += "-" + hex(checksum)[2:]
return i
def getpage(ifid):
response = urlopen(ifdb_url+ifid)
page = response.read().decode('latin-1')
if 'No results were found.' in page and 'Can\'t find the game you\'re looking for?' in page:
page = None
return page
def gettitle(ifdb_page):
expr = r"(?<=\<h1\>).*(?=\<\/h1\>)"
r = re.compile(expr, re.M | re.S)
match = r.search(ifdb_page)
if match is not None:
return match.string[match.start():match.end()]
return None
def getauthor(ifdb_page):
expr1 = r"(?<=\<a href=\"search\?searchfor=author).*?(?=\<\/a\>)"
expr2 = r"(?<=\">).*"
r = re.compile(expr1, re.M | re.S)
match = r.search(ifdb_page)
if match is not None:
m = match.string[match.start():match.end()]
r = re.compile(expr2, re.M | re.S)
match = r.search(m)
if match is not None:
return match.string[match.start():match.end()]
return None
if __name__ == '__main__':
f = open('games/zork1.z3', 'rb')
d = f.read()
f.close()
p = getpage(getifid(d))
if p:
print(getifid(d), gettitle(p), getauthor(p))