| import os |
| import xml.etree.ElementTree as ET |
| import glob |
| import re |
|
|
| def count_quotation_marks(text): |
| return text.count('"') |
|
|
| def replace_special_quotes(text): |
| if text: |
| return text.replace('\u201d', '"').replace('\u201e', '"').replace('\u201c', '"') |
| return text |
|
|
| def parse_odcs(folder_path): |
| |
| langs = ["en-GB", "fr-FR", "de-DE", "it-IT", "es-ES", "en-US", "ko-KR", "en-SG", "zh-HK", "zh-TW", "ja-JP"] |
| lang_to_territory = { |
| "en-GB": "SCEE", |
| "fr-FR": "SCEE", |
| "de-DE": "SCEE", |
| "it-IT": "SCEE", |
| "es-ES": "SCEE", |
| "en-US": "SCEA", |
| "ko-KR": "SCEAsia", |
| "en-SG": "SCEAsia", |
| "zh-HK": "SCEAsia", |
| "zh-TW": "SCEAsia", |
| "ja-JP": "SCEJ" |
| } |
| territories = ["SCEE", "SCEA", "SCEAsia", "SCEJ"] |
|
|
| |
| output_file = "ODCInfo.txt" |
| flagged_file = "FlaggedODCFiles.txt" |
|
|
| |
| with open(output_file, "w", encoding="utf-8") as out_file, open(flagged_file, "w", encoding="utf-8") as flag_file: |
| |
| header = "file_name|hdk_version|version|uuid|timestamp|lang|default|territory|entitlement_ids|category_ids|product_ids|maker|maker_image|small_image|large_image|scene_entitlement|header|world_map|clans|reward|heat|name|description\n" |
| out_file.write(header) |
|
|
| |
| flag_file.write("file_name|lang|problem_field|text\n") |
|
|
| |
| for file in glob.glob(os.path.join(folder_path, "*.odc")): |
| try: |
| |
| tree = ET.parse(file) |
| root = tree.getroot() |
|
|
| |
| def clean_text(text): |
| if text: |
| |
| return text.replace('\n', '').strip() |
| return '' |
|
|
| |
| hdk_version = root.attrib.get('hdk_version', '') |
| version = root.find('version').text if root.find('version') is not None else '' |
| uuid = root.find('uuid').text if root.find('uuid') is not None else '' |
| timestamp = root.find('timestamp').text if root.find('timestamp') is not None else '' |
|
|
| |
| name_defaults = {lang: 'false' for lang in langs} |
| description_defaults = {lang: 'false' for lang in langs} |
| names = {lang: '' for lang in langs} |
| descriptions = {lang: '' for lang in langs} |
|
|
| |
| for name in root.findall('name'): |
| lang = name.get('lang', '') |
| default = name.get('default', 'false') |
| if lang in name_defaults: |
| name_defaults[lang] = default |
|
|
| for description in root.findall('description'): |
| lang = description.get('lang', '') |
| default = description.get('default', 'false') |
| if lang in description_defaults: |
| description_defaults[lang] = default |
|
|
| entitlement_ids = {territory: '' for territory in territories} |
| category_ids = {territory: '' for territory in territories} |
| product_ids = {territory: '' for territory in territories} |
|
|
| for entitlement in root.findall('entitlements/entitlement_id'): |
| territory = entitlement.get('territory', '') |
| value = clean_text(entitlement.text) |
| entitlement_ids[territory] = value |
|
|
| for category in root.findall('entitlements/category_id'): |
| territory = category.get('territory', '') |
| value = clean_text(category.text) |
| category_ids[territory] = value |
|
|
| for product in root.findall('entitlements/product_id'): |
| territory = product.get('territory', '') |
| value = clean_text(product.text) |
| product_ids[territory] = value |
|
|
| maker = clean_text(root.find('maker').text) if root.find('maker') is not None else '' |
| maker = re.sub(r'\s+', ' ', maker).strip() |
| maker_image = root.find('maker_image').text.replace('[THUMBNAIL_ROOT]', '') if root.find('maker_image') is not None else '' |
|
|
| small_images = {lang: '' for lang in langs} |
| large_images = {lang: '' for lang in langs} |
| default_small_image = None |
| default_large_image = None |
|
|
| for small_img in root.findall('small_image'): |
| lang = small_img.get('lang', '') |
| default = small_img.get('default', 'false') |
| image = small_img.text.replace('[THUMBNAIL_ROOT]', '') if small_img.text else '' |
| if lang in small_images: |
| small_images[lang] = image |
| if default == 'true' and default_small_image is None: |
| default_small_image = image |
|
|
| for large_img in root.findall('large_image'): |
| lang = large_img.get('lang', '') |
| default = large_img.get('default', 'false') |
| image = large_img.text.replace('[THUMBNAIL_ROOT]', '') if large_img.text else '' |
| if lang in large_images: |
| large_images[lang] = image |
| if default == 'true' and default_large_image is None: |
| default_large_image = image |
|
|
| |
| if not default_small_image: |
| default_small_image = next((img for img in small_images.values() if img), '') |
| if not default_large_image: |
| default_large_image = next((img for img in large_images.values() if img), '') |
|
|
| data_components = {} |
|
|
| for data in root.findall('data'): |
| component_name = data.get('component', '') |
| elements = [f"{elem.get('name', '')}={clean_text(elem.text)}" for elem in data.findall('element')] |
| data_components[component_name] = '/'.join(elements) |
|
|
| heat_element = root.find('heat') |
| heat_values_present = False |
| heat_values = {key: 'n/a' for key in ['main', 'host', 'vram', 'ppu', 'net']} |
|
|
| if heat_element is not None and len(heat_element) > 0: |
| for elem in heat_element: |
| if elem.text: |
| heat_values[elem.tag] = elem.text |
| heat_values_present = True |
|
|
| heat_data = '' |
| if heat_values_present: |
| heat_data = '/'.join([f"{key}={value}" for key, value in heat_values.items()]) |
|
|
| for name in root.findall('name'): |
| lang = name.get('lang', '') |
| if lang in names: |
| name_text = clean_text(name.text) |
| name_text = replace_special_quotes(name_text) |
| |
| name_text = re.sub(r'\s+', ' ', name_text) |
| names[lang] = name_text |
|
|
| for description in root.findall('description'): |
| lang = description.get('lang', '') |
| if lang in descriptions: |
| description_text = clean_text(description.text) |
| description_text = replace_special_quotes(description_text) |
| |
| description_text = description_text.replace('\n', '') |
| |
| description_text = description_text.replace('\\n', '\\\\n') |
| |
| description_text = re.sub(r'\\\s+n', '\\n', description_text) |
| |
| description_text = re.sub(r'\\\s+N', '\\n', description_text) |
| |
| description_text = re.sub(r'(\\\\n)\s+(\\\\n)', '\\1\\2', description_text) |
| |
| |
| |
| description_text = re.sub(r'\s+', ' ', description_text) |
| |
| description_text = description_text.replace('\\\\n', '\\n') |
| descriptions[lang] = description_text |
|
|
| |
| for lang in langs: |
| if name_defaults[lang] == 'true' and (description_defaults[lang] == 'false' or description_defaults[lang] == ''): |
| description_defaults[lang] = 'true' |
| if description_defaults[lang] == 'true' and (name_defaults[lang] == 'false' or name_defaults[lang] == ''): |
| name_defaults[lang] = 'true' |
|
|
| |
| for lang in langs: |
| name = names.get(lang, '') |
| description = descriptions.get(lang, '') |
|
|
| if count_quotation_marks(name) % 2 != 0: |
| flag_file.write(f"{os.path.basename(file)}|{lang}|name|{name}\n") |
| if count_quotation_marks(description) % 2 != 0: |
| flag_file.write(f"{os.path.basename(file)}|{lang}|description|{description}\n") |
|
|
| |
| for lang in langs: |
| territory = lang_to_territory.get(lang, '') |
| entitlement_id = entitlement_ids.get(territory, '') |
| category_id = category_ids.get(territory, '') |
| product_id = product_ids.get(territory, '') |
| name = names.get(lang, '') |
| description = descriptions.get(lang, '') |
|
|
| small_image_lang = small_images.get(lang) or default_small_image |
| large_image_lang = large_images.get(lang) or default_large_image |
|
|
| default_value = f"name={name_defaults[lang]}/description={description_defaults[lang]}" |
| data_component_values = '|'.join([data_components.get(comp, '') for comp in ['scene_entitlement', 'header', 'world_map', 'clans', 'reward']]) |
| line = f"{os.path.basename(file)}|{hdk_version}|{version}|{uuid}|{timestamp}|{lang}|{default_value}|{territory}|{entitlement_id}|{category_id}|{product_id}|{maker}|{maker_image}|{small_image_lang}|{large_image_lang}|{data_component_values}|{heat_data}|{name}|{description}\n" |
| out_file.write(line) |
| except ET.ParseError: |
| |
| print(f"Error parsing file: {file}") |
|
|
| return output_file |
|
|
| def parse_age_ratings(folder_path): |
| output_file = "ageratings.txt" |
| max_age_ratings = 0 |
| file_data = [] |
|
|
| for file in glob.glob(os.path.join(folder_path, "**", "*.odc"), recursive=True): |
| try: |
| print(f"Processing file: {file}") |
| tree = ET.parse(file) |
| root = tree.getroot() |
| legal = root.find('legal') |
|
|
| age_ratings = [] |
| if legal is not None: |
| age_ratings = ["/".join([f"{attr}={age_rating.get(attr)}" for attr in age_rating.keys()]) |
| for age_rating in legal.findall('age_rating')] |
| max_age_ratings = max(max_age_ratings, len(age_ratings)) |
|
|
| file_data.append((os.path.basename(file), age_ratings)) |
| except ET.ParseError: |
| print(f"Error parsing file: {file}") |
|
|
| with open(output_file, "w", encoding="utf-8") as out_file: |
| header = ["file_name"] + [f"age_rating_{i+1}" for i in range(max_age_ratings)] |
| out_file.write("|".join(header) + "|\n") |
|
|
| for filename, age_ratings in file_data: |
| age_ratings += [""] * (max_age_ratings - len(age_ratings)) |
| out_file.write(f"{filename}|{'|'.join(age_ratings)}|\n") |
|
|
| return output_file |
|
|
|
|
| |
| if __name__ == "__main__": |
| current_directory = os.getcwd() |
| target_folder = "ODCsDecrypted" |
| full_path = os.path.join(current_directory, target_folder) |
| |
| |
| output_data = parse_age_ratings(full_path) |
|
|
| input("Done. Press Enter to exit.") |
|
|
|
|