From 0795bfae9c3ef50a452d7af60387c08b2b17b19d Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 15 Aug 2021 20:39:36 -0400 Subject: [PATCH 1/5] url_template updates load_map=True should now work on CN and NA out of the box. Updated the other url_templates to use the new blizzard CDN, although I neglected to include CN in them as adding it would be a bit more effort/it seems those were rarely used anyway since no one complained they were broken. --- sc2reader/resources.py | 10 +++++----- sc2reader/utils.py | 9 ++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/sc2reader/resources.py b/sc2reader/resources.py index ad80695e..3b15ad5c 100644 --- a/sc2reader/resources.py +++ b/sc2reader/resources.py @@ -914,7 +914,7 @@ def __getstate__(self): class Map(Resource): - url_template = "http://{0}.depot.battle.net:1119/{1}.s2ma" + url_template = "https://{0}-s2-depot.classic.blizzard.com/{1}.s2ma" def __init__(self, map_file, filename=None, region=None, map_hash=None, **options): super(Map, self).__init__(map_file, filename, **options) @@ -1021,7 +1021,7 @@ class GameSummary(Resource): that the data is not necessarily in the places we expect. """ - url_template = "http://{0}.depot.battle.net:1119/{1}.s2gs" + url_template = "https://{0}-s2-depot.classic.blizzard.com/{1}.s2gs" #: Game speed game_speed = str() @@ -1450,9 +1450,9 @@ def __str__(self): class MapHeader(Resource): """**Experimental**""" - base_url_template = "http://{0}.depot.battle.net:1119/{1}.{2}" - url_template = "http://{0}.depot.battle.net:1119/{1}.s2mh" - image_url_template = "http://{0}.depot.battle.net:1119/{1}.s2mv" + base_url_template = "https://{0}-s2-depot.classic.blizzard.com/{1}.{2}" + url_template = "https://{0}-s2-depot.classic.blizzard.com/{1}.s2mh" + image_url_template = "https://{0}-s2-depot.classic.blizzard.com/{1}.s2mv" #: The name of the map name = str() diff --git a/sc2reader/utils.py b/sc2reader/utils.py index c35f91f3..0b4000cb 100644 --- a/sc2reader/utils.py +++ b/sc2reader/utils.py @@ -20,15 +20,18 @@ class DepotFile(object): """ #: The url template for all DepotFiles - url_template = "https://{0}-s2-depot.classic.blizzard.com/{1}.{2}" + url_template = "https://{0}-s2-depot.classic.blizzard.com{1}/{2}.{3}" def __init__(self, bytes): #: The server the file is hosted on self.server = bytes[4:8].decode("utf-8").strip("\x00 ") - + #: Used to make it possible to load maps from CN. This isn't needed for any other region and so is blank by default. + self.urlEnd = "" # There is no SEA depot, use US instead if self.server == "SEA": self.server = "US" + elif self.server == "CN": + self.urlEnd = ".cn" #: The unique content based hash of the file self.hash = binascii.b2a_hex(bytes[8:]).decode("utf8") @@ -39,7 +42,7 @@ def __init__(self, bytes): @property def url(self): """Returns url of the depot file.""" - return self.url_template.format(self.server, self.hash, self.type) + return self.url_template.format(self.server, self.urlEnd, self.hash, self.type) def __hash__(self): return hash(self.url) From 2c0b37771a5962faf34b5c4ab172e854243744ca Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 16 Aug 2021 08:45:07 -0400 Subject: [PATCH 2/5] Cleaned URL templates --- sc2reader/resources.py | 10 +++++----- sc2reader/utils.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sc2reader/resources.py b/sc2reader/resources.py index 3b15ad5c..50c54f9f 100644 --- a/sc2reader/resources.py +++ b/sc2reader/resources.py @@ -914,7 +914,7 @@ def __getstate__(self): class Map(Resource): - url_template = "https://{0}-s2-depot.classic.blizzard.com/{1}.s2ma" + url_template = "https://{}-s2-depot.classic.blizzard.com/{}.s2ma" def __init__(self, map_file, filename=None, region=None, map_hash=None, **options): super(Map, self).__init__(map_file, filename, **options) @@ -1021,7 +1021,7 @@ class GameSummary(Resource): that the data is not necessarily in the places we expect. """ - url_template = "https://{0}-s2-depot.classic.blizzard.com/{1}.s2gs" + url_template = "https://{}-s2-depot.classic.blizzard.com/{}.s2gs" #: Game speed game_speed = str() @@ -1450,9 +1450,9 @@ def __str__(self): class MapHeader(Resource): """**Experimental**""" - base_url_template = "https://{0}-s2-depot.classic.blizzard.com/{1}.{2}" - url_template = "https://{0}-s2-depot.classic.blizzard.com/{1}.s2mh" - image_url_template = "https://{0}-s2-depot.classic.blizzard.com/{1}.s2mv" + base_url_template = "https://{}-s2-depot.classic.blizzard.com/{}.{}" + url_template = "https://{}-s2-depot.classic.blizzard.com/{}.s2mh" + image_url_template = "https://{}-s2-depot.classic.blizzard.com/{}.s2mv" #: The name of the map name = str() diff --git a/sc2reader/utils.py b/sc2reader/utils.py index 0b4000cb..a4564af3 100644 --- a/sc2reader/utils.py +++ b/sc2reader/utils.py @@ -20,7 +20,7 @@ class DepotFile(object): """ #: The url template for all DepotFiles - url_template = "https://{0}-s2-depot.classic.blizzard.com{1}/{2}.{3}" + url_template = "https://{}-s2-depot.classic.blizzard.com{}/{}.{}" def __init__(self, bytes): #: The server the file is hosted on From d96eb510838c7d63f02c32ca92fab45a697b032c Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 16 Aug 2021 08:46:55 -0400 Subject: [PATCH 3/5] Rename variable Renamed urlEnd to url_suffix for naming rules/better naming --- sc2reader/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sc2reader/utils.py b/sc2reader/utils.py index a4564af3..8bc1c054 100644 --- a/sc2reader/utils.py +++ b/sc2reader/utils.py @@ -26,12 +26,12 @@ def __init__(self, bytes): #: The server the file is hosted on self.server = bytes[4:8].decode("utf-8").strip("\x00 ") #: Used to make it possible to load maps from CN. This isn't needed for any other region and so is blank by default. - self.urlEnd = "" + self.url_suffix = "" # There is no SEA depot, use US instead if self.server == "SEA": self.server = "US" elif self.server == "CN": - self.urlEnd = ".cn" + self.url_suffix = ".cn" #: The unique content based hash of the file self.hash = binascii.b2a_hex(bytes[8:]).decode("utf8") @@ -42,7 +42,7 @@ def __init__(self, bytes): @property def url(self): """Returns url of the depot file.""" - return self.url_template.format(self.server, self.urlEnd, self.hash, self.type) + return self.url_template.format(self.server, self.url_suffix, self.hash, self.type) def __hash__(self): return hash(self.url) From 64041c27e1295aa99ea2e0c3c19a55676c8095b4 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 16 Aug 2021 13:20:34 -0400 Subject: [PATCH 4/5] Formatting Fixes --- sc2reader/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sc2reader/utils.py b/sc2reader/utils.py index 8bc1c054..c0cdd62c 100644 --- a/sc2reader/utils.py +++ b/sc2reader/utils.py @@ -25,8 +25,11 @@ class DepotFile(object): def __init__(self, bytes): #: The server the file is hosted on self.server = bytes[4:8].decode("utf-8").strip("\x00 ") - #: Used to make it possible to load maps from CN. This isn't needed for any other region and so is blank by default. + + # Used to make it possible to load maps from CN. + # This isn't needed for any other region and so is blank by default. self.url_suffix = "" + # There is no SEA depot, use US instead if self.server == "SEA": self.server = "US" @@ -42,7 +45,9 @@ def __init__(self, bytes): @property def url(self): """Returns url of the depot file.""" - return self.url_template.format(self.server, self.url_suffix, self.hash, self.type) + return self.url_template.format( + self.server, self.url_suffix, self.hash, self.type + ) def __hash__(self): return hash(self.url) From b68cc48a8b08da15ff90d4f950d3d3cbca4b89b1 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 16 Aug 2021 13:39:57 -0400 Subject: [PATCH 5/5] remove trailing spaces --- sc2reader/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sc2reader/utils.py b/sc2reader/utils.py index c0cdd62c..c4bbcd77 100644 --- a/sc2reader/utils.py +++ b/sc2reader/utils.py @@ -26,9 +26,9 @@ def __init__(self, bytes): #: The server the file is hosted on self.server = bytes[4:8].decode("utf-8").strip("\x00 ") - # Used to make it possible to load maps from CN. + # Used to make it possible to load maps from CN. # This isn't needed for any other region and so is blank by default. - self.url_suffix = "" + self.url_suffix = "" # There is no SEA depot, use US instead if self.server == "SEA":