Skip to content

Commit 236c2af

Browse files
committed
Adds a few hashes to the team and replay objects.
These can be used in conjuction with the start/end_time attributes to mark duplicate replay files and multiple replay versions of the same game from different participants.
1 parent 7a64557 commit 236c2af

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

sc2reader/objects.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import absolute_import
22

3+
import hashlib
4+
35
from collections import namedtuple
46

57
from sc2reader.constants import *
@@ -25,6 +27,9 @@ class Team(object):
2527
:param interger number: The team number as recorded in the replay
2628
"""
2729

30+
#: A unique hash identifying the team of players
31+
hash = str()
32+
2833
#: The team number as recorded in the replay
2934
number = int()
3035

@@ -48,6 +53,10 @@ def __init__(self,number):
4853
def __iter__(self):
4954
return self.players.__iter__()
5055

56+
@property
57+
def hash(self):
58+
raw_hash = ','.join(sorted(p.url for p in self.players))
59+
return hashlib.sha256(raw_hash).hexdigest()
5160

5261

5362
class Attribute(object):

sc2reader/replay.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import absolute_import
22

3+
import hashlib
4+
35
from datetime import datetime
46
from collections import defaultdict
57
from sc2reader.constants import REGIONS, LOCALIZED_RACES, GAME_SPEED_FACTOR
@@ -97,6 +99,10 @@ def __init__(self, replay_file, **options):
9799
self.raw_data = dict()
98100
self.listeners = defaultdict(list)
99101

102+
replay_file.seek(0)
103+
self.file_hash = hashlib.sha256(replay_file.read()).hexdigest()
104+
replay_file.seek(0)
105+
100106
self.filename = getattr(replay_file,'name', 'Unavailable')
101107
self.__dict__.update(utils.read_header(replay_file))
102108
self.archive = utils.open_archive(replay_file)
@@ -308,6 +314,9 @@ def load_players(self):
308314
else:
309315
raise ValueError("Get Recorder algorithm is broken!")
310316

317+
player_names = sorted(map(lambda p: p.name, self.people))
318+
hash_input = self.gateway+":"+','.join(player_names)
319+
self.people_hash = hashlib.sha256(hash_input).hexdigest()
311320

312321
def load_events(self, datapack=None):
313322
self.datapack = datapack

0 commit comments

Comments
 (0)