Skip to content

Commit

Permalink
recurse into cdn file 4399
Browse files Browse the repository at this point in the history
  • Loading branch information
mathgeniuszach committed Sep 3, 2024
1 parent eb081f0 commit c3db5cc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ If you are looking for command line usage, run `fpcurator --help` or `fpcurator.

The Auto Curator supports auto curating games from these websites:

- [4399](https://www.4399.com/) (Flash, Unity, or HTML5)
- [Addicting Games](https://www.addictinggames.com/) (Flash and HTML5)
- [Construct](https://www.construct.net/) (HTML5)
- [Coolmath Games](https://www.coolmathgames.com/) (HTML5)
Expand Down
53 changes: 47 additions & 6 deletions sites/c4399.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
SCREENSHOT = re.compile(r'var\s+\w+GamePic\s*=\s*"(.*?)"', re.IGNORECASE)
GAMEPATH = re.compile(r'var\s+\w+GamePath\s*=\s*"(.*?)"', re.IGNORECASE)
DIMS = re.compile(r'var\s+_w\s*=\s*(\d+);?\s*var\s+_h\s*=\s*(\d+)')
QUOTED_FILE = re.compile(rb'"([\w./-]+?\.(swf|unity3d))"')
HTML_FILES = re.compile(r'.*\.(htm|html)$')

HTML_EMBED = """<body>
<style>
Expand Down Expand Up @@ -41,7 +43,7 @@ def soupify(self):
with requests.get(self.src) as resp:
soup = bs4.BeautifulSoup(resp.content, "html.parser")
if not GAME_URL.search(self.src):
self.src = "https://wwww.4399.com" + soup.select_one(".play > a")["href"]
self.src = "https://www.4399.com" + soup.select_one(".play > a")["href"]
with requests.get(self.src) as resp:
soup = bs4.BeautifulSoup(resp.content, "html.parser")
return soup
Expand Down Expand Up @@ -115,25 +117,60 @@ def parse(self, soup):
is_html = bool(int(IS_HTML5.search(headtxt)[1]))
except:
is_html = False
# Embed and cdn files
self.embed = fpclib.normalize(self.src, False)
self.cdn = "http://sda.4399.com/4399swf" + GAMEPATH.search(headtxt)[1]
# Extra files to download
self.extra = []

# Embed dimensions
dims = DIMS.search(headtxt)
self.dims = (dims[1], dims[2])

# If the "isHTML5" flag is set, it's an html5 game.
if is_html:
self.platform = "HTML5"
self.app = fpclib.FPNAVIGATOR
self.cmd = self.embed
# Otherwise, check the ending of the file
# Flash games end in .swf
elif self.cdn.endswith(".swf"):
self.platform = "Flash"
# Unity games end in .unity3d
# I don't think a cdn file will ever end in .unity3d, but just in case, raise an error.
elif self.cdn.endswith(".unity3d"):
raise NotImplementedError("4399 embeds unity3d file directly from cdn.")
else:
# If the cdn file is something else, search for a ".swf" or ".unity3d" string inside it
with requests.get(self.cdn, headers={"referer": self.cdn}) as resp:
file = QUOTED_FILE.search(resp.content)

if file is not None:
direct_file = self.cdn[:self.cdn.rindex("/")+1] + file[1].decode("utf-8")
if file[2] == b"swf":
# swf file found embedded in the content. Try using it
self.cdn = direct_file
self.platform = "Flash"
else:
# unity3d file found embedded in the content. Mark it for download later
self.extra.append(direct_file)
self.platform = "Unity"

# Use detected platform to determine launch data
if self.platform == "HTML5":
self.app = fpclib.FPNAVIGATOR
self.cmd = self.embed
elif self.platform == "Flash":
self.app = fpclib.FLASH
self.cmd = self.cdn
self.add_app("Embedded Page", self.embed, fpclib.FPNAVIGATOR)
else:
self.platform = "Unity"
elif self.platform == "Unity":
self.app = fpclib.UNITY
self.cmd = self.embed
else:
# It's probably a Flash game
self.platform = "Flash"
self.app = fpclib.FPNAVIGATOR
self.cmd = self.embed


def get_files(self):
# Create embed file
Expand All @@ -144,4 +181,8 @@ def get_files(self):
fpclib.write(self.embed[self.embed.index("://")+3:], html)

# Download the game's true embedded file
fpclib.download_all((self.cdn,), spoof=True)
self.extra.append(self.cdn)
fpclib.download_all(self.extra, spoof=True)

# Replace https with http in html cdn files
fpclib.replace(fpclib.scan_dir('', HTML_FILES)[0], 'https:', 'http:')
2 changes: 1 addition & 1 deletion sites/defs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1725346764.5213957
1725396838.9561567
AddictingGames.py
Construct.py
CoolmathGames.py
Expand Down

0 comments on commit c3db5cc

Please sign in to comment.