Advertisement
Guest User

Convert LaunchBox DB data to advanced emulator launcher kodi

a guest
Oct 29th, 2016
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.22 KB | None | 0 0
  1. ## REQUIRED SETTINGS !!!
  2. #Use forward slashes / instead ob backslashes \
  3. LBDIR = "E:/LaunchBox/Data/"
  4. LBIMGDIR = "E:/LaunchBox/Images/"
  5. VIDEOSNAPSDIR = "Z:/Snaps/"
  6. ## END REQUIRED SETTINGS !!!
  7.  
  8. import os
  9. import untangle
  10. import fnmatch
  11. import array
  12.  
  13. print 'LaunchBox 2 AEL by Ize'
  14. print ''
  15. print 'Parsing Platforms:'
  16. print ''
  17.  
  18. def recursive_glob(treeroot, pattern):
  19.     results = []
  20.     for base, dirs, files in os.walk(treeroot):
  21.         goodfiles = fnmatch.filter(files, pattern)
  22.         results.extend(os.path.join(base, f) for f in goodfiles)
  23.     return results
  24.  
  25. #parse platforms
  26. p = untangle.parse('Platforms.xml')
  27.  
  28. for platform in p.LaunchBox.Platform:
  29.  myImages = []
  30.  myImages = recursive_glob(LBIMGDIR + platform.Name.cdata, '*.*')
  31.  f = open("LB2AEL_" + platform.Name.cdata + "_roms.json", 'w')
  32.  f.write('{\n')
  33.  print platform.Name.cdata
  34.  
  35.  #Parse roms
  36.  pPath = 'Platforms/' + platform.Name.cdata + '.xml'
  37.  g = untangle.parse(pPath)
  38.  
  39.  gameCount = 0
  40.  for game in g.LaunchBox.Game:
  41.   gameCount += 1
  42.  
  43.  curGame = 0
  44.  for game in g.LaunchBox.Game:
  45.   curGame += 1
  46.   f.write(' "' + game.ID.cdata + '":{\n')
  47.   f.write('  "altapp":"",\n')
  48.   f.write('  "altarg":"",\n')
  49.   f.write('  "filename":"' + game.ApplicationPath.cdata.replace('\\','\\\\') + '",\n')
  50.   f.write('  "finished":' + game.Completed.cdata + ',\n')
  51.   f.write('  "id":"' + game.ID.cdata + '",\n')
  52.   f.write('  "m_genre":"' + game.Genre.cdata.replace(";", " / ") + '",\n')
  53.   f.write('  "m_name":"' + game.Title.cdata.encode('utf-8') + '",\n')
  54.   f.write('  "m_plot":"",\n')
  55.   f.write('  "m_rating":"",\n')
  56.   f.write('  "m_studio":"",\n')
  57.   f.write('  "m_year":"",\n')
  58.   f.write('  "nointro_status":"None",\n')
  59.   f.write('  "s_banner":"",\n')
  60.   f.write('  "s_boxback":"",\n')
  61.   badName = game.Title.cdata.encode('utf-8-sig')
  62.   frontBoxes = [s for s in myImages if "Box - Front" in s]
  63.   frontBoxesGame = [s for s in frontBoxes if game.Title.cdata.replace(":", "_") in s]
  64.   if not frontBoxesGame:
  65.    frontBoxesGame.extend([""])
  66.   frontBoxGameString = '/'.join(frontBoxesGame[0].encode('utf').split('\\'))
  67.   frontBoxGameString = frontBoxGameString.replace("/","\\\\")
  68.   f.write('  "s_boxfront":"' + frontBoxGameString + '",\n')
  69.   f.write('  "s_cartridge":"",\n')
  70.   f.write('  "s_clearlogo":"",\n')
  71.   FanArt = [s for s in myImages if "Fanart" in s]
  72.   FanArtGame = [s for s in FanArt if game.Title.cdata.replace(":", "_") in s]      
  73.   if not FanArtGame:
  74.    FanArtGame.extend([""])  
  75.   FanArtGameString = '/'.join(FanArtGame[0].encode('utf').split('\\'))
  76.   FanArtGameString = FanArtGameString.replace("/","\\\\")    
  77.   f.write('  "s_fanart":"' + FanArtGameString + '",\n')
  78.   f.write('  "s_flyer":"",\n')
  79.   f.write('  "s_manual":"",\n')
  80.   f.write('  "s_map":"",\n')
  81.   f.write('  "s_snap":"",\n')
  82.   f.write('  "s_title":"",\n')
  83.   mySnap = VIDEOSNAPSDIR + platform.Name.cdata + "/" + game.Title.cdata.replace(":", "_") + ".mp4"
  84.   mySnap = mySnap.replace("/","\\\\")      
  85.   f.write('  "s_trailer":"' + mySnap.encode('utf') + '"\n') #comment this line and uncomment the next if you don't want this
  86.   #f.write('  "s_trailer":""\n')
  87.   if curGame == gameCount:
  88.    f.write(' }\n')
  89.   else:
  90.    f.write(' },\n')
  91.  f.write('}\n')  
  92.  f.close()
  93. print ''
  94. print 'Done.'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement