From 5cd69b1cbcdacd1e8ab41b5558f0108ec953c797 Mon Sep 17 00:00:00 2001 From: James H Date: Tue, 26 Nov 2024 22:57:51 +0000 Subject: [PATCH] Add retroarch playlist generator script --- retroarch_playlist_generator.py | 73 +++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 retroarch_playlist_generator.py diff --git a/retroarch_playlist_generator.py b/retroarch_playlist_generator.py new file mode 100644 index 0000000..415d116 --- /dev/null +++ b/retroarch_playlist_generator.py @@ -0,0 +1,73 @@ +import os +import sys +import re + +args = sys.argv + +if len(args) < 2: + print('need to pass path!') + exit() + +if len(args) < 3: + print('need to pass dbname!') + +path = args[1] +dbname = args[2] + +extfilter = [] +if len(args) >= 4: + extfilters = args[3].split(',') + +print('Arg Path: {}'.format(path)) +print('DB Name: {}'.format(dbname)) +print('Ext Filters: {}'.format(extfilters)) + +output = '''{ + "version": "1.2", + "default_core_path": "", + "default_core_name": "", + "label_display_mode": 0, + "right_thumbnail_mode": 0, + "left_thumbnail_mode": 0, + "items": [\n%ITEMS%] +} +''' + +itemstr = '' + +for root, dirs, files in os.walk(path): + for filename in sorted(files): + filepath = '{}\\{}'.format(root, filename) + filepath = filepath.replace('/', '\\') + filepath = filepath.replace('\\', '\\\\') + + if len(extfilters) != 0 and not os.path.splitext(os.path.basename(filepath))[1] in extfilters: + continue + + label = os.path.splitext(os.path.basename(filepath))[0] + label = label.replace(' [!]', '') + label = re.sub(r'^\d{4} - ', '', label) + core_path = 'DETECT' + core_name = 'DETECT' + crc32 = '00000000|crc' + + itemstr += ''' { + "path": "%PATH%", + "label": "%LABEL%", + "core_path": "%COREPATH%", + "core_name": "%CORENAME%", + "crc32": "%CRC%", + "db_name": "%DBNAME%" + },\n''' + itemstr = itemstr.replace('%PATH%', filepath) + itemstr = itemstr.replace('%LABEL%', label) + itemstr = itemstr.replace('%COREPATH%', core_path) + itemstr = itemstr.replace('%CORENAME%', core_name) + itemstr = itemstr.replace('%CRC%', crc32) + itemstr = itemstr.replace('%DBNAME%', dbname) + +output = output.replace('%ITEMS%', itemstr) + +with open('{}'.format(dbname), 'wt') as out_file: + out_file.write(output) + \ No newline at end of file