Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## REQUIRED SETTINGS !!!
- #Use forward slashes / instead ob backslashes \
- LBDIR = "E:/LaunchBox/Data/"
- LBIMGDIR = "E:/LaunchBox/Images/"
- VIDEOSNAPSDIR = "Z:/Snaps/"
- ## END REQUIRED SETTINGS !!!
- import os
- import untangle
- import fnmatch
- import array
- print 'LaunchBox 2 AEL by Ize'
- print ''
- print 'Parsing Platforms:'
- print ''
- def recursive_glob(treeroot, pattern):
- results = []
- for base, dirs, files in os.walk(treeroot):
- goodfiles = fnmatch.filter(files, pattern)
- results.extend(os.path.join(base, f) for f in goodfiles)
- return results
- #parse platforms
- p = untangle.parse('Platforms.xml')
- for platform in p.LaunchBox.Platform:
- myImages = []
- myImages = recursive_glob(LBIMGDIR + platform.Name.cdata, '*.*')
- f = open("LB2AEL_" + platform.Name.cdata + "_roms.json", 'w')
- f.write('{\n')
- print platform.Name.cdata
- #Parse roms
- pPath = 'Platforms/' + platform.Name.cdata + '.xml'
- g = untangle.parse(pPath)
- gameCount = 0
- for game in g.LaunchBox.Game:
- gameCount += 1
- curGame = 0
- for game in g.LaunchBox.Game:
- curGame += 1
- f.write(' "' + game.ID.cdata + '":{\n')
- f.write(' "altapp":"",\n')
- f.write(' "altarg":"",\n')
- f.write(' "filename":"' + game.ApplicationPath.cdata.replace('\\','\\\\') + '",\n')
- f.write(' "finished":' + game.Completed.cdata + ',\n')
- f.write(' "id":"' + game.ID.cdata + '",\n')
- f.write(' "m_genre":"' + game.Genre.cdata.replace(";", " / ") + '",\n')
- f.write(' "m_name":"' + game.Title.cdata.encode('utf-8') + '",\n')
- f.write(' "m_plot":"",\n')
- f.write(' "m_rating":"",\n')
- f.write(' "m_studio":"",\n')
- f.write(' "m_year":"",\n')
- f.write(' "nointro_status":"None",\n')
- f.write(' "s_banner":"",\n')
- f.write(' "s_boxback":"",\n')
- badName = game.Title.cdata.encode('utf-8-sig')
- frontBoxes = [s for s in myImages if "Box - Front" in s]
- frontBoxesGame = [s for s in frontBoxes if game.Title.cdata.replace(":", "_") in s]
- if not frontBoxesGame:
- frontBoxesGame.extend([""])
- frontBoxGameString = '/'.join(frontBoxesGame[0].encode('utf').split('\\'))
- frontBoxGameString = frontBoxGameString.replace("/","\\\\")
- f.write(' "s_boxfront":"' + frontBoxGameString + '",\n')
- f.write(' "s_cartridge":"",\n')
- f.write(' "s_clearlogo":"",\n')
- FanArt = [s for s in myImages if "Fanart" in s]
- FanArtGame = [s for s in FanArt if game.Title.cdata.replace(":", "_") in s]
- if not FanArtGame:
- FanArtGame.extend([""])
- FanArtGameString = '/'.join(FanArtGame[0].encode('utf').split('\\'))
- FanArtGameString = FanArtGameString.replace("/","\\\\")
- f.write(' "s_fanart":"' + FanArtGameString + '",\n')
- f.write(' "s_flyer":"",\n')
- f.write(' "s_manual":"",\n')
- f.write(' "s_map":"",\n')
- f.write(' "s_snap":"",\n')
- f.write(' "s_title":"",\n')
- mySnap = VIDEOSNAPSDIR + platform.Name.cdata + "/" + game.Title.cdata.replace(":", "_") + ".mp4"
- mySnap = mySnap.replace("/","\\\\")
- f.write(' "s_trailer":"' + mySnap.encode('utf') + '"\n') #comment this line and uncomment the next if you don't want this
- #f.write(' "s_trailer":""\n')
- if curGame == gameCount:
- f.write(' }\n')
- else:
- f.write(' },\n')
- f.write('}\n')
- f.close()
- print ''
- print 'Done.'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement