import re, urllib, os, unicodedata from xml.dom import minidom # Edit these variables publicid = "gabelogannewell" # If you're unsure, go to the community tab on Steam; it's the part of the URL after /id/ lnkloc = "D:\Steam\shortcuts" # Where you want to save your shortcuts, will be created if it does not exist steamloc = "D:\Steam" # Your Steam directory # Stop editing here # Profile URL to your game list url = "http://steamcommunity.com/id/" + publicid + "/games?xml=1" dom = minidom.parse(urllib.urlopen(url)) # parses the xml # File containing icon information f = open( os.path.join(steamloc,"appcache/appinfo.vdf") ,"rb") fdata = f.read() # Reads all the data to memory iterator = re.finditer('\x00\x02',fdata) # Creates iterator for pieces # Regex patterns to detect games and their icon paths namepat = re.compile('\x00([0-9]+)\x00') icopat = re.compile('\x01clienticon\x00(.+?)\x00') lastpos = 0 ico_db = {} # Creates the lnkloc directory if it doesn't exist already if not os.path.exists(lnkloc): os.makedirs(lnkloc) # Goes through appinfo.vdf and creates a database of icons for match in iterator: # Searches piece for a game app = namepat.search(fdata, lastpos, match.start() ) ico = icopat.search(fdata, lastpos, match.start() ) lastpos = match.end() # Updates position in the file if ico != None and app != None: # If icon was found ico_db[app.group(1)] = ico.group(1) # add to db for game in dom.getElementsByTagName("game"): # Gets the appid's and names from the xml appid = game.getElementsByTagName('appID')[0].childNodes[0].nodeValue name = game.getElementsByTagName('name')[0].childNodes[0].nodeValue # Gets rid of illegal filename characters from the game name name = re.sub('[\\/:"*?<>|\xae]','',name) # Removes all unicode characters, will lead to certain shortcuts looking odd # Example: Warhammer 40,000TM Dawn of War II name = unicodedata.normalize('NFKD', name).encode('ascii','ignore') ico = name+".ico" if ico_db.has_key(appid): # Gets icon if it exists in db ico = ico_db[appid]+".ico" # Creates an link file in the chosen folder lnk_f = open( os.path.join(lnkloc,name+".url") , 'w' ) lnk_f.write("[InternetShortcut]\n") lnk_f.write("URL=steam://rungameid/"+appid+"\n") lnk_f.write("IconFile=" + os.path.join(steamloc,"steam\games",ico) + "\n") lnk_f.write("IconIndex=0") lnk_f.close() f.close()