Guest User

Untitled

a guest
Sep 2nd, 2018
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.08 KB | None | 0 0
  1. #!/usr/bin/python3
  2. import subprocess
  3. import os
  4. import requests
  5. import re
  6. import sys
  7. from fuzzywuzzy import fuzz, process
  8.  
  9. def launch_game(title, id):
  10. """Launches Steam games with various state labels"""
  11. FNULL = open(os.devnull, 'w')
  12. state = ['Starting: ', 'Installing: ', 'Streaming: ']
  13. if check_installed(str(id)):
  14. print(state[0] + title)
  15. subprocess.call(['steam', f'steam://rungameid/{id}'], stdout=FNULL, stderr=subprocess.STDOUT)
  16. if not check_installed(str(id)):
  17. print(f'{title} is not installed!')
  18. print(state[1] + title)
  19. subprocess.call(['steam', f'steam://rungameid/{id}'], stdout=FNULL, stderr=subprocess.STDOUT)
  20.  
  21. def get_library(username):
  22. """Requests all game titles and ID's from a users Steam library. (PROFILE MUST BE PUBLIC)"""
  23. resp = requests.get(f"https://steamcommunity.com/id/{username}/games?tab=all&xml=1")
  24. gamelist = {name: uuid for uuid, name in re.findall(r'"appid":(\d+),"name":"([^"]+)"', resp.text)}
  25. return gamelist
  26.  
  27. def check_installed(uinput):
  28. """Looks to see if a game is installed or not, by checking Steam manifests"""
  29. manifests = str(subprocess.check_output(['ls', '/home/mtothem/.local/share/Steam/steamapps']))
  30. if uinput in manifests:
  31. return True
  32. else:
  33. return False
  34.  
  35. def fuzzresult(user_input, games):
  36. """Compares user input to the game library, then returns a tuple pair with the closest title, and it's match ratio."""
  37. (name, percentage) = process.extractOne(user_input, games)
  38. return name, percentage
  39.  
  40. def steamlist():
  41. """Pulls the users steam library if it's not present"""
  42. steamlist = {'ShareX': '400040', 'Factorio': '427520', 'Worms Reloaded': '22600', 'The Witcher 3: Wild Hunt': '292030', 'Terraria': '105600', 'The Elder Scrolls III: Morrowind': '22320', 'PAYDAY 2': '218620', 'Counter-Strike: Global Offensive': '730', 'Deus Ex: Mankind Divided\\u2122': '337000', 'The Elder Scrolls V: Skyrim': '72850', "PLAYERUNKNOWN'S BATTLEGROUNDS": '578080', 'Deus Ex: Game of the Year Edition': '6910', 'Borderlands 2': '49520', 'Counter-Strike: Source': '240', 'Eco': '382310', 'Stardew Valley': '413150', 'Grand Theft Auto IV': '12210', 'ArcheAge': '304030', 'Portal 2': '620', 'Left 4 Dead 2': '550', 'Rust': '252490', 'Worms Armageddon': '217200', 'Path of Exile': '238960', 'Warhammer: End Times - Vermintide': '235540', "Shadowrun: Dragonfall - Director's Cut": '300550', 'Global Agenda': '17020', 'Starbound': '211820', "Garry's Mod": '4000', 'Wallpaper Engine': '431960', 'Battlefield: Bad Company 2': '24960', 'Shovel Knight: Treasure Trove': '250760', 'Saints Row: The Third': '55230', 'Day of Defeat: Source': '300', 'Loadout': '208090', 'Worms Ultimate Mayhem': '70600', 'RimWorld': '294100', 'Moonlighter': '606150', 'Magic: The Gathering \\u2014 Duels of the Planeswalkers 2012': '49470', 'Grand Theft Auto: Episodes from Liberty City': '12220', 'Dota 2': '570', 'PAYDAY: The Heist': '24240', 'Team Fortress 2': '440', 'Call of Duty: Black Ops - Multiplayer': '42710', 'Call of Duty: Black Ops': '42700', 'The Secret of Monkey Island: Special Edition': '32360', 'Tabletop Simulator': '286160', 'POSTAL 2': '223470', 'War Thunder': '236390', 'Trine': '35700', 'Golf With Your Friends': '431240', 'Windward': '326410', 'PlanetSide 2': '218230', 'Magicka 2': '238370', 'Metro 2033': '43110', 'Half-Life 2: Deathmatch': '320', 'The Elder Scrolls V: Skyrim Special Edition': '489830', 'Counter-Strike': '10', 'The Elder Scrolls IV: Oblivion ': '22330', 'Alice: Madness Returns': '19680', 'Half-Life 2: Episode One': '380', 'Warhammer: Vermintide 2': '552500', 'NEKOPARA Vol. 0': '385800', 'SMITE': '386360', 'Planetary Annihilation': '233250', 'NightSky': '99700', 'Gemini Rue': '80310', 'Lead and Gold - Gangs of the Wild West': '42120', 'Hotline Miami': '219150', 'Dead Cells': '588650', 'Reigns': '474750', 'Crayon Physics Deluxe': '26900', 'Super Meat Boy': '40800', "Recettear: An Item Shop's Tale": '70400', 'Legend of Grimrock': '207170', 'Warframe': '230410', 'VRChat': '438100', 'Hero Siege': '269210', 'Portal': '400', 'Max and the Magic Marker': '50820', 'DOOM': '379720', 'Cave Story+': '200900', 'VVVVVV': '70300', 'Human Resource Machine': '375820', 'Deponia': '214340', 'Worms Revolution': '200170', 'Half-Life': '70', 'Cthulhu Saves the World ': '107310', 'Ricochet': '60', 'Half-Life 2': '220', 'Atom Zombie Smasher ': '55040', 'Alien Swarm': '630', 'Jamestown': '94200', 'Hitman: Blood Money': '6860', 'The Binding of Isaac': '113200', 'Ghost in the Shell: Stand Alone Complex - First Assault Online': '369200', 'Gish': '9500', 'DiRT Showdown': '201700', 'World of Goo': '22000', 'Worms W.M.D': '327030', "Sid Meier's Civilization V": '8930', 'Insurgency': '222880', 'Shadowrun Returns': '234650', 'Chivalry: Medieval Warfare': '219640', 'Dungeons of Dredmor': '98800', 'Company of Heroes ': '228200', 'Undertale': '391540', 'Puzzle Agent': '31270', 'Unturned': '304930', 'Risen': '40300', 'PC Gamer': '92500', 'Shank': '6120', 'Dead Island': '91310', 'Cogs': '26500', 'Amnesia: A Machine for Pigs': '239200', 'The Witcher: Enhanced Edition': '20900', 'Kerbal Space Program': '220200', 'Uplink': '1510', 'Team Fortress Classic': '20', 'Blocks That Matter': '111800', 'Offspring Fling!': '211360', 'Breath of Death VII ': '107300', 'Doki Doki Literature Club': '698780', 'theHunter Classic': '253710', 'KARAKARA': '487430', 'Deus Ex: Invisible War': '6920', 'Closure': '72000', 'Sanctum 2': '210770', 'BIT.TRIP RUNNER': '63710', 'Day of Defeat': '30', 'Poker Night at the Inventory': '31280', 'Never Alone (Kisima Ingitchuna)': '295790', 'Shadowgrounds': '2500', 'Jigoku Kisetsukan: Sense of the Seasons': '368950', 'NEKOPARA Vol. 1': '333600', "Oddworld: Abe's Oddysee": '15700', 'Hotline Miami 2: Wrong Number': '274170', 'Monaco': '113020', 'Guns of Icarus Online': '209080', 'Japanese School Life': '555640', 'Half-Life: Source': '280', 'And Yet It Moves': '18700', 'Skyrim Script Extender (SKSE)': '365720', 'Dungeon Defenders': '65800', 'Company of Heroes - Legacy Edition': '4560', 'Fractal: Make Blooms Not War': '61310', 'Ame no Marginal -Rain Marginal-': '348950', 'Amnesia: The Dark Descent': '57300', "Back to the Future: Ep 1 - It's About Time": '31290', 'Back to the Future: Ep 2 - Get Tannen!': '94500', 'Back to the Future: Ep 3 - Citizen Brown': '94510', 'Back to the Future: Ep 4 - Double Visions': '94520', 'Back to the Future: Ep 5 - OUTATIME': '94530', 'Bionic Commando Rearmed': '21680', 'Blender': '365670', 'Brothers - A Tale of Two Sons': '225080', 'Choice Chamber': '359960', 'Civilization V - Scrambled Continents Map Pack': '235584', 'Company of Heroes: Opposing Fronts': '9340', 'Company of Heroes: Tales of Valor': '20540', 'Cortex Command': '209670', 'Counter-Strike: Condition Zero': '80', 'Counter-Strike: Condition Zero Deleted Scenes': '100', 'Counter-Strike Nexon: Zombies': '273110', 'Crusader Kings II': '203770', 'Crusader Kings II: South Indian Portraits 5 Year Anniversary Gift': '592800', 'Darksiders': '50620', 'Darksiders Warmastered Edition': '462780', 'Darwinia': '1500', 'Deathmatch Classic': '40', 'DEFCON': '1520', 'Duke Nukem Forever': '57900', 'F1 2015': '286570', 'fault - milestone one': '286260', 'fault - milestone two side:above': '344770', 'For Honor': '304390', 'For Honor - Public Test': '654310', 'Frosty Kiss': '431540', 'Gemini: Heroes Reborn': '324650', 'Guns of Icarus Alliance': '608800', 'Hacker Evolution': '70100', 'Hacker Evolution - Untold': '70110', 'Hacker Evolution Duality': '70120', 'Hacknet': '365450', 'Half-Life 2: Episode Two': '420', 'Half-Life 2: Lost Coast': '340', 'Half-Life: Blue Shift': '130', 'Half-Life: Opposing Force': '50', 'Half-Life Deathmatch: Source': '360', "Hamilton's Great Adventure": '42140', 'Hammerfight': '41100', 'Highway Blossoms': '451760', 'Idol Magical Girl Chiru Chiru Michiru Part 1': '377710', 'Idol Magical Girl Chiru Chiru Michiru Part 2': '377720', 'Indie Game: The Movie': '207080', 'King Arthur - The Role-playing Wargame': '24400', 'Left 4 Dead': '500', 'Lost Planet 3': '226720', "Memory's Dogma CODE:01": '386970', 'Monkey Island 2: Special Edition': '32460', 'Multiwinia': '1530', 'Narcissu 10th Anniversary Anthology: Sumire': '608420', 'Narcissu 10th Anniversary Anthology Project': '426690', 'Narcissu 10th Anniversary Anthology Project - A Little Iris': '461250', 'Narcissu 10th Anniversary Anthology Project - Narcissu: Zero': '504640', 'Narcissu 10th Anniversary Anthology Project - Season Pass': '439510', 'Narcissu 10th Anniversary Soundtrack': '627310', 'NEKOPARA Vol. 2': '420110', 'Never Alone: Original Soundtrack': '351740', 'Nidhogg': '94400', 'No More Room in Hell': '224260', 'Nuclear Dawn': '17710', 'Orwell': '491950', 'Outlast': '238320', 'Puzzle Agent 2': '94590', 'Red Faction: Armageddon': '55110', 'Resident Evil Revelations 2 \\/ Biohazard Revelations 2': '287290', 'Retro City Rampage\\u2122 DX': '204630', 'Risen 2 - Dark Waters': '40390', 'Robot Roller-Derby Disco Dodgeball': '270450', 'Root Double -Before Crime * After Days- Xtend Edition': '438130', 'Rust - Staging Branch': '700580', 'Sacred 3': '247950', 'Sacred 3: Underworld Story': '261160', 'Sacred Citadel': '207930', 'Saints Row 2': '9480', 'Sam & Max 301: The Penal Zone': '31220', 'Sam & Max 302: The Tomb of Sammun-Mak': '31230', "Sam & Max 303: They Stole Max's Brain!": '31240', 'Sam & Max 304: Beyond the Alley of the Dolls': '31250', 'Sam & Max 305: The City that Dares not Sleep': '31260', 'Shadowgrounds: Survivor': '11200', 'Shank 2': '102840', 'Shoppe Keep': '381120', "Sid Meier's Civilization V: Brave New World": '235580', 'Skyrim High Resolution Texture Pack': '202485', 'Small Radios Big Televisions': '390040', 'Smite - Public Test': '858460', 'Snapshot': '204220', 'Sound of Drop - fall into poison -': '383460', 'Spec Ops: The Line': '50300', 'Starbound - Unstable': '367540', 'Steel Storm: Burning Retribution': '96200', 'Stories: The Path of Destinies': '439190', 'Strider': '235210', "Sunrider: Liberation Day - Captain's Edition": '358750', 'The Basement Collection': '214790', 'The Darkness II': '67370', 'The Elder Scrolls V: Skyrim - Dawnguard': '211720', 'The Elder Scrolls V: Skyrim - Dragonborn': '226880', 'The Elder Scrolls V: Skyrim - Hearthfire': '220760', 'The Flame in the Flood': '318600', 'The Walking Dead': '207610', 'The Witcher 2: Assassins of Kings Enhanced Edition': '20920', 'The Witcher 3: Wild Hunt - Expansion Pass': '355880', 'The Witcher 3: Wild Hunt - New Finisher Animations': '378646', 'Titan Quest': '4540', 'Titan Quest Anniversary Edition': '475150', 'Totally Accurate Battlegrounds': '823130', 'Tree of Savior (English Ver.)': '372000', 'Ultimate General: Gettysburg': '306660', 'Unreal Gold': '13250', 'Unturned - Early Access': '429881', 'Volgarr the Viking': '247240', 'Warhammer 40,000: Dawn of War - Game of the Year Edition': '4570', 'Warhammer: End Times - Vermintide Quests and Contracts': '463794', "Warhammer: End Times - Vermintide Sigmar's Blessing": '419070', 'WASTED': '327510', 'Westerado: Double Barreled': '275200', 'WORLD END ECONOMiCA episode.01': '269250', 'WORLD END ECONOMiCA episode.02': '368160', 'WORLD END ECONOMiCA episode.03': '527190'}
  43. if not steamlist:
  44. steamlist = get_library('mtothem1337')
  45. return steamlist
  46.  
  47. def determain_platform(game):
  48. """Checks which gamelist the game belongs to"""
  49. if fuzzresult(game, steamlist().keys())[1] >= 90: return 'steam'
  50. else: print("'" + game + "'" + ' were not found. :(')
  51.  
  52. def steam_launch(id):
  53. """Launches Steam games with various state labels"""
  54. FNULL = open(os.devnull, 'w')
  55. title = 'title'
  56. state = ['Starting: ', 'Installing: ', 'Streaming: ']
  57. if check_installed(str(id)):
  58. print(state[0] + title)
  59. subprocess.call(['steam', f'steam://rungameid/{id}'], stdout=FNULL, stderr=subprocess.STDOUT)
  60. if not check_installed(str(id)):
  61. print(f'{title} is not installed!')
  62. print(state[1] + title)
  63. subprocess.call(['steam', f'steam://rungameid/{id}'], stdout=FNULL, stderr=subprocess.STDOUT)
  64.  
  65. def find_steam_id(uinput):
  66. """Returns the ID of the closest match."""
  67. game = fuzzresult(uinput, steamlist().keys())[0]
  68. temp = steamlist().get(game)
  69. return temp
  70.  
  71. def userinput():
  72. argument = sys.argv[1:]
  73. string = ' '.join(argument)
  74. return string
  75.  
  76. def main():
  77. if len(sys.argv) == 1:
  78. print('usage: playboi [game] Spaces are allowed\n'
  79. 'Steam:\n'
  80. ' -r, --refresh Refreshes your steam library\n'
  81. ' -l, --list Lists your steam library, sorted alphabetically\n'
  82. ' -u, --username Displays your current steam username\n'
  83. ' -cu, --change-username Changes your steam username\n'
  84. ' -rg, --random-game Launches a random game from your steam library\n\n'
  85. 'Note that your steam library does not update manually\n\n'
  86. 'Submit feature requests and suggestions to <misc@mtothem.se>\n'
  87. 'Submit bug reports to <bugs@mtothem.se>')
  88. else:
  89. uinput = userinput()
  90. if determain_platform(uinput) == 'steam':
  91. id = find_steam_id(uinput)
  92. steam_launch(id)
  93.  
  94. main()
Add Comment
Please, Sign In to add comment