You've already forked KemoFureApi
Compare commits
23 Commits
0ce68c606f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 577411fadf | |||
| a51c8117d0 | |||
| b5d63d1d00 | |||
| 11edbf3abf | |||
| 3f8f9f708f | |||
| 18aa1843cd | |||
| 8733294f13 | |||
| fee0ecfe75 | |||
| fb4ad30d03 | |||
| 2623106212 | |||
| 16c7792b7f | |||
| 2a852388bf | |||
| 50559223ed | |||
| 6b0de05a80 | |||
| 155394ab75 | |||
| 794bf9d30b | |||
| 6157eb1e40 | |||
| db728f21ba | |||
| cbe0074c70 | |||
| 3a247d6ce1 | |||
| e7d21a90bb | |||
| 8b12ca9dae | |||
| 76b6c6cb79 |
6
app.py
6
app.py
@@ -3,7 +3,7 @@ from flask_restful import Api
|
|||||||
|
|
||||||
from modules.KF3.database import Database as KF3DB
|
from modules.KF3.database import Database as KF3DB
|
||||||
from modules.Kingdom.database import Database as KFKDB
|
from modules.Kingdom.database import Database as KFKDB
|
||||||
from modules.Archive.database import Database as KFADB
|
from modules.proxy import AgreementProxy, LaunchProxy, UpdateProxy
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['JSON_AS_ASCII'] = False
|
app.config['JSON_AS_ASCII'] = False
|
||||||
@@ -11,9 +11,11 @@ app.databases = {}
|
|||||||
|
|
||||||
api = Api(app)
|
api = Api(app)
|
||||||
|
|
||||||
|
api.add_resource(LaunchProxy, "/DMM/launch")
|
||||||
|
api.add_resource(UpdateProxy, "/DMM/filelist", "/DMM/update")
|
||||||
|
api.add_resource(AgreementProxy, "/DMM/agreement")
|
||||||
KF3DB(api)
|
KF3DB(api)
|
||||||
KFKDB(api)
|
KFKDB(api)
|
||||||
KFADB(api)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='127.0.0.1', port=8080, debug=True)
|
app.run(host='127.0.0.1', port=8080, debug=True)
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import json
|
|
||||||
from .databaseController import DatabaseController
|
|
||||||
from .endpoints.query import Archive_Query
|
|
||||||
|
|
||||||
class Database:
|
|
||||||
db : DatabaseController = None
|
|
||||||
processed_friends = {}
|
|
||||||
item_stages = {}
|
|
||||||
|
|
||||||
def __init__(self, api) -> None:
|
|
||||||
app = api.app
|
|
||||||
if "Archive" in app.databases:
|
|
||||||
del app.databases["Archive"]
|
|
||||||
|
|
||||||
self.reload_data()
|
|
||||||
|
|
||||||
app.databases["Archive"] = self
|
|
||||||
|
|
||||||
api.add_resource(Archive_Query, "/Archive/Query")
|
|
||||||
|
|
||||||
def reload_data(self):
|
|
||||||
self.db = DatabaseController("/home/pi/python/Katbots/JapariArchive/database.db")
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
import os
|
|
||||||
import sqlite3
|
|
||||||
|
|
||||||
TABLE_ACCOUNTS = "accounts"
|
|
||||||
TABLE_X = "x_posts"
|
|
||||||
|
|
||||||
class DatabaseController:
|
|
||||||
def __init__(self, db_name):
|
|
||||||
self.conn = sqlite3.connect(db_name, isolation_level="DEFERRED")
|
|
||||||
self.cursor = self.conn.cursor()
|
|
||||||
|
|
||||||
def run_query(self, query):
|
|
||||||
try:
|
|
||||||
self.cursor.execute(query)
|
|
||||||
results = self.cursor.fetchall()
|
|
||||||
return results
|
|
||||||
except:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
self.conn.close()
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
import json
|
|
||||||
from flask_restful import Resource
|
|
||||||
from flask import current_app as app, jsonify
|
|
||||||
|
|
||||||
class Archive_Query(Resource):
|
|
||||||
def post(self, query:str):
|
|
||||||
db = app.databases["Archive"]
|
|
||||||
|
|
||||||
result = db.run_query(query)
|
|
||||||
|
|
||||||
if result is None:
|
|
||||||
response = app.response_class(status=400)
|
|
||||||
else:
|
|
||||||
response = app.response_class(
|
|
||||||
response=json.dumps(result, ensure_ascii=False, indent=1),
|
|
||||||
status=200,
|
|
||||||
mimetype='application/json'
|
|
||||||
)
|
|
||||||
|
|
||||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
|
||||||
return response
|
|
||||||
@@ -82,7 +82,10 @@ async def download_cache(server_name, server : str):
|
|||||||
file.write(data)
|
file.write(data)
|
||||||
with open(file_path_json, "wt", encoding="utf-8") as out_file:
|
with open(file_path_json, "wt", encoding="utf-8") as out_file:
|
||||||
data = gzip.decompress(data)
|
data = gzip.decompress(data)
|
||||||
json.dump(json.loads(data), out_file, ensure_ascii=False, indent=1)
|
data = json.loads(data)
|
||||||
|
# if key == "GACHA_DATA":
|
||||||
|
# download_banners(data, server_name)
|
||||||
|
json.dump(data, out_file, ensure_ascii=False, indent=1)
|
||||||
|
|
||||||
old_mst_ver[key] = new_mst_ver[key]
|
old_mst_ver[key] = new_mst_ver[key]
|
||||||
|
|
||||||
@@ -93,6 +96,36 @@ async def download_cache(server_name, server : str):
|
|||||||
await session.close()
|
await session.close()
|
||||||
return downloaded_files
|
return downloaded_files
|
||||||
|
|
||||||
|
async def download_banners(gacha_data, server_name, session):
|
||||||
|
path = f"/var/www/html/Katworks/KF/assets/KF3/{server_name}/banners/"
|
||||||
|
os.makedirs(path, exist_ok=True)
|
||||||
|
|
||||||
|
for entry in gacha_data:
|
||||||
|
banner_name = entry["banner"]
|
||||||
|
if banner_name == "" or banner_name == None:
|
||||||
|
continue
|
||||||
|
banner_name += ".png"
|
||||||
|
file_path = path + banner_name
|
||||||
|
if os.path.exists(file_path):
|
||||||
|
continue
|
||||||
|
|
||||||
|
file_url = "https://parade-mobile-prod-cdn.kemono-friends-3.jp/Texture2D/GachaTop/" + banner_name
|
||||||
|
file_url_alt = "https://parade-mobile-develop01-app.kemono-friends-3.jp/Texture2D/GachaTop/" + banner_name
|
||||||
|
|
||||||
|
status = 0
|
||||||
|
async with session.get(file_url) as resp:
|
||||||
|
response = await resp.read()
|
||||||
|
status = resp.status
|
||||||
|
if status != 200:
|
||||||
|
async with session.get(file_url_alt) as resp:
|
||||||
|
response = await resp.read()
|
||||||
|
status = resp.status
|
||||||
|
if status != 200: continue
|
||||||
|
|
||||||
|
with open(file_path, "wb") as file:
|
||||||
|
file.write(response)
|
||||||
|
|
||||||
|
|
||||||
async def download_files(server_name, asset_bundle_url, srv_platform : str):
|
async def download_files(server_name, asset_bundle_url, srv_platform : str):
|
||||||
def parse_ab_list(filecontent : str):
|
def parse_ab_list(filecontent : str):
|
||||||
out = {}
|
out = {}
|
||||||
@@ -194,27 +227,36 @@ async def convert_files():
|
|||||||
print("Conversion failed", f)
|
print("Conversion failed", f)
|
||||||
|
|
||||||
async def manual():
|
async def manual():
|
||||||
|
|
||||||
|
# session = aiohttp.ClientSession()
|
||||||
|
|
||||||
|
# path = f"/var/www/html/Katworks/KF/assets/KF3/{server_name}/cache/"
|
||||||
|
|
||||||
|
# await session.close()
|
||||||
|
|
||||||
|
# return
|
||||||
|
|
||||||
downloaded_cache = {}
|
downloaded_cache = {}
|
||||||
downloaded_files = {}
|
downloaded_files = {}
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
# async with aiohttp.ClientSession() as session:
|
||||||
param = encode(json.dumps({"version":"1.0.0","dmm_viewer_id":0,"platform":1}))
|
# param = encode(json.dumps({"version":"1.0.0","dmm_viewer_id":0,"platform":1}))
|
||||||
request = await download_bytes(servers[0] + "paradesv/common/GetUrl.do?param=" + param, session)
|
# request = await download_bytes(servers[0] + "paradesv/common/GetUrl.do?param=" + param, session)
|
||||||
result = gzip.decompress(request)
|
# result = gzip.decompress(request)
|
||||||
response = json.loads(result)
|
# response = json.loads(result)
|
||||||
asset_bundle_url = response["asset_bundle_url"]
|
# asset_bundle_url = response["asset_bundle_url"]
|
||||||
urlName = asset_bundle_url.split("-")[2]
|
# urlName = asset_bundle_url.split("-")[2]
|
||||||
|
|
||||||
print("downloading from", servers[0])
|
# print("downloading from", servers[0])
|
||||||
downloaded_cache = await download_cache(urlName, servers[0])
|
# downloaded_cache = await download_cache(urlName, servers[0])
|
||||||
downloaded_files = await download_files(urlName, asset_bundle_url, "Windows")
|
# downloaded_files = await download_files(urlName, asset_bundle_url, "Windows")
|
||||||
|
|
||||||
if downloaded_cache != [] and downloaded_cache != None:
|
# if downloaded_cache != [] and downloaded_cache != None:
|
||||||
with open("/var/www/html/Katworks/KF/assets/KF3/lastUpdate_prod_cache.json", "wt", encoding="utf-8") as file:
|
# with open("/var/www/html/Katworks/KF/assets/KF3/lastUpdate_prod_cache.json", "wt", encoding="utf-8") as file:
|
||||||
json.dump(downloaded_cache, file, ensure_ascii=False, indent=1)
|
# json.dump(downloaded_cache, file, ensure_ascii=False, indent=1)
|
||||||
if downloaded_files != [] and downloaded_files != None:
|
# if downloaded_files != [] and downloaded_files != None:
|
||||||
with open("/var/www/html/Katworks/KF/assets/KF3/lastUpdate_prod_files.json", "wt", encoding="utf-8") as file:
|
# with open("/var/www/html/Katworks/KF/assets/KF3/lastUpdate_prod_files.json", "wt", encoding="utf-8") as file:
|
||||||
json.dump(downloaded_files, file, ensure_ascii=False, indent=1)
|
# json.dump(downloaded_files, file, ensure_ascii=False, indent=1)
|
||||||
|
|
||||||
print("downloading from", servers[1])
|
print("downloading from", servers[1])
|
||||||
asset_bundle_url = "https://parade-mobile-develop01-app.kemono-friends-3.jp/AssetBundles/0.0.0/latest"
|
asset_bundle_url = "https://parade-mobile-develop01-app.kemono-friends-3.jp/AssetBundles/0.0.0/latest"
|
||||||
|
|||||||
48
modules/proxy.py
Normal file
48
modules/proxy.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
from flask_restful import Resource
|
||||||
|
from flask import current_app as app, request, Request
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
def relayRequest(user_request : Request, url, headers):
|
||||||
|
with requests.Session() as session:
|
||||||
|
requests.utils.add_dict_to_cookiejar(session.cookies, user_request.cookies)
|
||||||
|
response = session.post(url, headers=headers, data=request.data)
|
||||||
|
|
||||||
|
result = app.response_class(
|
||||||
|
response=response.text,
|
||||||
|
status=200,
|
||||||
|
mimetype='application/json'
|
||||||
|
)
|
||||||
|
result.headers.add("Access-Control-Allow-Origin", "*")
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
class LaunchProxy(Resource):
|
||||||
|
def post(self):
|
||||||
|
url = "https://apidgp-gameplayer.games.dmm.com/v5/launch/cl"
|
||||||
|
headers = {"User-Agent": "DMMGamePlayer5-Win/5.3.12 Electron/32.1.0",
|
||||||
|
"Client-App": "DMMGamePlayer5",
|
||||||
|
"Client-version": "5.3.12",
|
||||||
|
"Content-Type": "application/json"}
|
||||||
|
|
||||||
|
return relayRequest(request, url, headers)
|
||||||
|
|
||||||
|
class UpdateProxy(Resource):
|
||||||
|
def post(self):
|
||||||
|
url = "https://apidgp-gameplayer.games.dmm.com/v5/r2/launch/cl"
|
||||||
|
headers = {"User-Agent": "DMMGamePlayer5-Win/5.3.12 Electron/32.1.0",
|
||||||
|
"Client-App": "DMMGamePlayer5",
|
||||||
|
"Client-version": "5.3.12",
|
||||||
|
"Content-Type": "application/json"}
|
||||||
|
|
||||||
|
return relayRequest(request, url, headers)
|
||||||
|
|
||||||
|
class AgreementProxy(Resource):
|
||||||
|
def post(self):
|
||||||
|
url = "https://apidgp-gameplayer.games.dmm.com/v5/agreement/confirm/client"
|
||||||
|
headers = {"User-Agent": "DMMGamePlayer5-Win/5.3.12 Electron/32.1.0",
|
||||||
|
"Client-App": "DMMGamePlayer5",
|
||||||
|
"Client-version": "5.3.12",
|
||||||
|
"Content-Type": "application/json"}
|
||||||
|
|
||||||
|
return relayRequest(request, url, headers)
|
||||||
2
run.sh
Normal file
2
run.sh
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
gunicorn --bind 127.0.0.1:8081 --config gunicorn_config.py wsgi:app
|
||||||
Reference in New Issue
Block a user