def loadTitleBuffer(buffer, silent=False): firstLine = True map = ['id', 'key', 'name'] for line in buffer.split('\n'): line = line.strip() if len(line) == 0 or line[0] == '#': continue if firstLine: firstLine = False if re.match('[A-Za-z\|\s]+', line, re.I): map = line.split('|') continue t = Title.Title() t.loadCsv(line, map) if not t.id in keys(): titles[t.id] = Title.Title() titleKey = titles[t.id].key titles[t.id].loadCsv(line, map) if not silent and titleKey != titles[t.id].key: Print.info('Added new title key for ' + str(titles[t.id].name) + '[' + str(t.id) + ']')
def get(key, region=None, language=None): key = key.upper() if not key in data(region, language): t = Title.Title() t.setId(key) data(region, language)[key] = t return data(region, language)[key]
def load(): confLock.acquire() global titles titles = {} if os.path.isfile("titledb/titles.json"): timestamp = time.clock() with open('titledb/titles.json', encoding="utf-8-sig") as f: for i, k in json.loads(f.read()).items(): titles[i] = Title.Title() titles[i].__dict__ = k titles[i].setId(i) Print.info('loaded titledb/titles.json in ' + str(time.clock() - timestamp) + ' seconds') ''' if os.path.isfile("titles.txt"): loadTitleFile('titles.txt', True) try: files = [f for f in os.listdir(Config.paths.titleDatabase) if f.endswith('.txt')] files.sort() for file in files: loadTitleFile(Config.paths.titleDatabase + '/' + file, False) except BaseException as e: Print.error('title load error: ' + str(e)) ''' confLock.release() loadTxtDatabases()
def load(): confLock.acquire() global titles if os.path.isfile("titles.json"): timestamp = time.clock() with open('titles.json', encoding="utf-8-sig") as f: for i, k in json.loads(f.read()).items(): #if k['frontBoxArt'] and k['frontBoxArt'].endswith('.jpg'): # k['iconUrl'] = k['frontBoxArt'] # k['frontBoxArt'] = None titles[i] = Title.Title() titles[i].__dict__ = k Print.info('loaded titles.json in ' + str(time.clock() - timestamp) + ' seconds') if os.path.isfile("titles.txt"): loadTitleFile('titles.txt', True) try: files = [ f for f in os.listdir(Config.paths.titleDatabase) if f.endswith('.txt') ] files.sort() for file in files: loadTitleFile(Config.paths.titleDatabase + '/' + file, False) except BaseException as e: Print.error('title load error: ' + str(e)) confLock.release()
def fileName(self): bt = None if not self.titleId in Titles.keys(): if not Title.getBaseId(self.titleId) in Titles.keys(): Print.info('could not find title key for ' + self.titleId + ' or ' + Title.getBaseId(self.titleId)) return None bt = Titles.get(Title.getBaseId(self.titleId)) t = Title() t.loadCsv(self.titleId + '0000000000000000|0000000000000000|' + bt.name) else: t = Titles.get(self.titleId) if not t: Print.error('could not find title id ' + str(self.titleId)) return None try: if not t.baseId in Titles.keys(): Print.info('could not find baseId for ' + self.path) return None except BaseException as e: print('exception: could not find title id ' + str(self.titleId) + ' ' + str(e)) return None bt = Titles.get(t.baseId) if t.isDLC: format = Config.paths.getTitleDLC(not self.hasValidTicket) elif t.isDemo: if t.idExt != 0: format = Config.paths.getTitleDemoUpdate( not self.hasValidTicket) else: format = Config.paths.getTitleDemo(not self.hasValidTicket) elif t.idExt != 0: format = Config.paths.getTitleUpdate(not self.hasValidTicket) else: format = Config.paths.getTitleBase(not self.hasValidTicket) format = format.replace('{id}', self.cleanFilename(t.id)) format = format.replace('{region}', self.cleanFilename(t.getRegion() or '')) format = format.replace('{name}', self.cleanFilename(t.getName() or '')) format = format.replace('{version}', str(self.getVersion() or 0)) format = format.replace('{baseId}', self.cleanFilename(bt.id)) format = format.replace('{baseName}', self.cleanFilename(bt.getName() or '')) ''' if self.hasValidTicket: format = os.path.splitext(format)[0] + '.nsp' else: format = os.path.splitext(format)[0] + '.nsx' ''' return format
def fileName(self): bt = None if not self.titleId in Titles.keys(): if not Title.getBaseId(self.titleId) in Titles.keys(): Print.info('could not find title key for ' + self.titleId + ' or ' + Title.getBaseId(self.titleId)) return None bt = Titles.get(Title.getBaseId(self.titleId)) t = Title() t.loadCsv(self.titleId + '0000000000000000|0000000000000000|' + bt.name) else: t = Titles.get(self.titleId) if not t: Print.error('could not find title id ' + str(self.titleId)) return None try: if not t.baseId in Titles.keys(): Print.info('could not find baseId for ' + self.path) return None except BaseException as e: print('exception: could not find title id ' + str(self.titleId) + ' ' + str(e)) return None bt = Titles.get(t.baseId) if t.isDLC: format = Config.paths.getTitleDLC(not self.hasValidTicket) elif t.isDemo: if t.idExt != 0: format = Config.paths.getTitleDemoUpdate( not self.hasValidTicket) else: format = Config.paths.getTitleDemo(not self.hasValidTicket) elif t.idExt != 0: format = Config.paths.getTitleUpdate(not self.hasValidTicket) else: format = Config.paths.getTitleBase(not self.hasValidTicket) format = format.replace('{id}', self.cleanFilename(t.id)) format = format.replace('{region}', self.cleanFilename(t.getRegion() or '')) format = format.replace('{name}', self.cleanFilename(t.getName() or '')) format = format.replace('{version}', str(self.getVersion() or 0)) format = format.replace('{baseId}', self.cleanFilename(bt.id)) baseName = self.cleanFilename(bt.getName() or '') result = format.replace('{baseName}', baseName) while (len(os.path.basename(result).encode('utf-8')) > 254 and len(baseName) > 3): baseName = baseName[:-1] result = format.replace('{baseName}', baseName) return result
def title(self): if not self.titleId: raise IOError('NSP no titleId set') if self.titleId in Titles.keys(): return Titles.get(self.titleId) t = Title.Title() t.setId(self.titleId) Titles.data()[self.titleId] = t return t
def asteroids(): continuer = True gameState = ["EndScreen", 50] screen = pygame.display.set_mode((600, 600)) while continuer: if gameState[0] == "TitleScreen": gameState = Title.Title(screen) elif gameState[0] == "GameScreen": gameState = Game.Game(screen) elif gameState[0] == "EndScreen": gameState = End.End(screen, gameState[1]) elif gameState[0] == "Quit": continuer = False
def getNsuid(id, region, language): id = int(id) map = data(region, language) for t in map: if map[t].nsuId == id: return map[t] title = Title.Title() title.nsuId = id map[id] = title return title
def create_titles(titles, all_sprites, mode): title = '' if mode == 1: title = 'SAVE MAP' if mode == 2: title = 'SAVE PIVOTS' if mode == 3: title = PREPARE_AND_RUN_TITLE # Button for saving map button_hight = SCREEN_WIDTH - SCREEN_HEIGHT - 2 * PADDING # (SCREEN_WIDTH + button_hight/2, button_hight/2) button = Title( button_hight, (SCREEN_HEIGHT + button_hight / 2, PADDING + button_hight / 2), title, mode) titles.add(button) all_sprites.add(button) if mode == 3: reset_button = Title(button_hight, (SCREEN_HEIGHT + button_hight / 2, PADDING * 2 + button_hight * 1.5), RESET_TITLE, mode) titles.add(reset_button) all_sprites.add(reset_button)
def loadTitleBuffer(buffer, silent = False): firstLine = True map = ['id', 'key', 'name'] for line in buffer.split('\n'): line = line.strip() if len(line) == 0 or line[0] == '#': continue if firstLine: firstLine = False if re.match('[A-Za-z\|\s]+', line, re.I): map = line.split('|') i = 0 while i < len(map): if map[i] == 'RightsID': map[i] = 'id' if map[i] == 'TitleKey': map[i] = 'key' if map[i] == 'Name': map[i] = 'name' i += 1 continue t = Title.Title() t.loadCsv(line, map) if not isinstance(t.id, str): continue if not t.id in keys(None, None): titles[t.id] = Title.Title() titleKey = titles[t.id].key titles[t.id].loadCsv(line, map) if not silent and titleKey != titles[t.id].key: Print.info('Added new title key for ' + str(titles[t.id].name) + '[' + str(t.id) + ']')
def loadTitlesJson(filePath='titledb/titles.json'): newTitles = {} confLock.acquire() if os.path.isfile(filePath): timestamp = time.clock() with open(filePath, encoding="utf-8-sig") as f: for i, k in json.loads(f.read()).items(): newTitles[i] = Title.Title() newTitles[i].__dict__ = k Print.info('loaded ' + filePath + ' in ' + str(time.clock() - timestamp) + ' seconds') confLock.release() return newTitles
def fileName(self): bt = None if not self.titleId in Titles.keys(): if not Title.getBaseId(self.titleId) in Titles.keys(): Print.info('could not find title key for ' + self.titleId + ' or ' + Title.getBaseId(self.titleId)) return None bt = Titles.get(Title.getBaseId(self.titleId)) t = Title() t.loadCsv(self.titleId + '0000000000000000|0000000000000000|' + bt.name) else: t = Titles.get(self.titleId) if not t.baseId in Titles.keys(): Print.info('could not find baseId for ' + self.path) return None bt = Titles.get(t.baseId) if t.isDLC: format = Config.paths.titleDLC elif t.isDemo: if t.idExt != 0: format = Config.paths.titleDemoUpdate else: format = Config.paths.titleDemo elif t.idExt != 0: format = Config.paths.titleUpdate else: format = Config.paths.titleBase format = format.replace('{id}', self.cleanFilename(t.id)) format = format.replace('{region}', self.cleanFilename(t.region or '')) format = format.replace('{name}', self.cleanFilename(t.name or '')) format = format.replace('{version}', str(self.version or 0)) format = format.replace('{baseId}', self.cleanFilename(bt.id)) format = format.replace('{baseName}', self.cleanFilename(bt.name or '')) if self.hasValidTicket: format = os.path.splitext(format)[0] + '.nsp' else: format = os.path.splitext(format)[0] + '.nsx' return format
def getNsuIds(titleIds, type='title', region='US', shop_id=4): j = ids(titleIds, type, region, shop_id) lst = {} try: for i in j['id_pairs']: titleId = i['title_id'].upper() nsuId = int(['id']) lst[titleId] = nsuId if Titles.contains(titleId): Titles.get(titleId).nsuId = nsuId else: title = Title.Title() title.setId(titleId) title.nsuId = nsuId Titles.set(titleId, title) except BaseException as e: pass return lst
def xmlGetTitleNodeRecursive(self, node, title_idx=-1): print "[xmlGetTitleNodeRecursive]", title_idx, node print node.childNodes for subnode in node.childNodes: print "xmlGetTitleNodeRecursive subnode:", subnode if subnode.nodeType == xml.dom.minidom.Element.nodeType: if subnode.tagName == 'title': title_idx += 1 title = Title.Title(self) self.titles.append(title) self.xmlGetTitleNodeRecursive(subnode, title_idx) if subnode.tagName == 'path': print "path:", subnode.firstChild.data filename = subnode.firstChild.data self.titles[title_idx].addFile(filename.encode("utf-8")) if subnode.tagName == 'properties': self.xmlAttributesToConfig( node, self.titles[title_idx].properties) if subnode.tagName == 'audiotracks': self.xmlGetTitleNodeRecursive(subnode, title_idx) if subnode.tagName == 'audiotrack': print "audiotrack...", subnode.toxml()
def load(): global regionTitles for region in cdn.regions(): filePath = 'titledb/%s.json' % region if os.path.isfile(filePath): regionTitles[region] = loadTitlesJson(filePath) else: regionTitles[region] = {} confLock.acquire() global titles if os.path.isfile("titledb/titles.json"): timestamp = time.clock() with open('titledb/titles.json', encoding="utf-8-sig") as f: for i, k in json.loads(f.read()).items(): titles[i] = Title.Title() titles[i].__dict__ = k Print.info('loaded titledb/titles.json in ' + str(time.clock() - timestamp) + ' seconds') if os.path.isfile("titles.txt"): loadTitleFile('titles.txt', True) try: files = [ f for f in os.listdir(Config.paths.titleDatabase) if f.endswith('.txt') ] files.sort() for file in files: loadTitleFile(Config.paths.titleDatabase + '/' + file, False) except BaseException as e: Print.error('title load error: ' + str(e)) confLock.release()
def getAddOns(titleId): url = 'https://superfly.hac.%s.d4c.nintendo.net/v1/a/%s/dv' % ( Config.cdn.environment, titleId) j = makeJsonRequest('GET', url, {}, '%d/a/%s/dv.json' % (shop_id, titleId)) lst = [] if not j: return lst for i in j: id = i['title_id'].upper() if Titles.contains(id): Titles.get(id).setVersion(int(i['version'])) else: Print.info('New DLC found: ' + id) title = Title.Title() title.setId(id) title.setVersion(int(i['version'])) Titles.set(id, title) lst.append(id) return lst
def scrapeTitles(region='US', shop_id=4): Print.info('Scraping %s' % region) pageSize = 50 offset = 0 total = 1 c = 0 while offset < total: url = 'https://bugyo.hac.%s.eshop.nintendo.net/shogun/v1/titles?shop_id=%d&lang=%s&country=%s&sort=new&limit=%d&offset=%d' % ( Config.cdn.environment, shop_id, countryLanguage(region), region, pageSize, offset) #print(url) j = makeJsonRequest( 'GET', url, {}, '%d/%s/%s/titles/index/%d-%d.json' % (shop_id, countryLanguage(region), region, pageSize, offset)) if not j: break total = int(j['total']) try: for i in j['contents']: title = Titles.getNsuid(i['id']) n = getTitleByNsuid(i['id'], region) if title: for x in cdn.Superfly.getAddOns(title.id): getNsuIds(x, 'aoc', region) title.parseShogunJson(n) rt = Title.Title() rt.setId(title.id) rt.setRegion(region) rt.parseShogunJson(n) Titles.set(title.id, rt, region) scrapeDlc(i['id'], region) else: try: if n and len(n["applications"]) > 0: titleId = n["applications"][0]["id"].upper() for x in cdn.Superfly.getAddOns(titleId): getNsuIds(x, 'aoc', region) if titleId: if Titles.contains(titleId): title = Titles.get(titleId) title.setId(titleId) title.parseShogunJson(n) #print('existing title found!') else: title = Title.Title() title.setId(titleId) title.parseShogunJson(n) Titles.set(titleId, title) print('added new title %s %s' % (title.id, title.name)) rt = Title.Title() rt.setId(titleId) rt.setRegion(region) rt.parseShogunJson(n) Titles.set(titleId, rt, region) scrapeDlc(i['id'], region) else: print('Could not get title json!') else: #print('no title id found in json!') pass except Exception as e: #print(str(e)) pass except Exception as e: print(str(e)) raise break offset = offset + len(j['contents']) #c = c + 1 #if c % 100 == 0: # Print.info('.') # Titles.save() Titles.save()
def handle_escape(self): Globals.STATE = Title.Title()
def addService(self, service): title = Title.Title(self) title.addService(service) self.titles.append(title) return title
def PreparePiece(self, name): self.circle = Circle.Circle(self.current_position[0], self.current_position[1]) self.title = Title.Title(name, self.current_position[0], self.current_position[1])
def scrapeDlc(baseNsuid, region='US', shop_id=3): pageSize = 50 offset = 0 total = 1 while offset < total: url = 'https://bugyo.hac.%s.eshop.nintendo.net/shogun/v1/titles/%d/aocs?shop_id=%d&lang=%s&country=%s' % ( Config.cdn.environment, baseNsuid, shop_id, countryLanguage(region), region) #print(url) #exit(0) j = makeJsonRequest( 'GET', url, {}, '%d/%s/%s/titles/aocs/%d.json' % (shop_id, countryLanguage(region), region, baseNsuid)) if not j: break total = int(j['total']) if total == 0: break try: for i in j['contents']: title = Titles.getNsuid(i['id']) n = getDlcByNsuid(i['id']) if title: title.parseShogunJson(n, region) rt = Title.Title() rt.setId(title.id) rt.setRegion(region) rt.parseShogunJson(n) Titles.set(title.id, rt, region) else: try: if n and len(n["applications"]) > 0: titleId = n["applications"][0]["id"].upper() if titleId: if Titles.contains(titleId): title = Titles.get(titleId) title.setId(titleId) title.parseShogunJson(n, region) #print('existing title found!') else: title = Title.Title() title.setId(titleId) title.parseShogunJson(n, region) Titles.set(titleId, title) print('added new DLC %s %s' % (title.id, title.name)) rt = Title.Title() rt.setId(titleId) rt.setRegion(region) rt.parseShogunJson(n, region) Titles.set(titleId, rt, region) else: print('Could not get title json!') else: #print('no title id found in json!') pass except Exception as e: #print(str(e)) pass except Exception as e: print(str(e)) raise break offset = offset + len(j['contents'])