Skip to content

Commit cf65672

Browse files
committed
Adds os specific timestamp parsing. Re: #58
Identifies a flag for an operating system with Windows as 0 and Mac as 1. Also adds a new algorithm for getting times from Mac replays.
1 parent 7e8721e commit cf65672

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

sc2reader/objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from sc2reader.utils import PersonDict, AttributeDict
99

1010
Location = namedtuple('Location',('x','y'))
11-
Details = namedtuple('Details',['players','map','unknown1','unknown2','unknown3','file_time','utc_adjustment','unknown4','unknown5','unknown6','unknown7','unknown8','unknown9','unknown10'])
11+
Details = namedtuple('Details',['players','map','unknown1','unknown2','os','file_time','utc_adjustment','unknown4','unknown5','unknown6','unknown7','unknown8','unknown9','unknown10'])
1212

1313
MapData = namedtuple('MapData',['unknown','gateway','map_hash'])
1414
PlayerData = namedtuple('PlayerData',['name','bnet','race','color','unknown1','unknown2','handicap','unknown3','result'])

sc2reader/resources.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class Replay(Resource):
5353
#: The game speed: Slower, Slow, Normal, Fast, Faster
5454
speed = str()
5555

56+
#: The operating system the replay was recorded on.
57+
#: Useful for interpretting certain kind of raw data.
58+
os = str()
59+
5660
#: Deprecated, use :member:`game_type` or :member:`real_type` instead
5761
type = str()
5862

@@ -180,6 +184,7 @@ def __init__(self, replay_file, filename=None, load_level=4, **options):
180184
self.other_people = set()
181185
self.speed = ""
182186
self.type = ""
187+
self.os = str()
183188
self.game_type = ""
184189
self.real_type = ""
185190
self.category = ""
@@ -269,11 +274,21 @@ def load_details(self):
269274

270275
self.map_name = details.map
271276

272-
self.windows_timestamp = details.file_time-details.utc_adjustment
273-
self.unix_timestamp = utils.windows_to_unix(self.windows_timestamp)
274-
self.time_zone = details.utc_adjustment/(10**7*60*60)
277+
if details.os == 0:
278+
self.os = "Windows"
279+
self.windows_timestamp = details.file_time-details.utc_adjustment
280+
self.unix_timestamp = utils.windows_to_unix(self.windows_timestamp)
281+
self.time_zone = details.utc_adjustment/(10**7*60*60)
282+
self.end_time = datetime.utcfromtimestamp(self.unix_timestamp)
283+
elif details.os == 1:
284+
self.os = "Mac"
285+
self.windows_timestamp = details.utc_adjustment
286+
self.unix_timestamp = utils.windows_to_unix(self.windows_timestamp)
287+
self.time_zone = (details.utc_adjustment-details.file_time)/(10**7*60*60)
288+
self.end_time = datetime.utcfromtimestamp(self.unix_timestamp)
289+
else:
290+
raise ValueError("Unknown operating system {} detected.".format(details.os))
275291

276-
self.end_time = datetime.utcfromtimestamp(self.unix_timestamp)
277292
self.game_length = self.length
278293
self.real_length = utils.Length(seconds=int(self.length.seconds/GAME_SPEED_FACTOR[self.speed]))
279294
self.start_time = datetime.utcfromtimestamp(self.unix_timestamp-self.real_length.seconds)

0 commit comments

Comments
 (0)