This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 24th, 2013  |  syntax: None  |  size: 2.51 KB  |  views: 152  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import re, urllib, os, unicodedata
  2. from xml.dom import minidom
  3.  
  4.  
  5. # Edit these variables
  6. publicid = "gabelogannewell" # If you're unsure, go to the community tab on Steam; it's the part of the URL after /id/
  7. lnkloc = "D:\Steam\shortcuts" # Where you want to save your shortcuts, will be created if it does not exist
  8. steamloc = "D:\Steam" # Your Steam directory
  9. # Stop editing here
  10.  
  11.  
  12.  
  13.  
  14. # Profile URL to your game list
  15. url = "http://steamcommunity.com/id/" + publicid + "/games?xml=1"
  16. dom = minidom.parse(urllib.urlopen(url)) # parses the xml
  17.  
  18. # File containing icon information
  19. f = open( os.path.join(steamloc,"appcache/appinfo.vdf") ,"rb")
  20. fdata = f.read() # Reads all the data to memory
  21. iterator = re.finditer('\x00\x02',fdata) # Creates iterator for pieces
  22.  
  23. # Regex patterns to detect games and their icon paths
  24. namepat = re.compile('\x00([0-9]+)\x00')
  25. icopat = re.compile('\x01clienticon\x00(.+?)\x00')
  26.  
  27. lastpos = 0
  28. ico_db = {}
  29.  
  30. # Creates the lnkloc directory if it doesn't exist already
  31. if not os.path.exists(lnkloc):
  32.     os.makedirs(lnkloc)
  33.  
  34. # Goes through appinfo.vdf and creates a database of icons
  35. for match in iterator:
  36.  
  37.     # Searches piece for a game
  38.     app = namepat.search(fdata, lastpos, match.start() )
  39.     ico = icopat.search(fdata, lastpos, match.start() )
  40.     lastpos = match.end() # Updates position in the file
  41.    
  42.     if ico != None and app != None: # If icon was found
  43.         ico_db[app.group(1)] = ico.group(1) # add to db
  44.            
  45. for game in dom.getElementsByTagName("game"):
  46.     # Gets the appid's and names from the xml
  47.     appid = game.getElementsByTagName('appID')[0].childNodes[0].nodeValue
  48.     name = game.getElementsByTagName('name')[0].childNodes[0].nodeValue
  49.  
  50.     # Gets rid of illegal filename characters from the game name
  51.     name = re.sub('[\\/:"*?<>|\xae]','',name)
  52.     # Removes all unicode characters, will lead to certain shortcuts looking odd
  53.     # Example: Warhammer 40,000TM Dawn of War II
  54.     name = unicodedata.normalize('NFKD', name).encode('ascii','ignore')
  55.  
  56.  
  57.     ico = name+".ico"
  58.     if ico_db.has_key(appid): # Gets icon if it exists in db
  59.         ico = ico_db[appid]+".ico"
  60.  
  61.     # Creates an link file in the chosen folder
  62.     lnk_f = open( os.path.join(lnkloc,name+".url") , 'w' )
  63.     lnk_f.write("[InternetShortcut]\n")
  64.     lnk_f.write("URL=steam://rungameid/"+appid+"\n")
  65.     lnk_f.write("IconFile=" + os.path.join(steamloc,"steam\games",ico) + "\n")
  66.     lnk_f.write("IconIndex=0")
  67.     lnk_f.close()    
  68.            
  69. f.close()
clone this paste RAW Paste Data