Custom TLS Cipher

pull/166/head
Puyodead1 2023-01-25 15:17:27 -05:00
parent 18a9c364af
commit 705de30925
No known key found for this signature in database
GPG Key ID: A4FA4FEC0DD353FC
2 changed files with 114 additions and 8 deletions

94
main.py
View File

@ -2,29 +2,32 @@
import argparse
import glob
import json
import logging
import os
import re
import subprocess
import sys
import time
from html.parser import HTMLParser as compat_HTMLParser
from pathlib import Path
from typing import IO
import cloudscraper
import m3u8
import requests
import yt_dlp
import logging
from constants import *
from bs4 import BeautifulSoup
from coloredlogs import ColoredFormatter
from pathlib import Path
from html.parser import HTMLParser as compat_HTMLParser
from dotenv import load_dotenv
from pathvalidate import sanitize_filename
from requests.exceptions import ConnectionError as conn_error
from tqdm import tqdm
from _version import __version__
from constants import *
from tls import SSLCiphers
from utils import extract_kid
from vtt_to_srt import convert
from _version import __version__
from bs4 import BeautifulSoup
from pathvalidate import sanitize_filename
retry = 3
cookies = ""
@ -790,6 +793,12 @@ class Session(object):
def __init__(self):
self._headers = HEADERS
self._session = requests.sessions.Session()
self._sesion.mount(
"https://",
SSLCiphers(
cipher_list="ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:AES256-SH"
),
)
def _set_auth_headers(self, bearer_token=""):
self._headers["Authorization"] = "Bearer {}".format(bearer_token)
@ -1026,7 +1035,76 @@ def handle_segments(url, format_id, video_title, output_path, lecture_file_name,
# for french language among others, this characters cause problems with shaka-packager resulting in decryption failure
# https://github.com/Puyodead1/udemy-downloader/issues/137
# Thank to cutecat !
file_name = file_name.replace("é", "e").replace("è", "e").replace("à", "a").replace("À", "A").replace("à", "a").replace("Á", "A").replace("á", "a").replace("Â", "a").replace("â", "a").replace("Ã", "A").replace("ã", "a").replace("Ä", "A").replace("ä", "a").replace("Å", "A").replace("å", "a").replace("Æ", "AE").replace("æ", "ae").replace("Ç", "C").replace("ç", "c").replace("Ð", "D").replace("ð", "o").replace("È", "E").replace("è", "e").replace("É", "e").replace("Ê", "e").replace("ê", "e").replace("Ë", "E").replace("ë", "e").replace("Ì", "I").replace("ì", "i").replace("Í", "I").replace("í", "I").replace("Î", "I").replace("î", "i").replace("Ï", "I").replace("ï", "i").replace("Ñ", "N").replace("ñ", "n").replace("Ò", "O").replace("ò", "o").replace("Ó", "O").replace("ó", "o").replace("Ô", "O").replace("ô", "o").replace("Õ", "O").replace("õ", "o").replace("Ö", "o").replace("ö", "o").replace("œ", "oe").replace("Œ", "OE").replace("Ø", "O").replace("ø", "o").replace("ß", "B").replace("Ù", "U").replace("ù", "u").replace("Ú", "U").replace("ú", "u").replace("Û", "U").replace("û", "u").replace("Ü", "U").replace("ü", "u").replace("Ý", "Y").replace("ý", "y").replace("Þ", "P").replace("þ", "P").replace("Ÿ", "Y").replace("ÿ", "y").replace("%", "")
file_name = (
file_name.replace("é", "e")
.replace("è", "e")
.replace("à", "a")
.replace("À", "A")
.replace("à", "a")
.replace("Á", "A")
.replace("á", "a")
.replace("Â", "a")
.replace("â", "a")
.replace("Ã", "A")
.replace("ã", "a")
.replace("Ä", "A")
.replace("ä", "a")
.replace("Å", "A")
.replace("å", "a")
.replace("Æ", "AE")
.replace("æ", "ae")
.replace("Ç", "C")
.replace("ç", "c")
.replace("Ð", "D")
.replace("ð", "o")
.replace("È", "E")
.replace("è", "e")
.replace("É", "e")
.replace("Ê", "e")
.replace("ê", "e")
.replace("Ë", "E")
.replace("ë", "e")
.replace("Ì", "I")
.replace("ì", "i")
.replace("Í", "I")
.replace("í", "I")
.replace("Î", "I")
.replace("î", "i")
.replace("Ï", "I")
.replace("ï", "i")
.replace("Ñ", "N")
.replace("ñ", "n")
.replace("Ò", "O")
.replace("ò", "o")
.replace("Ó", "O")
.replace("ó", "o")
.replace("Ô", "O")
.replace("ô", "o")
.replace("Õ", "O")
.replace("õ", "o")
.replace("Ö", "o")
.replace("ö", "o")
.replace("œ", "oe")
.replace("Œ", "OE")
.replace("Ø", "O")
.replace("ø", "o")
.replace("ß", "B")
.replace("Ù", "U")
.replace("ù", "u")
.replace("Ú", "U")
.replace("ú", "u")
.replace("Û", "U")
.replace("û", "u")
.replace("Ü", "U")
.replace("ü", "u")
.replace("Ý", "Y")
.replace("ý", "y")
.replace("Þ", "P")
.replace("þ", "P")
.replace("Ÿ", "Y")
.replace("ÿ", "y")
.replace("%", "")
)
# commas cause problems with shaka-packager resulting in decryption failure
file_name = file_name.replace(",", "")
file_name = file_name.replace(".mp4", "")

28
tls.py Normal file
View File

@ -0,0 +1,28 @@
import ssl
from typing import Optional
from requests.adapters import HTTPAdapter
class SSLCiphers(HTTPAdapter):
"""
Custom HTTP Adapter to change the TLS Cipher set, and therefore it's fingerprint.
"""
def __init__(self, cipher_list: Optional[str] = None, *args, **kwargs):
ctx = ssl.create_default_context()
ctx.check_hostname = False # For some reason this is needed to avoid a verification error
self._ssl_context = ctx
# You can set ciphers but Python's default cipher list should suffice.
# This cipher list differs to the default Python-requests one.
if cipher_list:
self._ssl_context.set_ciphers(cipher_list)
super().__init__(*args, **kwargs)
def init_poolmanager(self, *args, **kwargs):
kwargs["ssl_context"] = self._ssl_context
return super().init_poolmanager(*args, **kwargs)
def proxy_manager_for(self, *args, **kwargs):
kwargs["ssl_context"] = self._ssl_context
return super().proxy_manager_for(*args, **kwargs)