Last active
August 19, 2020 02:37
-
-
Save einstein95/821e76b2c66d775f7f14afbdbc18c538 to your computer and use it in GitHub Desktop.
Get game URLs from Kongregate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import re | |
import requests | |
import uuid | |
from sys import argv, exit | |
from urllib.parse import unquote | |
PROTOCOL = 'https:' | |
if 'www.kongregate.com' not in argv[1]: | |
exit('no') | |
r = requests.get(argv[1]) | |
iframe_url, = re.findall(r"iframe_url\":(?:\'|\")([^'\"]+)", r.text) | |
if len(re.findall('channel_id', r.text)) > 6: | |
r = requests.get(iframe_url+str(uuid.uuid4())) | |
else: | |
print(iframe_url) | |
exit() | |
game_url = re.findall(r'game_swf":"([^"]+)', r.text) | |
if not game_url: | |
if 'unity_265x250.swf' in r.text: | |
game_url = re.findall(r'unityObject.embedUnity\(\\"kongregateUnityDiv\\", \\"([^\\]+)', r.text) | |
else: | |
game_url = re.findall(r'swf_location = "([^"]+)', r.text) | |
print(PROTOCOL+unquote(game_url[0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment