#程式主體和錯誤修正是由我設計、解決,chatgpt負責加入功能 from pytube import YouTube import ssl
from pytube.innertube import _default_clients from pytube import cipher import re #400錯誤解決代碼 (https://github.com/pytube/pytube/issues/1973) _default_clients["ANDROID"]["context"]["client"]["clientVersion"] = "19.08.35" _default_clients["IOS"]["context"]["client"]["clientVersion"] = "19.08.35" _default_clients["ANDROID_EMBED"]["context"]["client"]["clientVersion"] = "19.08.35" _default_clients["IOS_EMBED"]["context"]["client"]["clientVersion"] = "19.08.35" _default_clients["IOS_MUSIC"]["context"]["client"]["clientVersion"] = "6.41" _default_clients["ANDROID_MUSIC"] = _default_clients["ANDROID_CREATOR"]
defget_throttling_function_name(js: str) -> str: """Extract the name of the function that computes the throttling parameter. :param str js: The contents of the base.js asset file. :rtype: str :returns: The name of the function used to compute the throttling parameter. """ function_patterns = [ r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&\s*' r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])?\([a-z]\)', r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])\([a-z]\)', ] #logger.debug('Finding throttling function name') for pattern in function_patterns: regex = re.compile(pattern) function_match = regex.search(js) if function_match: #logger.debug("finished regex search, matched: %s", pattern) iflen(function_match.groups()) == 1: return function_match.group(1) idx = function_match.group(2) if idx: idx = idx.strip("[]") array = re.search( r'var {nfunc}\s*=\s*(\[.+?\]);'.format( nfunc=re.escape(function_match.group(1))), js ) if array: array = array.group(1).strip("[]").split(",") array = [x.strip() for x in array] return array[int(idx)]