diff --git a/routes/remote_device_pr.py b/routes/remote_device_pr.py index 29188a3..298d0b3 100644 --- a/routes/remote_device_pr.py +++ b/routes/remote_device_pr.py @@ -7,6 +7,8 @@ from pyplayready import PSSH as PlayReadyPSSH from pyplayready.exceptions import (InvalidSession, TooManySessions, InvalidLicense, InvalidPssh) from custom_functions.database.user_db import fetch_username_by_api_key from custom_functions.user_checks.device_allowed import user_allowed_to_use_device +from pathlib import Path + @@ -37,9 +39,24 @@ def remote_cdm_playready_deviceinfo(): 'security_level': cdm.security_level, 'host': f'{config["fqdn"]}/remotecdm/playready', 'secret': f'{config["remote_cdm_secret"]}', - 'device_name': f'{base_name}' + 'device_name': Path(base_name).stem }) +@remotecdm_pr_bp.route('/remotecdm/playready/deviceinfo/', methods=['GET']) +def remote_cdm_playready_deviceinfo_specific(device): + if request.method == 'GET': + base_name = Path(device).with_suffix('.prd').name + api_key = request.headers['X-Secret-Key'] + username = fetch_username_by_api_key(api_key) + device = PlayReadyDevice.load(f'{os.getcwd()}/configs/CDMs/{username}/PR/{base_name}') + cdm = PlayReadyCDM.from_device(device) + return jsonify({ + 'security_level': cdm.security_level, + 'host': f'{config["fqdn"]}/remotecdm/widevine', + 'secret': f'{api_key}', + 'device_name': Path(base_name).stem + }) + @remotecdm_pr_bp.route('/remotecdm/playready//open', methods=['GET']) def remote_cdm_playready_open(device): if str(device).lower() == config['default_pr_cdm'].lower(): diff --git a/routes/remote_device_wv.py b/routes/remote_device_wv.py index 080bc02..8ff18df 100644 --- a/routes/remote_device_wv.py +++ b/routes/remote_device_wv.py @@ -13,6 +13,7 @@ from pywidevine.exceptions import (InvalidContext, InvalidInitData, InvalidLicen import yaml from custom_functions.database.user_db import fetch_api_key, fetch_username_by_api_key from custom_functions.user_checks.device_allowed import user_allowed_to_use_device +from pathlib import Path remotecdm_wv_bp = Blueprint('remotecdm_wv', __name__) with open(f'{os.getcwd()}/configs/config.yaml', 'r') as file: @@ -35,8 +36,8 @@ def remote_cdm_widevine_deviceinfo(): if request.method == 'GET': base_name = config["default_wv_cdm"] if not base_name.endswith(".wvd"): - full_file_name = (base_name + ".wvd") - device = widevineDevice.load(f'{os.getcwd()}/configs/CDMs/WV/{full_file_name}') + base_name = (base_name + ".wvd") + device = widevineDevice.load(f'{os.getcwd()}/configs/CDMs/WV/{base_name}') cdm = widevineCDM.from_device(device) return jsonify({ 'device_type': cdm.device_type.name, @@ -44,7 +45,24 @@ def remote_cdm_widevine_deviceinfo(): 'security_level': cdm.security_level, 'host': f'{config["fqdn"]}/remotecdm/widevine', 'secret': f'{config["remote_cdm_secret"]}', - 'device_name': f'{base_name}' + 'device_name': Path(base_name).stem + }) + +@remotecdm_wv_bp.route('/remotecdm/widevine/deviceinfo/', methods=['GET']) +def remote_cdm_widevine_deviceinfo_specific(device): + if request.method == 'GET': + base_name = Path(device).with_suffix('.wvd').name + api_key = request.headers['X-Secret-Key'] + username = fetch_username_by_api_key(api_key) + device = widevineDevice.load(f'{os.getcwd()}/configs/CDMs/{username}/WV/{base_name}') + cdm = widevineCDM.from_device(device) + return jsonify({ + 'device_type': cdm.device_type.name, + 'system_id': cdm.system_id, + 'security_level': cdm.security_level, + 'host': f'{config["fqdn"]}/remotecdm/widevine', + 'secret': f'{api_key}', + 'device_name': Path(base_name).stem }) @remotecdm_wv_bp.route('/remotecdm/widevine//open', methods=['GET']) diff --git a/routes/user_info.py b/routes/user_info.py index 8af24b4..c5e7c71 100644 --- a/routes/user_info.py +++ b/routes/user_info.py @@ -2,7 +2,7 @@ from flask import Blueprint, request, jsonify, session import os import glob import logging -from custom_functions.database.user_db import fetch_api_key, fetch_styled_username +from custom_functions.database.user_db import fetch_api_key, fetch_styled_username, fetch_username_by_api_key user_info_bp = Blueprint('user_info_bp', __name__) @@ -10,7 +10,12 @@ user_info_bp = Blueprint('user_info_bp', __name__) def user_info(): username = session.get('username') if not username: - return jsonify({'message': 'False'}), 400 + try: + headers = request.headers + api_key = headers['Api-Key'] + username = fetch_username_by_api_key(api_key) + except: + return jsonify({'message': 'False'}), 400 try: base_path = os.path.join(os.getcwd(), 'configs', 'CDMs', username.lower())