Skip to content

Commit

Permalink
add product_id のみで起動できるように
Browse files Browse the repository at this point in the history
  • Loading branch information
fa0311 committed Mar 11, 2022
1 parent 758a4da commit a7774f5
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions DMMGamePlayerFastLauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import requests
import argparse
import re
import json
import glob

requests.packages.urllib3.disable_warnings()

Expand All @@ -12,13 +14,14 @@
)

argpar.add_argument("product_id")
argpar.add_argument("game_path")
argpar.add_argument("--game-path", default=False)
argpar.add_argument(
"-dgp-path",
"--dmmgameplayer-path",
default="C:/Program Files/DMMGamePlayer/DMMGamePlayer.exe",
)
argpar.add_argument("--kill", default=True)
argpar.add_argument("--debug", default=False)
arg = argpar.parse_args()

headers = {
Expand All @@ -40,24 +43,30 @@
"user_os": "win",
}


def get_dmm_cookie():
def dgp5_session():
process = subprocess.Popen(
args="", executable=arg.dmmgameplayer_path, shell=True, stdout=subprocess.PIPE
)
for line in process.stdout:
text = line.decode("utf8").strip()
if arg.debug:
print(text)
if 'Parsing json string is ' in text:
install_data = json.loads(text.lstrip("Parsing json string is ").rstrip("."))
if 'Header key: "cookie"' in text:
cookie = re.findall(r'"(.*?)"', text)[1]
if arg.kill:
process.terminate()
return re.findall(r'"(.*?)"', text)[1]
return install_data, cookie
raise Exception("DMMGamePlayerが起動できませんでした")

install_data, headers["cookie"] = dgp5_session()

dmm_cookie = get_dmm_cookie()
if dmm_cookie == None:
raise Exception("DMMGamePlayerが起動できませんでした\nDMMGamePlayerがすでに起動されている可能性があります")
if not arg.game_path:
for contents in install_data["contents"]:
if contents["productId"] == arg.product_id:
game_path = glob.glob('{path}\*.exe._'.format(path=contents['detail']['path']))[0][:-2]

headers["cookie"] = dmm_cookie
response = requests.session().post(
"https://apidgp-gameplayer.games.dmm.com/v5/launch/cl",
headers=headers,
Expand All @@ -66,4 +75,4 @@ def get_dmm_cookie():
)
dmm_args = response.json()["data"]["execute_args"].split(" ")

subprocess.Popen([arg.game_path, dmm_args[0], dmm_args[1]])
subprocess.Popen([game_path, dmm_args[0], dmm_args[1]])

0 comments on commit a7774f5

Please sign in to comment.