upload
This commit is contained in:
551
helpers/Parsers/Netflix/MSLClient.py
Normal file
551
helpers/Parsers/Netflix/MSLClient.py
Normal file
@@ -0,0 +1,551 @@
|
||||
import base64, binascii, json, os, re, random, requests, string, time, traceback, logging
|
||||
from datetime import datetime
|
||||
from Cryptodome.Cipher import AES, PKCS1_OAEP
|
||||
from Cryptodome.Util import Padding
|
||||
from Cryptodome.Hash import HMAC, SHA256
|
||||
from Cryptodome.PublicKey import RSA
|
||||
from pywidevine.cdm import cdm, deviceconfig
|
||||
from configs.config import tool
|
||||
|
||||
class MSLClient:
|
||||
def __init__(self, profiles=None, wv_keyexchange=True, proxies=None):
|
||||
|
||||
self.session = requests.session()
|
||||
self.logger = logging.getLogger(__name__)
|
||||
if proxies:
|
||||
self.session.proxies.update(proxies)
|
||||
|
||||
self.nf_endpoints = {
|
||||
"manifest": "https://www.netflix.com/nq/msl_v1/cadmium/pbo_manifests/^1.0.0/router",
|
||||
"license": "https://www.netflix.com/nq/msl_v1/cadmium/pbo_licenses/^1.0.0/router",
|
||||
}
|
||||
|
||||
######################################################################
|
||||
|
||||
self.config = tool().config("NETFLIX")
|
||||
self.email = self.config["email"]
|
||||
self.password = self.config["password"]
|
||||
self.device = tool().devices()["NETFLIX-MANIFEST"]
|
||||
self.save_rsa_location = self.config["token_file"]
|
||||
self.languages = self.config["manifest_language"]
|
||||
self.license_path = None
|
||||
|
||||
######################################################################
|
||||
|
||||
if os.path.isfile(self.save_rsa_location):
|
||||
self.generatePrivateKey = RSA.importKey(
|
||||
json.loads(open(self.save_rsa_location, "r").read())["RSA_KEY"]
|
||||
)
|
||||
else:
|
||||
self.generatePrivateKey = RSA.generate(2048)
|
||||
|
||||
if wv_keyexchange:
|
||||
self.wv_keyexchange = True
|
||||
self.cdm = cdm.Cdm()
|
||||
self.cdm_session = None
|
||||
else:
|
||||
self.wv_keyexchange = False
|
||||
self.cdm = None
|
||||
self.cdm_session = None
|
||||
|
||||
self.manifest_challenge = '' # set desired wv data to overide wvexchange data
|
||||
|
||||
self.profiles = profiles
|
||||
|
||||
self.logger.debug("Using profiles: {}".format(self.profiles))
|
||||
|
||||
esn = self.config["androidEsn"]
|
||||
if esn is None:
|
||||
self.logger.error(
|
||||
'\nandroid esn not found, set esn with cdm systemID in config.py'
|
||||
)
|
||||
else:
|
||||
self.esn = esn
|
||||
|
||||
self.logger.debug("Using esn: " + self.esn)
|
||||
|
||||
self.messageid = random.randint(0, 2 ** 52)
|
||||
self.session_keys = {} #~
|
||||
self.header = {
|
||||
"sender": self.esn,
|
||||
"handshake": True,
|
||||
"nonreplayable": 2,
|
||||
"capabilities": {"languages": [], "compressionalgos": []},
|
||||
"recipient": "Netflix",
|
||||
"renewable": True,
|
||||
"messageid": self.messageid,
|
||||
"timestamp": time.time(),
|
||||
}
|
||||
|
||||
self.setRSA()
|
||||
|
||||
def get_header_extra(self):
|
||||
|
||||
if self.wv_keyexchange:
|
||||
self.cdm_session = self.cdm.open_session(
|
||||
None,
|
||||
deviceconfig.DeviceConfig(self.device),
|
||||
b"\x0A\x7A\x00\x6C\x38\x2B",
|
||||
True,
|
||||
)
|
||||
wv_request = base64.b64encode(
|
||||
self.cdm.get_license_request(self.cdm_session)
|
||||
).decode("utf-8")
|
||||
|
||||
self.header["keyrequestdata"] = [
|
||||
{
|
||||
"scheme": "WIDEVINE",
|
||||
"keydata": {
|
||||
"keyrequest": wv_request
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
else:
|
||||
self.header["keyrequestdata"] = [
|
||||
{
|
||||
"scheme": "ASYMMETRIC_WRAPPED",
|
||||
"keydata": {
|
||||
"publickey": base64.b64encode(
|
||||
self.generatePrivateKey.publickey().exportKey("DER")
|
||||
).decode("utf8"),
|
||||
"mechanism": "JWK_RSA",
|
||||
"keypairid": "rsaKeypairId",
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
return self.header
|
||||
|
||||
def setRSA(self):
|
||||
if os.path.isfile(self.save_rsa_location):
|
||||
master_token = self.load_tokens()
|
||||
expires = master_token["expiration"]
|
||||
valid_until = datetime.utcfromtimestamp(int(expires))
|
||||
present_time = datetime.now()
|
||||
|
||||
difference = valid_until - present_time
|
||||
difference = difference.total_seconds() / 60 / 60
|
||||
if difference < 10:
|
||||
self.logger.debug("rsa file found. expired soon")
|
||||
self.session_keys["session_keys"] = self.generate_handshake()
|
||||
else:
|
||||
self.logger.debug("rsa file found")
|
||||
self.session_keys["session_keys"] = {
|
||||
"mastertoken": master_token["mastertoken"],
|
||||
"sequence_number": master_token["sequence_number"],
|
||||
"encryption_key": master_token["encryption_key"],
|
||||
"sign_key": master_token["sign_key"],
|
||||
}
|
||||
else:
|
||||
self.logger.debug("rsa file not found")
|
||||
self.session_keys["session_keys"] = self.generate_handshake()
|
||||
|
||||
def load_playlist(self, viewable_id):
|
||||
|
||||
payload = {
|
||||
"version": 2,
|
||||
"url": "/manifest", #"/licensedManifest"
|
||||
"id": int(time.time()),
|
||||
"languages": self.languages,
|
||||
"params": {
|
||||
#"challenge": self.manifest_challenge,
|
||||
"type": "standard",
|
||||
"viewableId": viewable_id,
|
||||
"profiles": self.profiles,
|
||||
"flavor": "STANDARD", #'PRE_FETCH'
|
||||
"drmType": "widevine",
|
||||
"usePsshBox": True,
|
||||
"useHttpsStreams": True,
|
||||
"supportsPreReleasePin": True,
|
||||
"supportsWatermark": True,
|
||||
'supportsUnequalizedDownloadables': True,
|
||||
'requestEligibleABTests': True,
|
||||
"isBranching": False,
|
||||
'isNonMember': False,
|
||||
'isUIAutoPlay': False,
|
||||
"imageSubtitleHeight": 1080,
|
||||
"uiVersion": "shakti-v4bf615c3",
|
||||
'uiPlatform': 'SHAKTI',
|
||||
"clientVersion": "6.0026.291.011",
|
||||
'desiredVmaf': 'plus_lts', # phone_plus_exp
|
||||
"showAllSubDubTracks": True,
|
||||
#"preferredTextLocale": "ar",
|
||||
#"preferredAudioLocale": "ar",
|
||||
#"maxSupportedLanguages": 2,
|
||||
"preferAssistiveAudio": False,
|
||||
"deviceSecurityLevel": "3000",
|
||||
'licenseType': 'standard',
|
||||
'titleSpecificData': {
|
||||
str(viewable_id): {
|
||||
'unletterboxed': True
|
||||
}
|
||||
},
|
||||
"videoOutputInfo": [
|
||||
{
|
||||
"type": "DigitalVideoOutputDescriptor",
|
||||
"outputType": "unknown",
|
||||
"supportedHdcpVersions": ['2.2'],
|
||||
"isHdcpEngaged": True,
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
request_data = self.msl_request(payload)
|
||||
response = self.session.post(self.nf_endpoints["manifest"], data=request_data)
|
||||
manifest = json.loads(json.dumps(self.decrypt_response(response.text)))
|
||||
|
||||
if manifest.get("result"):
|
||||
#with open('videoTraks.json', 'w', encoding='utf-8') as d:
|
||||
#["result"]["video_tracks"]
|
||||
# d.write(json.dumps(manifest, indent=2))
|
||||
self.license_path = manifest["result"]["links"]["license"]["href"]
|
||||
return manifest
|
||||
|
||||
if manifest.get("errormsg"):
|
||||
self.logger.info(manifest["errormsg"])
|
||||
return None
|
||||
else:
|
||||
self.logger.info(manifest)
|
||||
return None
|
||||
|
||||
def decrypt_response(self, payload):
|
||||
errored = False
|
||||
try:
|
||||
p = json.loads(payload)
|
||||
if p.get("errordata"):
|
||||
return json.loads(base64.b64decode(p["errordata"]).decode())
|
||||
except:
|
||||
payloads = re.split(
|
||||
r',"signature":"[0-9A-Za-z/+=]+"}', payload.split("}}")[1]
|
||||
)
|
||||
payloads = [x + "}" for x in payloads]
|
||||
new_payload = payloads[:-1]
|
||||
|
||||
chunks = []
|
||||
for chunk in new_payload:
|
||||
try:
|
||||
payloadchunk = json.loads(chunk)["payload"]
|
||||
encryption_envelope = payloadchunk
|
||||
cipher = AES.new(
|
||||
self.session_keys["session_keys"]["encryption_key"],
|
||||
AES.MODE_CBC,
|
||||
base64.b64decode(
|
||||
json.loads(
|
||||
base64.b64decode(encryption_envelope).decode("utf8")
|
||||
)["iv"]
|
||||
),
|
||||
)
|
||||
|
||||
plaintext = cipher.decrypt(
|
||||
base64.b64decode(
|
||||
json.loads(
|
||||
base64.b64decode(encryption_envelope).decode("utf8")
|
||||
)["ciphertext"]
|
||||
)
|
||||
)
|
||||
|
||||
plaintext = json.loads(Padding.unpad(plaintext, 16).decode("utf8"))
|
||||
|
||||
data = plaintext["data"]
|
||||
data = base64.b64decode(data).decode("utf8")
|
||||
chunks.append(data)
|
||||
except:
|
||||
continue
|
||||
|
||||
decrypted_payload = "".join(chunks)
|
||||
try:
|
||||
return json.loads(decrypted_payload)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
self.logger.info("Unable to decrypt payloads...exiting")
|
||||
exit(-1)
|
||||
|
||||
def generate_handshake(self):
|
||||
self.logger.debug("generate_handshake")
|
||||
header = self.get_header_extra()
|
||||
|
||||
request = {
|
||||
"entityauthdata": {
|
||||
"scheme": "NONE",
|
||||
"authdata": {"identity": self.esn,}
|
||||
},
|
||||
"signature": "",
|
||||
"headerdata": base64.b64encode(json.dumps(header).encode("utf8")).decode("utf8"),
|
||||
}
|
||||
response = self.session.post(
|
||||
url=self.nf_endpoints["manifest"],
|
||||
json=request,
|
||||
)
|
||||
try:
|
||||
if response.json().get("errordata"):
|
||||
self.logger.info("ERROR")
|
||||
self.logger.info(
|
||||
base64.b64decode(response.json()["errordata"]).decode()
|
||||
)
|
||||
exit(-1)
|
||||
handshake = self.parse_handshake(response=response.json())
|
||||
return handshake
|
||||
except:
|
||||
traceback.print_exc()
|
||||
self.logger.info(response.text)
|
||||
exit(-1)
|
||||
|
||||
def load_tokens(self):
|
||||
|
||||
with open(self.save_rsa_location, "r", encoding='utf-8') as f:
|
||||
tokens_data = json.loads(f.read())
|
||||
|
||||
data = {
|
||||
"mastertoken": tokens_data["mastertoken"],
|
||||
"sequence_number": tokens_data["sequence_number"],
|
||||
"encryption_key": base64.standard_b64decode(tokens_data["encryption_key"]),
|
||||
"sign_key": base64.standard_b64decode(tokens_data["sign_key"]),
|
||||
"RSA_KEY": tokens_data["RSA_KEY"],
|
||||
"expiration": tokens_data["expiration"],
|
||||
}
|
||||
|
||||
return data
|
||||
|
||||
def save_tokens(self, tokens_data):
|
||||
|
||||
data = {
|
||||
"mastertoken": tokens_data["mastertoken"],
|
||||
"sequence_number": tokens_data["sequence_number"],
|
||||
"encryption_key": base64.standard_b64encode(
|
||||
tokens_data["encryption_key"]
|
||||
).decode("utf-8"),
|
||||
"sign_key": base64.standard_b64encode(tokens_data["sign_key"]).decode(
|
||||
"utf-8"
|
||||
),
|
||||
"RSA_KEY": tokens_data["RSA_KEY"],
|
||||
"expiration": tokens_data["expiration"],
|
||||
}
|
||||
|
||||
with open(self.save_rsa_location, 'w', encoding='utf-8') as f:
|
||||
f.write(json.dumps(data, indent=2))
|
||||
|
||||
def parse_handshake(self, response):
|
||||
headerdata = json.loads(base64.b64decode(response["headerdata"]).decode("utf8"))
|
||||
|
||||
keyresponsedata = headerdata["keyresponsedata"]
|
||||
mastertoken = headerdata["keyresponsedata"]["mastertoken"]
|
||||
sequence_number = json.loads(
|
||||
base64.b64decode(mastertoken["tokendata"]).decode("utf8")
|
||||
)["sequencenumber"]
|
||||
|
||||
if self.wv_keyexchange:
|
||||
expected_scheme = "WIDEVINE"
|
||||
else:
|
||||
expected_scheme = "ASYMMETRIC_WRAPPED"
|
||||
|
||||
scheme = keyresponsedata["scheme"]
|
||||
|
||||
if scheme != expected_scheme:
|
||||
self.logger.info("Key Exchange failed:")
|
||||
return False
|
||||
|
||||
keydata = keyresponsedata["keydata"]
|
||||
|
||||
if self.wv_keyexchange:
|
||||
encryption_key, sign_key = self.__process_wv_keydata(keydata)
|
||||
else:
|
||||
encryption_key, sign_key = self.__parse_rsa_wrapped_crypto_keys(keydata)
|
||||
|
||||
tokens_data = {
|
||||
"mastertoken": mastertoken,
|
||||
"sequence_number": sequence_number,
|
||||
"encryption_key": encryption_key,
|
||||
"sign_key": sign_key,
|
||||
}
|
||||
|
||||
tokens_data_save = tokens_data
|
||||
tokens_data_save.update(
|
||||
{"RSA_KEY": self.generatePrivateKey.exportKey().decode()}
|
||||
)
|
||||
tokens_data_save.update(
|
||||
{
|
||||
"expiration": json.loads(
|
||||
base64.b64decode(
|
||||
json.loads(base64.b64decode(response["headerdata"]))[
|
||||
"keyresponsedata"
|
||||
]["mastertoken"]["tokendata"]
|
||||
)
|
||||
)["expiration"]
|
||||
}
|
||||
)
|
||||
self.save_tokens(tokens_data_save)
|
||||
return tokens_data
|
||||
|
||||
def __process_wv_keydata(self, keydata):
|
||||
|
||||
wv_response_b64 = keydata["cdmkeyresponse"] # pass as b64
|
||||
encryptionkeyid = base64.standard_b64decode(keydata["encryptionkeyid"])
|
||||
hmackeyid = base64.standard_b64decode(keydata["hmackeyid"])
|
||||
self.cdm.provide_license(self.cdm_session, wv_response_b64)
|
||||
keys = self.cdm.get_keys(self.cdm_session)
|
||||
self.logger.debug("wv key exchange: obtained wv key exchange keys %s" % keys)
|
||||
return (
|
||||
self.__find_wv_key(encryptionkeyid, keys, ["AllowEncrypt", "AllowDecrypt"]),
|
||||
self.__find_wv_key(hmackeyid, keys, ["AllowSign", "AllowSignatureVerify"]),
|
||||
)
|
||||
|
||||
def __find_wv_key(self, kid, keys, permissions):
|
||||
for key in keys:
|
||||
if key.kid != kid:
|
||||
continue
|
||||
if key.type != "OPERATOR_SESSION":
|
||||
self.logger.debug(
|
||||
"wv key exchange: Wrong key type (not operator session) key %s"
|
||||
% key
|
||||
)
|
||||
continue
|
||||
|
||||
if not set(permissions) <= set(key.permissions):
|
||||
self.logger.debug(
|
||||
"wv key exchange: Incorrect permissions, key %s, needed perms %s"
|
||||
% (key, permissions)
|
||||
)
|
||||
continue
|
||||
return key.key
|
||||
|
||||
return None
|
||||
|
||||
def __parse_rsa_wrapped_crypto_keys(self, keydata):
|
||||
# Init Decryption
|
||||
encrypted_encryption_key = base64.b64decode(keydata["encryptionkey"])
|
||||
|
||||
encrypted_sign_key = base64.b64decode(keydata["hmackey"])
|
||||
|
||||
oaep_cipher = PKCS1_OAEP.new(self.generatePrivateKey)
|
||||
encryption_key_data = json.loads(
|
||||
oaep_cipher.decrypt(encrypted_encryption_key).decode("utf8")
|
||||
)
|
||||
|
||||
encryption_key = self.base64_check(encryption_key_data["k"])
|
||||
|
||||
sign_key_data = json.loads(
|
||||
oaep_cipher.decrypt(encrypted_sign_key).decode("utf8")
|
||||
)
|
||||
|
||||
sign_key = self.base64_check(sign_key_data["k"])
|
||||
return (encryption_key, sign_key)
|
||||
|
||||
def base64key_decode(self, payload):
|
||||
l = len(payload) % 4
|
||||
if l == 2:
|
||||
payload += "=="
|
||||
elif l == 3:
|
||||
payload += "="
|
||||
elif l != 0:
|
||||
raise ValueError("Invalid base64 string")
|
||||
return base64.urlsafe_b64decode(payload.encode("utf-8"))
|
||||
|
||||
def base64_check(self, string):
|
||||
|
||||
while len(string) % 4 != 0:
|
||||
string = string + "="
|
||||
return base64.urlsafe_b64decode(string.encode())
|
||||
|
||||
def msl_request(self, data, is_handshake=False):
|
||||
|
||||
header = self.header.copy()
|
||||
header["handshake"] = is_handshake
|
||||
header["userauthdata"] = {
|
||||
"scheme": "EMAIL_PASSWORD",
|
||||
"authdata": {"email": self.email, "password": self.password},
|
||||
}
|
||||
|
||||
header_envelope = self.msl_encrypt(self.session_keys, json.dumps(header))
|
||||
|
||||
header_signature = HMAC.new(
|
||||
self.session_keys["session_keys"]["sign_key"], header_envelope, SHA256
|
||||
).digest()
|
||||
|
||||
encrypted_header = {
|
||||
"headerdata": base64.b64encode(header_envelope).decode("utf8"),
|
||||
"signature": base64.b64encode(header_signature).decode("utf8"),
|
||||
"mastertoken": self.session_keys["session_keys"]["mastertoken"],
|
||||
}
|
||||
|
||||
payload = {
|
||||
"messageid": self.messageid,
|
||||
"data": base64.b64encode(json.dumps(data).encode()).decode("utf8"),
|
||||
"sequencenumber": 1,
|
||||
"endofmsg": True,
|
||||
}
|
||||
|
||||
payload_envelope = self.msl_encrypt(self.session_keys, json.dumps(payload))
|
||||
|
||||
payload_signature = HMAC.new(
|
||||
self.session_keys["session_keys"]["sign_key"], payload_envelope, SHA256
|
||||
).digest()
|
||||
|
||||
payload_chunk = {
|
||||
"payload": base64.b64encode(payload_envelope).decode("utf8"),
|
||||
"signature": base64.b64encode(payload_signature).decode("utf8"),
|
||||
}
|
||||
return json.dumps(encrypted_header) + json.dumps(payload_chunk)
|
||||
|
||||
def msl_encrypt(self, msl_session, plaintext):
|
||||
|
||||
cbc_iv = os.urandom(16)
|
||||
encryption_envelope = {
|
||||
"keyid": "%s_%s"
|
||||
% (self.esn, msl_session["session_keys"]["sequence_number"]),
|
||||
"sha256": "AA==",
|
||||
"iv": base64.b64encode(cbc_iv).decode("utf8"),
|
||||
}
|
||||
|
||||
plaintext = Padding.pad(plaintext.encode("utf8"), 16)
|
||||
cipher = AES.new(
|
||||
msl_session["session_keys"]["encryption_key"], AES.MODE_CBC, cbc_iv
|
||||
)
|
||||
|
||||
ciphertext = cipher.encrypt(plaintext)
|
||||
|
||||
encryption_envelope["ciphertext"] = base64.b64encode(ciphertext).decode("utf8")
|
||||
|
||||
return json.dumps(encryption_envelope).encode("utf8")
|
||||
|
||||
def get_license(self, challenge, session_id):
|
||||
|
||||
if not isinstance(challenge, bytes):
|
||||
raise TypeError("challenge must be of type bytes")
|
||||
|
||||
if not isinstance(session_id, str):
|
||||
raise TypeError("session_id must be of type string")
|
||||
|
||||
timestamp = int(time.time() * 10000)
|
||||
|
||||
license_request_data = {
|
||||
"version": 2,
|
||||
"url": self.license_path,
|
||||
"id": timestamp,
|
||||
"languages": "en_US",
|
||||
"echo": "drmsessionId",
|
||||
"params": [
|
||||
{
|
||||
"drmSessionId": session_id,
|
||||
"clientTime": int(timestamp / 10000),
|
||||
"challengeBase64": base64.b64encode(challenge).decode("utf8"),
|
||||
"xid": str(timestamp + 1610),
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
request_data = self.msl_request(license_request_data)
|
||||
|
||||
resp = self.session.post(url=self.nf_endpoints["license"],data=request_data)
|
||||
|
||||
try:
|
||||
resp.json()
|
||||
|
||||
except ValueError:
|
||||
msl_license_data = json.loads(json.dumps(self.decrypt_response(resp.text)))
|
||||
if msl_license_data.get("result"):
|
||||
return msl_license_data
|
||||
if msl_license_data.get("errormsg"):
|
||||
raise ValueError(msl_license_data["errormsg"])
|
||||
raise ValueError(msl_license_data)
|
||||
BIN
helpers/Parsers/Netflix/__pycache__/MSLClient.cpython-36.pyc
Normal file
BIN
helpers/Parsers/Netflix/__pycache__/MSLClient.cpython-36.pyc
Normal file
Binary file not shown.
BIN
helpers/Parsers/Netflix/__pycache__/MSLClient.cpython-39.pyc
Normal file
BIN
helpers/Parsers/Netflix/__pycache__/MSLClient.cpython-39.pyc
Normal file
Binary file not shown.
BIN
helpers/Parsers/Netflix/__pycache__/get_keys.cpython-36.pyc
Normal file
BIN
helpers/Parsers/Netflix/__pycache__/get_keys.cpython-36.pyc
Normal file
Binary file not shown.
BIN
helpers/Parsers/Netflix/__pycache__/get_keys.cpython-39.pyc
Normal file
BIN
helpers/Parsers/Netflix/__pycache__/get_keys.cpython-39.pyc
Normal file
Binary file not shown.
BIN
helpers/Parsers/Netflix/__pycache__/get_manifest.cpython-36.pyc
Normal file
BIN
helpers/Parsers/Netflix/__pycache__/get_manifest.cpython-36.pyc
Normal file
Binary file not shown.
BIN
helpers/Parsers/Netflix/__pycache__/get_manifest.cpython-39.pyc
Normal file
BIN
helpers/Parsers/Netflix/__pycache__/get_manifest.cpython-39.pyc
Normal file
Binary file not shown.
159
helpers/Parsers/Netflix/get_keys.py
Normal file
159
helpers/Parsers/Netflix/get_keys.py
Normal file
@@ -0,0 +1,159 @@
|
||||
import time, os, json, logging, base64
|
||||
from helpers.Parsers.Netflix.MSLClient import MSLClient
|
||||
from configs.config import tool
|
||||
from pywidevine.decrypt.wvdecryptcustom import WvDecrypt
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
''' "av1-main-L20-dash-cbcs-prk",
|
||||
"av1-main-L21-dash-cbcs-prk",
|
||||
"av1-main-L30-dash-cbcs-prk",
|
||||
"av1-main-L31-dash-cbcs-prk",
|
||||
"av1-main-L40-dash-cbcs-prk",
|
||||
"av1-main-L41-dash-cbcs-prk",
|
||||
"av1-main-L50-dash-cbcs-prk",
|
||||
"av1-main-L51-dash-cbcs-prk",'''
|
||||
|
||||
''' "vp9-profile0-L21-dash-cenc",
|
||||
"vp9-profile0-L30-dash-cenc",
|
||||
"vp9-profile0-L31-dash-cenc",
|
||||
"vp9-profile0-L40-dash-cenc",
|
||||
"vp9-profile2-L30-dash-cenc-prk",
|
||||
"vp9-profile2-L31-dash-cenc-prk",
|
||||
"vp9-profile2-L40-dash-cenc-prk",
|
||||
"vp9-profile2-L50-dash-cenc-prk",
|
||||
"vp9-profile2-L51-dash-cenc-prk"'''
|
||||
|
||||
def from_kid(kid):
|
||||
array_of_bytes = bytearray(b"\x00\x00\x002pssh\x00\x00\x00\x00")
|
||||
array_of_bytes.extend(bytes.fromhex("edef8ba979d64acea3c827dcd51d21ed"))
|
||||
array_of_bytes.extend(b"\x00\x00\x00\x12\x12\x10")
|
||||
array_of_bytes.extend(bytes.fromhex(kid.replace("-", "")))
|
||||
pssh = base64.b64encode(bytes.fromhex(array_of_bytes.hex()))
|
||||
return pssh.decode()
|
||||
|
||||
def __profiles(profile, addHEVCDO=False):
|
||||
|
||||
profiles = [
|
||||
"heaac-2-dash",
|
||||
"dfxp-ls-sdh",
|
||||
"webvtt-lssdh-ios8",
|
||||
"BIF240",
|
||||
"BIF320",
|
||||
]
|
||||
|
||||
if profile == "High KEYS":
|
||||
profiles += [
|
||||
"playready-h264hpl22-dash",
|
||||
"playready-h264hpl30-dash",
|
||||
"playready-h264hpl31-dash",
|
||||
#'playready-h264hpl40-dash'
|
||||
]
|
||||
|
||||
elif profile == "Main KEYS":
|
||||
profiles += [
|
||||
"playready-h264mpl30-dash",
|
||||
]
|
||||
|
||||
elif profile == "HEVC KEYS":
|
||||
profiles += [
|
||||
"hevc-main-L30-dash-cenc",
|
||||
"hevc-main10-L30-dash-cenc",
|
||||
"hevc-main10-L30-dash-cenc-prk",
|
||||
"hevc-main-L31-dash-cenc"
|
||||
"hevc-main10-L31-dash-cenc",
|
||||
"hevc-main10-L31-dash-cenc-prk",
|
||||
"hevc-main-L40-dash-cenc",
|
||||
"hevc-main10-L40-dash-cenc",
|
||||
"hevc-main10-L40-dash-cenc-prk",
|
||||
"hevc-main-L41-dash-cenc",
|
||||
"hevc-main10-L41-dash-cenc",
|
||||
"hevc-main10-L41-dash-cenc-prk"
|
||||
]
|
||||
if addHEVCDO:
|
||||
profiles += [
|
||||
"hevc-main10-L31-dash-cenc-prk-do",
|
||||
"hevc-main10-L31-dash-cenc-prk-do",
|
||||
"hevc-main10-L40-dash-cenc-prk-do",
|
||||
"hevc-main10-L41-dash-cenc-prk-do",
|
||||
]
|
||||
|
||||
elif profile == 'HDR-10 KEYS':
|
||||
profiles += [
|
||||
"hevc-hdr-main10-L30-dash-cenc",
|
||||
"hevc-hdr-main10-L30-dash-cenc-prk",
|
||||
"hevc-hdr-main10-L31-dash-cenc",
|
||||
"hevc-hdr-main10-L31-dash-cenc-prk",
|
||||
"hevc-hdr-main10-L40-dash-cenc",
|
||||
"hevc-hdr-main10-L41-dash-cenc",
|
||||
"hevc-hdr-main10-L40-dash-cenc-prk",
|
||||
"hevc-hdr-main10-L41-dash-cenc-prk"
|
||||
]
|
||||
else:
|
||||
profiles += [
|
||||
"playready-h264mpl30-dash",
|
||||
]
|
||||
|
||||
return profiles
|
||||
|
||||
def GettingKEYS_Netflixv2(nfID, profile): #
|
||||
|
||||
KEYS = []
|
||||
|
||||
available_profiles = [
|
||||
"High KEYS",
|
||||
"HEVC KEYS",
|
||||
"HDR-10 KEYS",
|
||||
"Main KEYS"
|
||||
]
|
||||
|
||||
if not profile in available_profiles:
|
||||
logger.info("Error: Unknown profile: {}".format(profile))
|
||||
exit(1)
|
||||
|
||||
logger.info(f"\nGetting {profile}...")
|
||||
|
||||
profiles = __profiles(profile)
|
||||
|
||||
try:
|
||||
client = MSLClient(profiles=profiles)
|
||||
resp = client.load_playlist(int(nfID))
|
||||
if resp is None:
|
||||
if profile == 'HEVC KEYS':
|
||||
profiles = __profiles(profile, addHEVCDO=True)
|
||||
client = MSLClient(profiles=profiles)
|
||||
resp = client.load_playlist(int(nfID))
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Manifest Error: {}".format(e))
|
||||
return KEYS
|
||||
|
||||
try:
|
||||
#init_data_b64 = from_kid('0000000005edabd50000000000000000')
|
||||
init_data_b64 = resp["result"]["video_tracks"][0]["drmHeader"]["bytes"]
|
||||
except KeyError:
|
||||
logger.error("cannot get pssh, {}".format(resp))
|
||||
return KEYS
|
||||
|
||||
cert_data_b64 = "CAUSwwUKvQIIAxIQ5US6QAvBDzfTtjb4tU/7QxiH8c+TBSKOAjCCAQoCggEBAObzvlu2hZRsapAPx4Aa4GUZj4/GjxgXUtBH4THSkM40x63wQeyVxlEEo1D/T1FkVM/S+tiKbJiIGaT0Yb5LTAHcJEhODB40TXlwPfcxBjJLfOkF3jP6wIlqbb6OPVkDi6KMTZ3EYL6BEFGfD1ag/LDsPxG6EZIn3k4S3ODcej6YSzG4TnGD0szj5m6uj/2azPZsWAlSNBRUejmP6Tiota7g5u6AWZz0MsgCiEvnxRHmTRee+LO6U4dswzF3Odr2XBPD/hIAtp0RX8JlcGazBS0GABMMo2qNfCiSiGdyl2xZJq4fq99LoVfCLNChkn1N2NIYLrStQHa35pgObvhwi7ECAwEAAToQdGVzdC5uZXRmbGl4LmNvbRKAA4TTLzJbDZaKfozb9vDv5qpW5A/DNL9gbnJJi/AIZB3QOW2veGmKT3xaKNQ4NSvo/EyfVlhc4ujd4QPrFgYztGLNrxeyRF0J8XzGOPsvv9Mc9uLHKfiZQuy21KZYWF7HNedJ4qpAe6gqZ6uq7Se7f2JbelzENX8rsTpppKvkgPRIKLspFwv0EJQLPWD1zjew2PjoGEwJYlKbSbHVcUNygplaGmPkUCBThDh7p/5Lx5ff2d/oPpIlFvhqntmfOfumt4i+ZL3fFaObvkjpQFVAajqmfipY0KAtiUYYJAJSbm2DnrqP7+DmO9hmRMm9uJkXC2MxbmeNtJHAHdbgKsqjLHDiqwk1JplFMoC9KNMp2pUNdX9TkcrtJoEDqIn3zX9p+itdt3a9mVFc7/ZL4xpraYdQvOwP5LmXj9galK3s+eQJ7bkX6cCi+2X+iBmCMx4R0XJ3/1gxiM5LiStibCnfInub1nNgJDojxFA3jH/IuUcblEf/5Y0s1SzokBnR8V0KbA=="
|
||||
|
||||
device = tool().devices()["NETFLIX-LICENSE"]
|
||||
|
||||
wvdecrypt = WvDecrypt(
|
||||
init_data_b64=init_data_b64, cert_data_b64=cert_data_b64, device=device
|
||||
)
|
||||
challenge = wvdecrypt.get_challenge()
|
||||
current_sessionId = str(time.time()).replace(".", "")[0:-2]
|
||||
data = client.get_license(challenge, current_sessionId)
|
||||
|
||||
try:
|
||||
license_b64 = data["result"][0]["licenseResponseBase64"]
|
||||
except Exception:
|
||||
logger.error("MSL LICENSE Error Message: {}".format(data))
|
||||
return KEYS
|
||||
|
||||
wvdecrypt.update_license(license_b64)
|
||||
Correct, keyswvdecrypt = wvdecrypt.start_process()
|
||||
KEYS = keyswvdecrypt
|
||||
|
||||
return KEYS
|
||||
736
helpers/Parsers/Netflix/get_manifest.py
Normal file
736
helpers/Parsers/Netflix/get_manifest.py
Normal file
@@ -0,0 +1,736 @@
|
||||
from helpers.ripprocess import ripprocess
|
||||
from helpers.Parsers.Netflix.MSLClient import MSLClient
|
||||
from configs.config import tool
|
||||
import re, os, json, logging
|
||||
|
||||
def MSLprofiles():
|
||||
PROFILES = {
|
||||
"BASICS": ["BIF240", "BIF320", "webvtt-lssdh-ios8", "dfxp-ls-sdh"],
|
||||
"MAIN": {
|
||||
"SD": [
|
||||
"playready-h264bpl30-dash",
|
||||
"playready-h264mpl22-dash",
|
||||
"playready-h264mpl30-dash",
|
||||
],
|
||||
"HD": [
|
||||
"playready-h264bpl30-dash",
|
||||
"playready-h264mpl22-dash",
|
||||
"playready-h264mpl30-dash",
|
||||
"playready-h264mpl31-dash",
|
||||
],
|
||||
"FHD": [
|
||||
"playready-h264bpl30-dash",
|
||||
"playready-h264mpl22-dash",
|
||||
"playready-h264mpl30-dash",
|
||||
"playready-h264mpl31-dash",
|
||||
"playready-h264mpl40-dash",
|
||||
],
|
||||
"ALL": [
|
||||
"playready-h264bpl30-dash",
|
||||
"playready-h264mpl22-dash",
|
||||
"playready-h264mpl30-dash",
|
||||
"playready-h264mpl31-dash",
|
||||
"playready-h264mpl40-dash",
|
||||
],
|
||||
},
|
||||
"HIGH": {
|
||||
"SD": [
|
||||
"playready-h264hpl22-dash",
|
||||
"playready-h264hpl30-dash",
|
||||
],
|
||||
"HD": [
|
||||
"playready-h264hpl22-dash",
|
||||
"playready-h264hpl30-dash",
|
||||
"playready-h264hpl31-dash",
|
||||
],
|
||||
"FHD": [
|
||||
"playready-h264hpl22-dash",
|
||||
"playready-h264hpl30-dash",
|
||||
"playready-h264hpl31-dash",
|
||||
"playready-h264hpl40-dash",
|
||||
],
|
||||
"ALL": [
|
||||
"playready-h264hpl22-dash",
|
||||
"playready-h264hpl30-dash",
|
||||
"playready-h264hpl31-dash",
|
||||
"playready-h264hpl40-dash",
|
||||
],
|
||||
},
|
||||
"HEVC": {
|
||||
"SD": [
|
||||
"hevc-main-L30-dash-cenc",
|
||||
"hevc-main10-L30-dash-cenc",
|
||||
"hevc-main10-L30-dash-cenc-prk",
|
||||
],
|
||||
"HD": [
|
||||
"hevc-main-L30-dash-cenc",
|
||||
"hevc-main10-L30-dash-cenc",
|
||||
"hevc-main10-L30-dash-cenc-prk",
|
||||
"hevc-main-L31-dash-cenc",
|
||||
"hevc-main10-L31-dash-cenc",
|
||||
"hevc-main10-L31-dash-cenc-prk",
|
||||
],
|
||||
"FHD": [
|
||||
"hevc-main-L30-dash-cenc",
|
||||
"hevc-main10-L30-dash-cenc",
|
||||
"hevc-main10-L30-dash-cenc-prk",
|
||||
"hevc-main-L31-dash-cenc"
|
||||
"hevc-main10-L31-dash-cenc",
|
||||
"hevc-main10-L31-dash-cenc-prk",
|
||||
"hevc-main-L40-dash-cenc",
|
||||
"hevc-main10-L40-dash-cenc",
|
||||
"hevc-main10-L40-dash-cenc-prk",
|
||||
"hevc-main-L41-dash-cenc",
|
||||
"hevc-main10-L41-dash-cenc",
|
||||
"hevc-main10-L41-dash-cenc-prk",
|
||||
],
|
||||
"ALL": [
|
||||
"hevc-main-L30-dash-cenc",
|
||||
"hevc-main10-L30-dash-cenc",
|
||||
"hevc-main10-L30-dash-cenc-prk",
|
||||
"hevc-main-L31-dash-cenc"
|
||||
"hevc-main10-L31-dash-cenc",
|
||||
"hevc-main10-L31-dash-cenc-prk",
|
||||
"hevc-main-L40-dash-cenc",
|
||||
"hevc-main10-L40-dash-cenc",
|
||||
"hevc-main10-L40-dash-cenc-prk",
|
||||
"hevc-main-L41-dash-cenc",
|
||||
"hevc-main10-L41-dash-cenc",
|
||||
"hevc-main10-L41-dash-cenc-prk",
|
||||
],
|
||||
},
|
||||
"HEVCDO": {
|
||||
"SD": [
|
||||
"hevc-main10-L30-dash-cenc-prk-do",
|
||||
],
|
||||
"HD": [
|
||||
"hevc-main10-L30-dash-cenc-prk-do",
|
||||
"hevc-main10-L31-dash-cenc-prk-do"
|
||||
],
|
||||
"FHD": [
|
||||
"hevc-main10-L31-dash-cenc-prk-do",
|
||||
"hevc-main10-L31-dash-cenc-prk-do",
|
||||
"hevc-main10-L40-dash-cenc-prk-do",
|
||||
"hevc-main10-L41-dash-cenc-prk-do",
|
||||
],
|
||||
"ALL": [
|
||||
"hevc-main10-L31-dash-cenc-prk-do",
|
||||
"hevc-main10-L31-dash-cenc-prk-do",
|
||||
"hevc-main10-L40-dash-cenc-prk-do",
|
||||
"hevc-main10-L41-dash-cenc-prk-do",
|
||||
],
|
||||
},
|
||||
"HDR": {
|
||||
"SD": [
|
||||
"hevc-hdr-main10-L30-dash-cenc",
|
||||
"hevc-hdr-main10-L30-dash-cenc-prk",
|
||||
],
|
||||
"HD": [
|
||||
"hevc-hdr-main10-L30-dash-cenc",
|
||||
"hevc-hdr-main10-L30-dash-cenc-prk",
|
||||
"hevc-hdr-main10-L31-dash-cenc",
|
||||
"hevc-hdr-main10-L31-dash-cenc-prk",
|
||||
],
|
||||
"FHD": [
|
||||
"hevc-hdr-main10-L30-dash-cenc",
|
||||
"hevc-hdr-main10-L30-dash-cenc-prk",
|
||||
"hevc-hdr-main10-L31-dash-cenc",
|
||||
"hevc-hdr-main10-L31-dash-cenc-prk",
|
||||
"hevc-hdr-main10-L40-dash-cenc",
|
||||
"hevc-hdr-main10-L41-dash-cenc",
|
||||
"hevc-hdr-main10-L40-dash-cenc-prk",
|
||||
"hevc-hdr-main10-L41-dash-cenc-prk",
|
||||
],
|
||||
"ALL": [
|
||||
"hevc-hdr-main10-L30-dash-cenc",
|
||||
"hevc-hdr-main10-L30-dash-cenc-prk",
|
||||
"hevc-hdr-main10-L31-dash-cenc",
|
||||
"hevc-hdr-main10-L31-dash-cenc-prk",
|
||||
"hevc-hdr-main10-L40-dash-cenc",
|
||||
"hevc-hdr-main10-L41-dash-cenc",
|
||||
"hevc-hdr-main10-L40-dash-cenc-prk",
|
||||
"hevc-hdr-main10-L41-dash-cenc-prk",
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
return PROFILES
|
||||
|
||||
class get_manifest:
|
||||
|
||||
def __init__(self, args, nfid):
|
||||
self.logger = logging.getLogger(__name__)
|
||||
self.args = args
|
||||
self.nfid = nfid
|
||||
self.ripprocess = ripprocess()
|
||||
self.profiles = MSLprofiles()
|
||||
self.config = tool().config("NETFLIX")
|
||||
|
||||
def LoadProfies(self, addHEVCDO=False):
|
||||
getHigh = False
|
||||
profiles = self.profiles["BASICS"]
|
||||
|
||||
if self.args.video_main:
|
||||
if self.args.customquality:
|
||||
if int(self.args.customquality[0]) == 1080:
|
||||
profiles += self.profiles["MAIN"]["FHD"]
|
||||
elif (
|
||||
int(self.args.customquality[0]) < 1080
|
||||
and int(self.args.customquality[0]) >= 720
|
||||
):
|
||||
profiles += self.profiles["MAIN"]["HD"]
|
||||
elif int(self.args.customquality[0]) < 720:
|
||||
profiles += self.profiles["MAIN"]["SD"]
|
||||
else:
|
||||
profiles += self.profiles["MAIN"]["ALL"]
|
||||
else:
|
||||
if self.args.video_high:
|
||||
if self.args.customquality:
|
||||
if int(self.args.customquality[0]) == 1080:
|
||||
profiles += self.profiles["HIGH"]["FHD"]
|
||||
elif (
|
||||
int(self.args.customquality[0]) < 1080
|
||||
and int(self.args.customquality[0]) >= 720
|
||||
):
|
||||
profiles += self.profiles["HIGH"]["HD"]
|
||||
elif int(self.args.customquality[0]) < 720:
|
||||
profiles += self.profiles["HIGH"]["SD"]
|
||||
else:
|
||||
profiles += self.profiles["HIGH"]["ALL"]
|
||||
else:
|
||||
if self.args.hdr:
|
||||
if self.args.customquality:
|
||||
if int(self.args.customquality[0]) == 1080:
|
||||
profiles += self.profiles["HDR"]["FHD"]
|
||||
elif (
|
||||
int(self.args.customquality[0]) < 1080
|
||||
and int(self.args.customquality[0]) >= 720
|
||||
):
|
||||
profiles += self.profiles["HDR"]["HD"]
|
||||
elif int(self.args.customquality[0]) < 720:
|
||||
profiles += self.profiles["HDR"]["SD"]
|
||||
else:
|
||||
profiles += self.profiles["HDR"]["ALL"]
|
||||
|
||||
elif self.args.hevc:
|
||||
if self.args.customquality:
|
||||
if int(self.args.customquality[0]) == 1080:
|
||||
profiles += self.profiles["HEVC"]["FHD"]
|
||||
if addHEVCDO:
|
||||
profiles += self.profiles['HEVCDO']['FHD']
|
||||
elif (
|
||||
int(self.args.customquality[0]) < 1080
|
||||
and int(self.args.customquality[0]) >= 720
|
||||
):
|
||||
profiles += self.profiles["HEVC"]["HD"]
|
||||
if addHEVCDO:
|
||||
profiles += self.profiles['HEVCDO']['HD']
|
||||
elif int(self.args.customquality[0]) < 720:
|
||||
profiles += self.profiles["HEVC"]["SD"]
|
||||
if addHEVCDO:
|
||||
profiles += self.profiles['HEVCDO']['SD']
|
||||
else:
|
||||
profiles += self.profiles["HEVC"]["ALL"]
|
||||
if addHEVCDO:
|
||||
profiles += self.profiles['HEVCDO']['ALL']
|
||||
|
||||
else:
|
||||
getHigh = True
|
||||
if self.args.customquality:
|
||||
if int(self.args.customquality[0]) == 1080:
|
||||
profiles += self.profiles["MAIN"]["FHD"]
|
||||
elif (
|
||||
int(self.args.customquality[0]) < 1080
|
||||
and int(self.args.customquality[0]) >= 720
|
||||
):
|
||||
profiles += self.profiles["MAIN"]["HD"]
|
||||
elif int(self.args.customquality[0]) < 720:
|
||||
profiles += self.profiles["MAIN"]["SD"]
|
||||
else:
|
||||
profiles += self.profiles["MAIN"]["ALL"]
|
||||
|
||||
if self.args.aformat_2ch:
|
||||
if str(self.args.aformat_2ch[0]) == "aac":
|
||||
profiles.append("heaac-2-dash")
|
||||
profiles.append("heaac-2hq-dash")
|
||||
elif str(self.args.aformat_2ch[0]) == "eac3":
|
||||
profiles.append("ddplus-2.0-dash")
|
||||
elif str(self.args.aformat_2ch[0]) == "ogg":
|
||||
profiles.append("playready-oggvorbis-2-dash")
|
||||
else:
|
||||
if self.args.only_2ch_audio:
|
||||
profiles.append("ddplus-2.0-dash")
|
||||
else:
|
||||
if self.args.aformat_51ch:
|
||||
if str(self.args.aformat_51ch[0]) == "aac":
|
||||
profiles.append("heaac-5.1-dash")
|
||||
profiles.append("heaac-5.1hq-dash")
|
||||
elif str(self.args.aformat_51ch[0]) == "eac3":
|
||||
profiles.append("ddplus-5.1-dash")
|
||||
profiles.append("ddplus-5.1hq-dash")
|
||||
elif str(self.args.aformat_51ch[0]) == "ac3":
|
||||
profiles.append("dd-5.1-dash")
|
||||
elif str(self.args.aformat_51ch[0]) == "atmos":
|
||||
profiles.append("dd-5.1-dash")
|
||||
profiles.append("ddplus-atmos-dash")
|
||||
else:
|
||||
profiles.append("dd-5.1-dash")
|
||||
profiles.append("ddplus-5.1-dash")
|
||||
profiles.append("ddplus-5.1hq-dash")
|
||||
else:
|
||||
profiles.append("ddplus-2.0-dash")
|
||||
profiles.append("dd-5.1-dash")
|
||||
profiles.append("ddplus-5.1-dash")
|
||||
profiles.append("ddplus-5.1hq-dash")
|
||||
profiles.append("ddplus-atmos-dash")
|
||||
|
||||
return list(set(profiles)), getHigh
|
||||
|
||||
def PyMSL(self, profiles):
|
||||
|
||||
client = MSLClient(profiles=profiles)
|
||||
|
||||
try:
|
||||
resp = client.load_playlist(int(self.nfid))
|
||||
return resp
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error("Manifest Error: {}".format(e))
|
||||
|
||||
return None
|
||||
|
||||
def HighVideoMSL(self):
|
||||
# for bitrate compare with main ~
|
||||
|
||||
self.logger.info("Getting High Profile Manifest...")
|
||||
|
||||
profiles = self.profiles["BASICS"]
|
||||
|
||||
if self.args.customquality:
|
||||
if int(self.args.customquality[0]) == 1080:
|
||||
profiles += self.profiles["HIGH"]["FHD"]
|
||||
elif (
|
||||
int(self.args.customquality[0]) < 1080
|
||||
and int(self.args.customquality[0]) >= 720
|
||||
):
|
||||
profiles += self.profiles["HIGH"]["HD"]
|
||||
elif int(self.args.customquality[0]) < 720:
|
||||
profiles += self.profiles["HIGH"]["SD"]
|
||||
else:
|
||||
profiles += self.profiles["HIGH"]["ALL"]
|
||||
|
||||
resp = self.PyMSL(profiles=profiles)
|
||||
|
||||
VideoList = list()
|
||||
|
||||
manifest = resp["result"]
|
||||
|
||||
for video_track in manifest["video_tracks"]:
|
||||
for downloadable in video_track["streams"]:
|
||||
size_in_bytes = int(float(downloadable["size"]))
|
||||
vid_size = (
|
||||
f"{size_in_bytes/1048576:0.2f} MiB"
|
||||
if size_in_bytes < 1073741824
|
||||
else f"{size_in_bytes/1073741824:0.2f} GiB"
|
||||
)
|
||||
vid_url = downloadable["urls"][0]["url"]
|
||||
L3 = 'L3' if 'SEGMENT_MAP_2KEY' in str(downloadable['tags']) else '' #
|
||||
|
||||
VideoList.append(
|
||||
{
|
||||
"Type": "video",
|
||||
"Drm": downloadable["isDrm"],
|
||||
"vmaf": downloadable["vmaf"],
|
||||
"FrameRate": downloadable["framerate_value"],
|
||||
"Height": downloadable["res_h"],
|
||||
"Width": downloadable["res_w"],
|
||||
"Size": vid_size,
|
||||
"Url": vid_url,
|
||||
"Bitrate": str(downloadable["bitrate"]),
|
||||
"Profile": downloadable["content_profile"],
|
||||
"L3": L3 #
|
||||
}
|
||||
)
|
||||
|
||||
VideoList = sorted(VideoList, key=lambda k: int(k["Bitrate"]))
|
||||
|
||||
if self.args.customquality:
|
||||
inp_height = int(self.args.customquality[0])
|
||||
top_height = sorted(VideoList, key=lambda k: int(k["Height"]))[-1]["Height"]
|
||||
|
||||
if top_height >= inp_height:
|
||||
height = [x for x in VideoList if int(x["Height"]) >= inp_height]
|
||||
if not height == []:
|
||||
VideoList = height
|
||||
|
||||
return VideoList
|
||||
|
||||
def ParseVideo(self, resp, getHigh):
|
||||
manifest = resp["result"]
|
||||
VideoList = []
|
||||
checkerinfo = ""
|
||||
|
||||
for video_track in manifest["video_tracks"]:
|
||||
for downloadable in video_track["streams"]:
|
||||
size_in_bytes = int(float(downloadable["size"]))
|
||||
vid_size = (
|
||||
f"{size_in_bytes/1048576:0.2f} MiB"
|
||||
if size_in_bytes < 1073741824
|
||||
else f"{size_in_bytes/1073741824:0.2f} GiB"
|
||||
)
|
||||
vid_url = downloadable["urls"][0]["url"]
|
||||
|
||||
VideoList.append(
|
||||
{
|
||||
"Type": "video",
|
||||
"Drm": downloadable["isDrm"],
|
||||
"vmaf": downloadable["vmaf"],
|
||||
"FrameRate": downloadable["framerate_value"],
|
||||
"Height": downloadable["res_h"],
|
||||
"Width": downloadable["res_w"],
|
||||
"Size": vid_size,
|
||||
"Url": vid_url,
|
||||
"Bitrate": str(downloadable["bitrate"]),
|
||||
"Profile": downloadable["content_profile"],
|
||||
}
|
||||
)
|
||||
|
||||
VideoList = sorted(VideoList, key=lambda k: int(k["Bitrate"]))
|
||||
self.logger.debug("VideoList: {}".format(VideoList))
|
||||
|
||||
if self.args.customquality:
|
||||
inp_height = int(self.args.customquality[0])
|
||||
top_height = sorted(VideoList, key=lambda k: int(k["Height"]))[-1]["Height"]
|
||||
|
||||
if top_height >= inp_height:
|
||||
height = [x for x in VideoList if int(x["Height"]) >= inp_height]
|
||||
if not height == []:
|
||||
VideoList = height
|
||||
|
||||
if getHigh:
|
||||
HighVideoList = self.HighVideoMSL()
|
||||
if not HighVideoList == []:
|
||||
checkerinfo = "\nNetflix Profile Checker v1.0\nMAIN: {}kbps | {}\nHIGH: {}kbps | {}\n\n{}\n"
|
||||
checkerinfo = checkerinfo.format(
|
||||
str(dict(VideoList[-1])["Bitrate"]),
|
||||
str(dict(VideoList[-1])["Profile"]),
|
||||
str(dict(HighVideoList[-1])["Bitrate"]),
|
||||
str(dict(HighVideoList[-1])["Profile"]),
|
||||
"result: MAIN is Better"
|
||||
if int(dict(VideoList[-1])["Bitrate"])
|
||||
>= int(dict(HighVideoList[-1])["Bitrate"])
|
||||
else "result: HIGH is Better",
|
||||
)
|
||||
|
||||
VideoList += HighVideoList
|
||||
self.logger.debug("HighVideoList: {}".format(HighVideoList))
|
||||
|
||||
VideoList = sorted(VideoList, key=lambda k: int(k["Bitrate"]))
|
||||
|
||||
return VideoList, checkerinfo
|
||||
|
||||
def ParseAudioSubs(self, resp):
|
||||
|
||||
def remove_dups(List, keyword=""):
|
||||
# function to remove all dups based on list items ~
|
||||
Added_ = set()
|
||||
Proper_ = []
|
||||
for L in List:
|
||||
if L[keyword] not in Added_:
|
||||
Proper_.append(L)
|
||||
Added_.add(L[keyword])
|
||||
|
||||
return Proper_
|
||||
|
||||
def isOriginal(language_text):
|
||||
# function to detect the original audio ~
|
||||
if "Original" in language_text:
|
||||
return True
|
||||
|
||||
brackets = re.search(r"\[(.*)\]", language_text)
|
||||
if brackets:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def noOriginal(language_text):
|
||||
# function to remove (original) from audio language to be detected in --alang ~
|
||||
brackets = re.search(r"\[(.*)\]", language_text)
|
||||
if brackets:
|
||||
return language_text.replace(brackets[0], "").strip()
|
||||
|
||||
return language_text
|
||||
|
||||
# start audio, subs parsing ~
|
||||
|
||||
manifest = resp["result"]
|
||||
|
||||
AudioList, SubtitleList, ForcedList = list(), list(), list()
|
||||
|
||||
# parse audios and return all (AD, non AD) as a list
|
||||
for audio_track in manifest["audio_tracks"]:
|
||||
AudioDescription = 'Audio Description' if "audio description" in \
|
||||
audio_track["languageDescription"].lower() else 'Audio'
|
||||
Original = isOriginal(audio_track["languageDescription"])
|
||||
LanguageName, LanguageCode = self.ripprocess.countrycode(
|
||||
audio_track["language"]
|
||||
)
|
||||
LanguageName = noOriginal(audio_track["languageDescription"])
|
||||
|
||||
for downloadable in audio_track["streams"]:
|
||||
aud_url = downloadable["urls"][0]["url"]
|
||||
size = (
|
||||
str(format(float(int(downloadable["size"])) / 1058816, ".2f"))
|
||||
+ " MiB"
|
||||
)
|
||||
|
||||
audioDict = {
|
||||
"Type": AudioDescription,
|
||||
"Drm": downloadable["isDrm"],
|
||||
"Original": Original,
|
||||
"Language": LanguageName,
|
||||
"langAbbrev": LanguageCode,
|
||||
"Size": size,
|
||||
"Url": aud_url,
|
||||
"channels": str(downloadable["channels"]),
|
||||
"Bitrate": str(downloadable["bitrate"]),
|
||||
"Profile": downloadable["content_profile"],
|
||||
}
|
||||
|
||||
if self.args.custom_audio_bitrate:
|
||||
# only append the audio langs with the given bitrate
|
||||
if int(downloadable["bitrate"]) <= \
|
||||
int(self.args.custom_audio_bitrate[0]):
|
||||
AudioList.append(audioDict)
|
||||
else:
|
||||
AudioList.append(audioDict)
|
||||
|
||||
AudioList = sorted(AudioList, key=lambda k: int(k["Bitrate"]), reverse=True)
|
||||
|
||||
self.logger.debug("AudioList: {}".format(AudioList))
|
||||
|
||||
#################################################################################
|
||||
|
||||
AudioList = sorted( # keep only highest bitrate for every language
|
||||
remove_dups(AudioList, keyword="Language"),
|
||||
key=lambda k: int(k["Bitrate"]),
|
||||
reverse=True,
|
||||
)
|
||||
|
||||
OriginalAudioList = ( # for detect automatically forced subs ~
|
||||
AudioList
|
||||
if len(AudioList) == 1
|
||||
else [x for x in AudioList if x["Original"]]
|
||||
)
|
||||
|
||||
#################################################################################
|
||||
|
||||
# now parser AudioList based on user input to
|
||||
# --alang X X --AD X X or original if none
|
||||
|
||||
if self.args.AD:
|
||||
ADlist = list()
|
||||
UserLanguagesLower = list(map(lambda x: x.lower(), self.args.AD))
|
||||
for aud in AudioList:
|
||||
if aud['Type'] == 'Audio':
|
||||
if self.args.allaudios:
|
||||
ADlist.append(aud)
|
||||
else:
|
||||
if aud["Original"]:
|
||||
ADlist.append(aud)
|
||||
|
||||
if aud['Type'] == 'Audio Description':
|
||||
if (
|
||||
aud["Language"].lower() in UserLanguagesLower
|
||||
or aud["langAbbrev"].lower() in UserLanguagesLower
|
||||
):
|
||||
ADlist.append(aud)
|
||||
|
||||
AudioList = ADlist
|
||||
|
||||
if self.args.audiolang:
|
||||
NewAudioList = list()
|
||||
UserLanguagesLower = list(map(lambda x: x.lower(), self.args.audiolang))
|
||||
for aud in AudioList:
|
||||
if self.args.AD:
|
||||
# I already have AD langs parsed
|
||||
if aud['Type'] == 'Audio Description':
|
||||
NewAudioList.append(aud)
|
||||
if aud['Type'] == 'Audio':
|
||||
if (
|
||||
aud["Language"].lower() in UserLanguagesLower
|
||||
or aud["langAbbrev"].lower() in UserLanguagesLower
|
||||
):
|
||||
NewAudioList.append(aud)
|
||||
|
||||
AudioList = NewAudioList
|
||||
|
||||
else:
|
||||
# so I know have the complete Audiolist
|
||||
if self.args.allaudios: # remove AD tracks if not --AD X X
|
||||
AllaudiosList = list()
|
||||
if self.args.AD:
|
||||
for aud in AudioList:
|
||||
AllaudiosList.append(aud)
|
||||
AudioList = AllaudiosList
|
||||
else:
|
||||
for aud in AudioList:
|
||||
if aud['Type'] == 'Audio':
|
||||
AllaudiosList.append(aud)
|
||||
AudioList.clear()
|
||||
AudioList = AllaudiosList
|
||||
|
||||
else:
|
||||
if self.args.AD:
|
||||
AudioList = AudioList # I mean the ADlist
|
||||
else:
|
||||
# I mean no audio options are given, so we go with the original
|
||||
AudioList = [x for x in AudioList if x["Original"] or len(AudioList) == 1]
|
||||
|
||||
#####################################(Subtitles)#####################################
|
||||
|
||||
for text_track in manifest["timedtexttracks"]:
|
||||
if (
|
||||
not text_track["languageDescription"] == "Off"
|
||||
and text_track["language"] is not None
|
||||
):
|
||||
Language, langAbbrev = self.ripprocess.countrycode(
|
||||
text_track["language"]
|
||||
)
|
||||
Language = text_track["languageDescription"]
|
||||
Type = text_track["trackType"]
|
||||
rawTrackType = (
|
||||
text_track["rawTrackType"]
|
||||
.replace("closedcaptions", "CC")
|
||||
.replace("subtitles", "SUB")
|
||||
)
|
||||
isForced = "NO"
|
||||
|
||||
if (
|
||||
"CC" in rawTrackType
|
||||
and langAbbrev != "ara"
|
||||
and "dfxp-ls-sdh" in str(text_track["ttDownloadables"])
|
||||
):
|
||||
Profile = "dfxp-ls-sdh"
|
||||
Url = next(
|
||||
iter(
|
||||
text_track["ttDownloadables"]["dfxp-ls-sdh"][
|
||||
"downloadUrls"
|
||||
].values()
|
||||
)
|
||||
)
|
||||
else:
|
||||
Profile = "webvtt-lssdh-ios8"
|
||||
Url = next(
|
||||
iter(
|
||||
text_track["ttDownloadables"]["webvtt-lssdh-ios8"][
|
||||
"downloadUrls"
|
||||
].values()
|
||||
)
|
||||
)
|
||||
|
||||
SubtitleList.append(
|
||||
{
|
||||
"Type": Type,
|
||||
"rawTrackType": rawTrackType,
|
||||
"Language": Language,
|
||||
"isForced": isForced,
|
||||
"langAbbrev": langAbbrev,
|
||||
"Url": Url,
|
||||
"Profile": Profile,
|
||||
}
|
||||
)
|
||||
|
||||
self.logger.debug("SubtitleList: {}".format(SubtitleList))
|
||||
SubtitleList = remove_dups(SubtitleList, keyword="Language")
|
||||
|
||||
if self.args.sublang:
|
||||
NewSubtitleList = list()
|
||||
UserLanguagesLower = list(map(lambda x: x.lower(), self.args.sublang))
|
||||
for sub in SubtitleList:
|
||||
if (
|
||||
sub["Language"].lower() in UserLanguagesLower
|
||||
or sub["langAbbrev"].lower() in UserLanguagesLower
|
||||
):
|
||||
NewSubtitleList.append(sub)
|
||||
SubtitleList = remove_dups(NewSubtitleList, keyword="Language")
|
||||
|
||||
#####################################(Forced Subtitles)###############################
|
||||
|
||||
for text_track in manifest["timedtexttracks"]:
|
||||
if text_track["isForcedNarrative"] and text_track["language"] is not None:
|
||||
LanguageName, LanguageCode = self.ripprocess.countrycode(
|
||||
text_track["language"]
|
||||
)
|
||||
# LanguageName = text_track["languageDescription"] # no i will use pycountry instead bcs it's off dude.
|
||||
ForcedList.append(
|
||||
{
|
||||
"Type": text_track["trackType"],
|
||||
"rawTrackType": text_track["rawTrackType"]
|
||||
.replace("closedcaptions", "CC ")
|
||||
.replace("subtitles", "SUB"),
|
||||
"Language": LanguageName,
|
||||
"isForced": "YES",
|
||||
"langAbbrev": LanguageCode,
|
||||
"Url": next(
|
||||
iter(
|
||||
text_track["ttDownloadables"]["webvtt-lssdh-ios8"][
|
||||
"downloadUrls"
|
||||
].values()
|
||||
)
|
||||
),
|
||||
"Profile": "webvtt-lssdh-ios8",
|
||||
}
|
||||
)
|
||||
|
||||
ForcedList = remove_dups(ForcedList, keyword="Language")
|
||||
|
||||
if self.args.forcedlang:
|
||||
NewForcedList = []
|
||||
UserLanguagesLower = list(map(lambda x: x.lower(), self.args.forcedlang))
|
||||
for sub in ForcedList:
|
||||
if (
|
||||
sub["Language"].lower() in UserLanguagesLower
|
||||
or sub["langAbbrev"].lower() in UserLanguagesLower
|
||||
):
|
||||
NewForcedList.append(sub)
|
||||
ForcedList = remove_dups(NewForcedList, keyword="Language")
|
||||
else:
|
||||
if not self.args.allforcedlang:
|
||||
if len(OriginalAudioList) != 0:
|
||||
OriginalLanguage = OriginalAudioList[0]["langAbbrev"]
|
||||
ForcedList = [
|
||||
x for x in ForcedList if x["langAbbrev"] == OriginalLanguage
|
||||
]
|
||||
|
||||
return AudioList, SubtitleList, ForcedList
|
||||
|
||||
def LoadManifest(self):
|
||||
|
||||
profiles, getHigh = self.LoadProfies()
|
||||
|
||||
if self.args.hevc:
|
||||
self.logger.info("Getting HEVC Manifest...")
|
||||
elif self.args.hdr:
|
||||
self.logger.info("Getting HDR-10 Manifest...")
|
||||
elif self.args.video_high:
|
||||
self.logger.info("Getting High Profile Manifest...")
|
||||
else:
|
||||
self.logger.info("Getting Main Profile Manifest...")
|
||||
|
||||
resp = self.PyMSL(profiles=profiles)
|
||||
|
||||
if not resp:
|
||||
if self.args.hevc:
|
||||
profiles, getHigh = self.LoadProfies(addHEVCDO=True)
|
||||
self.logger.info('\nGetting HEVC DO Manifest...')
|
||||
resp = self.PyMSL(profiles=profiles)
|
||||
|
||||
if not resp:
|
||||
self.logger.info("Failed getting Manifest")
|
||||
exit(-1)
|
||||
|
||||
VideoList, checkerinfo = self.ParseVideo(resp, getHigh)
|
||||
AudioList, SubtitleList, ForcedList = self.ParseAudioSubs(resp)
|
||||
|
||||
return VideoList, AudioList, SubtitleList, ForcedList, checkerinfo
|
||||
Reference in New Issue
Block a user