From a7774f5ea6ec00d392fe34458cb09bbadd745be2 Mon Sep 17 00:00:00 2001 From: fa0311 Date: Sat, 12 Mar 2022 05:20:09 +0900 Subject: [PATCH] =?UTF-8?q?add=20product=5Fid=20=E3=81=AE=E3=81=BF?= =?UTF-8?q?=E3=81=A7=E8=B5=B7=E5=8B=95=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DMMGamePlayerFastLauncher.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/DMMGamePlayerFastLauncher.py b/DMMGamePlayerFastLauncher.py index ce94360..103c1bc 100644 --- a/DMMGamePlayerFastLauncher.py +++ b/DMMGamePlayerFastLauncher.py @@ -2,6 +2,8 @@ import requests import argparse import re +import json +import glob requests.packages.urllib3.disable_warnings() @@ -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 = { @@ -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, @@ -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]])