aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp
diff options
context:
space:
mode:
Diffstat (limited to 'yt_dlp')
-rw-r--r--yt_dlp/YoutubeDL.py1
-rw-r--r--yt_dlp/__init__.py70
-rw-r--r--yt_dlp/downloader/hls.py4
-rw-r--r--yt_dlp/extractor/iqiyi.py174
-rw-r--r--yt_dlp/extractor/ivi.py2
-rw-r--r--yt_dlp/options.py9
-rw-r--r--yt_dlp/update.py283
-rw-r--r--yt_dlp/utils.py7
8 files changed, 45 insertions, 505 deletions
diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py
index c6882d0d7..de8a8c4d2 100644
--- a/yt_dlp/YoutubeDL.py
+++ b/yt_dlp/YoutubeDL.py
@@ -47,7 +47,6 @@ from .postprocessor import (
MoveFilesAfterDownloadPP,
get_postprocessor,
)
-from .update import detect_variant
from .utils import (
DEFAULT_OUTTMPL,
IDENTITY,
diff --git a/yt_dlp/__init__.py b/yt_dlp/__init__.py
index 357be861b..0c68f8571 100644
--- a/yt_dlp/__init__.py
+++ b/yt_dlp/__init__.py
@@ -1,6 +1,7 @@
+#!/usr/bin/python
f'You are using an unsupported version of Python. Only Python versions 3.6 and above are supported by yt-dlp' # noqa: F541
-__license__ = 'Public Domain'
+__license__ = 'CC0-1.0'
import getpass
import itertools
@@ -88,27 +89,28 @@ def print_extractor_information(opts, urls):
out = ''
if opts.list_extractors:
- urls = dict.fromkeys(urls, False)
- for ie in list_extractor_classes(opts.age_limit):
- out += ie.IE_NAME + (' (CURRENTLY BROKEN)' if not ie.working() else '') + '\n'
- if ie == GenericIE:
- matched_urls = [url for url, matched in urls.items() if not matched]
- else:
- matched_urls = tuple(filter(ie.suitable, urls.keys()))
- urls.update(dict.fromkeys(matched_urls, True))
- out += ''.join(f' {url}\n' for url in matched_urls)
+ for ie in list_extractors(opts.age_limit):
+ write_string(ie.IE_NAME + (' (CURRENTLY BROKEN)' if not ie.working() else '') + '\n', out=sys.stdout)
+ matchedUrls = [url for url in urls if ie.suitable(url)]
+ for mu in matchedUrls:
+ write_string(' ' + mu + '\n', out=sys.stdout)
elif opts.list_extractor_descriptions:
- _SEARCHES = ('cute kittens', 'slithering pythons', 'falling cat', 'angry poodle', 'purple fish', 'running tortoise', 'sleeping bunny', 'burping cow')
- out = '\n'.join(
- ie.description(markdown=False, search_examples=_SEARCHES)
- for ie in list_extractor_classes(opts.age_limit) if ie.working() and ie.IE_DESC is not False)
+ for ie in list_extractors(opts.age_limit):
+ if not ie.working():
+ continue
+ if ie.IE_DESC is False:
+ continue
+ desc = ie.IE_DESC or ie.IE_NAME
+ if getattr(ie, 'SEARCH_KEY', None) is not None:
+ _SEARCHES = ('cute kittens', 'slithering pythons', 'falling cat', 'angry poodle', 'purple fish', 'running tortoise', 'sleeping bunny', 'burping cow')
+ _COUNTS = ('', '5', '10', 'all')
+ desc += f'; "{ie.SEARCH_KEY}:" prefix (Example: "{ie.SEARCH_KEY}{random.choice(_COUNTS)}:{random.choice(_SEARCHES)}")'
+ write_string(desc + '\n', out=sys.stdout)
elif opts.ap_list_mso:
- out = 'Supported TV Providers:\n%s\n' % render_table(
- ['mso', 'mso name'],
- [[mso_id, mso_info['name']] for mso_id, mso_info in MSO_INFO.items()])
+ table = [[mso_id, mso_info['name']] for mso_id, mso_info in MSO_INFO.items()]
+ write_string('Supported TV Providers:\n' + render_table(['mso', 'mso name'], table) + '\n', out=sys.stdout)
else:
return False
- write_string(out, out=sys.stdout)
return True
@@ -457,15 +459,13 @@ def validate_options(opts):
report_conflict('--playlist-random', 'playlist_random', '--lazy-playlist', 'lazy_playlist')
report_conflict('--dateafter', 'dateafter', '--date', 'date', default=None)
report_conflict('--datebefore', 'datebefore', '--date', 'date', default=None)
- report_conflict('--exec-before-download', 'exec_before_dl_cmd',
- '"--exec before_dl:"', 'exec_cmd', val2=opts.exec_cmd.get('before_dl'))
+ report_conflict('--exec-before-download', 'exec_before_dl_cmd', '"--exec before_dl:"', 'exec_cmd', opts.exec_cmd.get('before_dl'))
report_conflict('--id', 'useid', '--output', 'outtmpl', val2=opts.outtmpl.get('default'))
report_conflict('--remux-video', 'remuxvideo', '--recode-video', 'recodevideo')
report_conflict('--sponskrub', 'sponskrub', '--remove-chapters', 'remove_chapters')
report_conflict('--sponskrub', 'sponskrub', '--sponsorblock-mark', 'sponsorblock_mark')
report_conflict('--sponskrub', 'sponskrub', '--sponsorblock-remove', 'sponsorblock_remove')
- report_conflict('--sponskrub-cut', 'sponskrub_cut', '--split-chapter', 'split_chapters',
- val1=opts.sponskrub and opts.sponskrub_cut)
+ report_conflict('--sponskrub-cut', 'sponskrub_cut', '--split-chapter', 'split_chapters', val1=opts.sponskrub and opts.sponskrub_cut)
# Conflicts with --allow-unplayable-formats
report_conflict('--add-metadata', 'addmetadata')
@@ -474,7 +474,7 @@ def validate_options(opts):
report_conflict('--embed-subs', 'embedsubtitles')
report_conflict('--embed-thumbnail', 'embedthumbnail')
report_conflict('--extract-audio', 'extractaudio')
- report_conflict('--fixup', 'fixup', val1=opts.fixup not in (None, 'never', 'ignore'), default='never')
+ report_conflict('--fixup', 'fixup', val1=(opts.fixup or '').lower() in ('', 'never', 'ignore'), default='never')
report_conflict('--recode-video', 'recodevideo')
report_conflict('--remove-chapters', 'remove_chapters', default=[])
report_conflict('--remux-video', 'remuxvideo')
@@ -678,11 +678,11 @@ def parse_options(argv=None):
postprocessors = list(get_postprocessors(opts))
- print_only = bool(opts.forceprint) and all(k not in opts.forceprint for k in POSTPROCESS_WHEN[2:])
- any_getting = any(getattr(opts, k) for k in (
- 'dumpjson', 'dump_single_json', 'getdescription', 'getduration', 'getfilename',
- 'getformat', 'getid', 'getthumbnail', 'gettitle', 'geturl'
- ))
+ any_getting = (any(opts.forceprint.values()) or opts.dumpjson or opts.dump_single_json
+ or opts.geturl or opts.gettitle or opts.getid or opts.getthumbnail
+ or opts.getdescription or opts.getfilename or opts.getformat or opts.getduration)
+
+ any_printing = opts.print_json
final_ext = (
opts.recodevideo if opts.recodevideo in FFmpegVideoConvertorPP.SUPPORTED_EXTS
@@ -700,10 +700,7 @@ def parse_options(argv=None):
'ap_mso': opts.ap_mso,
'ap_username': opts.ap_username,
'ap_password': opts.ap_password,
- 'client_certificate': opts.client_certificate,
- 'client_certificate_key': opts.client_certificate_key,
- 'client_certificate_password': opts.client_certificate_password,
- 'quiet': opts.quiet or any_getting or opts.print_json or bool(opts.forceprint),
+ 'quiet': (opts.quiet or any_getting or any_printing),
'no_warnings': opts.no_warnings,
'forceurl': opts.geturl,
'forcetitle': opts.gettitle,
@@ -718,7 +715,7 @@ def parse_options(argv=None):
'forcejson': opts.dumpjson or opts.print_json,
'dump_single_json': opts.dump_single_json,
'force_write_download_archive': opts.force_write_download_archive,
- 'simulate': (print_only or any_getting or None) if opts.simulate is None else opts.simulate,
+ 'simulate': (any_getting or None) if opts.simulate is None else opts.simulate,
'skip_download': opts.skip_download,
'format': opts.format,
'allow_unplayable_formats': opts.allow_unplayable_formats,
@@ -867,6 +864,13 @@ def parse_options(argv=None):
def _real_main(argv=None):
+ # Compatibility fixes for Windows
+ if sys.platform == 'win32':
+ # https://github.com/ytdl-org/youtube-dl/issues/820
+ codecs.register(lambda name: codecs.lookup('utf-8') if name == 'cp65001' else None)
+
+ workaround_optparse_bug9161()
+
setproctitle('yt-dlp')
parser, opts, all_urls, ydl_opts = parse_options(argv)
diff --git a/yt_dlp/downloader/hls.py b/yt_dlp/downloader/hls.py
index 1e75c5e9c..f54b3f473 100644
--- a/yt_dlp/downloader/hls.py
+++ b/yt_dlp/downloader/hls.py
@@ -65,9 +65,9 @@ class HlsFD(FragmentFD):
has_ffmpeg = FFmpegFD.available()
no_crypto = not Cryptodome_AES and '#EXT-X-KEY:METHOD=AES-128' in s
if no_crypto and has_ffmpeg:
- can_download, message = False, 'The stream has AES-128 encryption and pycryptodomex is not available'
+ can_download, message = False, 'The stream has AES-128 encryption and pycryptodome is not available'
elif no_crypto:
- message = ('The stream has AES-128 encryption and neither ffmpeg nor pycryptodomex are available; '
+ message = ('The stream has AES-128 encryption and neither ffmpeg nor pycryptodome are available; '
'Decryption will be performed natively, but will be extremely slow')
elif re.search(r'#EXT-X-MEDIA-SEQUENCE:(?!0$)', s):
install_ffmpeg = '' if has_ffmpeg else 'install ffmpeg and '
diff --git a/yt_dlp/extractor/iqiyi.py b/yt_dlp/extractor/iqiyi.py
index 35691ec20..5c316687c 100644
--- a/yt_dlp/extractor/iqiyi.py
+++ b/yt_dlp/extractor/iqiyi.py
@@ -6,13 +6,11 @@ import time
from .common import InfoExtractor
from ..compat import (
compat_str,
- compat_urllib_parse_urlencode,
compat_urllib_parse_unquote
)
from .openload import PhantomJSwrapper
from ..utils import (
clean_html,
- decode_packed_codes,
ExtractorError,
float_or_none,
format_field,
@@ -37,135 +35,6 @@ def md5_text(text):
return hashlib.md5(text.encode('utf-8')).hexdigest()
-class IqiyiSDK:
- def __init__(self, target, ip, timestamp):
- self.target = target
- self.ip = ip
- self.timestamp = timestamp
-
- @staticmethod
- def split_sum(data):
- return compat_str(sum(map(lambda p: int(p, 16), list(data))))
-
- @staticmethod
- def digit_sum(num):
- if isinstance(num, int):
- num = compat_str(num)
- return compat_str(sum(map(int, num)))
-
- def even_odd(self):
- even = self.digit_sum(compat_str(self.timestamp)[::2])
- odd = self.digit_sum(compat_str(self.timestamp)[1::2])
- return even, odd
-
- def preprocess(self, chunksize):
- self.target = md5_text(self.target)
- chunks = []
- for i in range(32 // chunksize):
- chunks.append(self.target[chunksize * i:chunksize * (i + 1)])
- if 32 % chunksize:
- chunks.append(self.target[32 - 32 % chunksize:])
- return chunks, list(map(int, self.ip.split('.')))
-
- def mod(self, modulus):
- chunks, ip = self.preprocess(32)
- self.target = chunks[0] + ''.join(map(lambda p: compat_str(p % modulus), ip))
-
- def split(self, chunksize):
- modulus_map = {
- 4: 256,
- 5: 10,
- 8: 100,
- }
-
- chunks, ip = self.preprocess(chunksize)
- ret = ''
- for i in range(len(chunks)):
- ip_part = compat_str(ip[i] % modulus_map[chunksize]) if i < 4 else ''
- if chunksize == 8:
- ret += ip_part + chunks[i]
- else:
- ret += chunks[i] + ip_part
- self.target = ret
-
- def handle_input16(self):
- self.target = md5_text(self.target)
- self.target = self.split_sum(self.target[:16]) + self.target + self.split_sum(self.target[16:])
-
- def handle_input8(self):
- self.target = md5_text(self.target)
- ret = ''
- for i in range(4):
- part = self.target[8 * i:8 * (i + 1)]
- ret += self.split_sum(part) + part
- self.target = ret
-
- def handleSum(self):
- self.target = md5_text(self.target)
- self.target = self.split_sum(self.target) + self.target
-
- def date(self, scheme):
- self.target = md5_text(self.target)
- d = time.localtime(self.timestamp)
- strings = {
- 'y': compat_str(d.tm_year),
- 'm': '%02d' % d.tm_mon,
- 'd': '%02d' % d.tm_mday,
- }
- self.target += ''.join(map(lambda c: strings[c], list(scheme)))
-
- def split_time_even_odd(self):
- even, odd = self.even_odd()
- self.target = odd + md5_text(self.target) + even
-
- def split_time_odd_even(self):
- even, odd = self.even_odd()
- self.target = even + md5_text(self.target) + odd
-
- def split_ip_time_sum(self):
- chunks, ip = self.preprocess(32)
- self.target = compat_str(sum(ip)) + chunks[0] + self.digit_sum(self.timestamp)
-
- def split_time_ip_sum(self):
- chunks, ip = self.preprocess(32)
- self.target = self.digit_sum(self.timestamp) + chunks[0] + compat_str(sum(ip))
-
-
-class IqiyiSDKInterpreter:
- def __init__(self, sdk_code):
- self.sdk_code = sdk_code
-
- def run(self, target, ip, timestamp):
- self.sdk_code = decode_packed_codes(self.sdk_code)
-
- functions = re.findall(r'input=([a-zA-Z0-9]+)\(input', self.sdk_code)
-
- sdk = IqiyiSDK(target, ip, timestamp)
-
- other_functions = {
- 'handleSum': sdk.handleSum,
- 'handleInput8': sdk.handle_input8,
- 'handleInput16': sdk.handle_input16,
- 'splitTimeEvenOdd': sdk.split_time_even_odd,
- 'splitTimeOddEven': sdk.split_time_odd_even,
- 'splitIpTimeSum': sdk.split_ip_time_sum,
- 'splitTimeIpSum': sdk.split_time_ip_sum,
- }
- for function in functions:
- if re.match(r'mod\d+', function):
- sdk.mod(int(function[3:]))
- elif re.match(r'date[ymd]{3}', function):
- sdk.date(function[4:])
- elif re.match(r'split\d+', function):
- sdk.split(int(function[5:]))
- elif function in other_functions:
- other_functions[function]()
- else:
- raise ExtractorError('Unknown function %s' % function)
-
- return sdk.target
-
-
class IqiyiIE(InfoExtractor):
IE_NAME = 'iqiyi'
IE_DESC = '爱奇艺'
@@ -246,47 +115,8 @@ class IqiyiIE(InfoExtractor):
return ohdave_rsa_encrypt(data, e, N)
- def _perform_login(self, username, password):
-
- data = self._download_json(
- 'http://kylin.iqiyi.com/get_token', None,
- note='Get token for logging', errnote='Unable to get token for logging')
- sdk = data['sdk']
- timestamp = int(time.time())
- target = '/apis/reglogin/login.action?lang=zh_TW&area_code=null&email=%s&passwd=%s&agenttype=1&from=undefined&keeplogin=0&piccode=&fromurl=&_pos=1' % (
- username, self._rsa_fun(password.encode('utf-8')))
-
- interp = IqiyiSDKInterpreter(sdk)
- sign = interp.run(target, data['ip'], timestamp)
-
- validation_params = {
- 'target': target,
- 'server': 'BEA3AA1908656AABCCFF76582C4C6660',
- 'token': data['token'],
- 'bird_src': 'f8d91d57af224da7893dd397d52d811a',
- 'sign': sign,
- 'bird_t': timestamp,
- }
- validation_result = self._download_json(
- 'http://kylin.iqiyi.com/validate?' + compat_urllib_parse_urlencode(validation_params), None,
- note='Validate credentials', errnote='Unable to validate credentials')
-
- MSG_MAP = {
- 'P00107': 'please login via the web interface and enter the CAPTCHA code',
- 'P00117': 'bad username or password',
- }
-
- code = validation_result['code']
- if code != 'A00000':
- msg = MSG_MAP.get(code)
- if not msg:
- msg = 'error %s' % code
- if validation_result.get('msg'):
- msg += ': ' + validation_result['msg']
- self.report_warning('unable to log in: ' + msg)
- return False
-
- return True
+ def _perform_login(self):
+ raise ExtractorError("iQiyi's non-free authentication algorithm has made login impossible", expected=True)
def get_raw_data(self, tvid, video_id):
tm = int(time.time() * 1000)
diff --git a/yt_dlp/extractor/ivi.py b/yt_dlp/extractor/ivi.py
index 699746943..f469a6adf 100644
--- a/yt_dlp/extractor/ivi.py
+++ b/yt_dlp/extractor/ivi.py
@@ -138,7 +138,7 @@ class IviIE(InfoExtractor):
elif site == 353:
continue
elif not pycryptodome_found:
- raise ExtractorError('pycryptodomex not found. Please install', expected=True)
+ raise ExtractorError('pycryptodome not found. Please install', expected=True)
elif message:
extractor_msg += ': ' + message
raise ExtractorError(extractor_msg % video_id, expected=True)
diff --git a/yt_dlp/options.py b/yt_dlp/options.py
index 8c9a9bbb4..dddd5b15b 100644
--- a/yt_dlp/options.py
+++ b/yt_dlp/options.py
@@ -19,7 +19,6 @@ from .postprocessor import (
SponsorBlockPP,
)
from .postprocessor.modify_chapters import DEFAULT_SPONSORBLOCK_CHAPTER_TITLE
-from .update import detect_variant
from .utils import (
OUTTMPL_TYPES,
POSTPROCESS_WHEN,
@@ -325,14 +324,6 @@ def create_parser():
action='version',
help='Print program version and exit')
general.add_option(
- '-U', '--update',
- action='store_true', dest='update_self',
- help='Update this program to latest version')
- general.add_option(
- '--no-update',
- action='store_false', dest='update_self',
- help='Do not update (default)')
- general.add_option(
'-i', '--ignore-errors',
action='store_true', dest='ignoreerrors',
help='Ignore download and postprocessing errors. The download will be considered successful even if the postprocessing fails')
diff --git a/yt_dlp/update.py b/yt_dlp/update.py
deleted file mode 100644
index 8e34f2127..000000000
--- a/yt_dlp/update.py
+++ /dev/null
@@ -1,283 +0,0 @@
-import atexit
-import hashlib
-import json
-import os
-import platform
-import subprocess
-import sys
-from zipimport import zipimporter
-
-from .compat import functools # isort: split
-from .compat import compat_realpath
-from .utils import Popen, shell_quote, traverse_obj, version_tuple
-from .version import __version__
-
-REPOSITORY = 'yt-dlp/yt-dlp'
-API_URL = f'https://api.github.com/repos/{REPOSITORY}/releases/latest'
-
-
-@functools.cache
-def _get_variant_and_executable_path():
- """@returns (variant, executable_path)"""
- if hasattr(sys, 'frozen'):
- path = sys.executable
- if not hasattr(sys, '_MEIPASS'):
- return 'py2exe', path
- if sys._MEIPASS == os.path.dirname(path):
- return f'{sys.platform}_dir', path
- return f'{sys.platform}_exe', path
-
- path = os.path.dirname(__file__)
- if isinstance(__loader__, zipimporter):
- return 'zip', os.path.join(path, '..')
- elif (os.path.basename(sys.argv[0]) in ('__main__.py', '-m')
- and os.path.exists(os.path.join(path, '../.git/HEAD'))):
- return 'source', path
- return 'unknown', path
-
-
-def detect_variant():
- return _get_variant_and_executable_path()[0]
-
-
-_FILE_SUFFIXES = {
- 'zip': '',
- 'py2exe': '_min.exe',
- 'win32_exe': '.exe',
- 'darwin_exe': '_macos',
- 'linux_exe': '_linux',
-}
-
-_NON_UPDATEABLE_REASONS = {
- **{variant: None for variant in _FILE_SUFFIXES}, # Updatable
- **{variant: f'Auto-update is not supported for unpackaged {name} executable; Re-download the latest release'
- for variant, name in {'win32_dir': 'Windows', 'darwin_dir': 'MacOS', 'linux_dir': 'Linux'}.items()},
- 'source': 'You cannot update when running from source code; Use git to pull the latest changes',
- 'unknown': 'It looks like you installed yt-dlp with a package manager, pip or setup.py; Use that to update',
- 'other': 'It looks like you are using an unofficial build of yt-dlp; Build the executable again',
-}
-
-
-def is_non_updateable():
- return _NON_UPDATEABLE_REASONS.get(detect_variant(), _NON_UPDATEABLE_REASONS['other'])
-
-
-def _sha256_file(path):
- h = hashlib.sha256()
- mv = memoryview(bytearray(128 * 1024))
- with open(os.path.realpath(path), 'rb', buffering=0) as f:
- for n in iter(lambda: f.readinto(mv), 0):
- h.update(mv[:n])
- return h.hexdigest()
-
-
-class Updater:
- def __init__(self, ydl):
- self.ydl = ydl
-
- @functools.cached_property
- def _new_version_info(self):
- self.ydl.write_debug(f'Fetching release info: {API_URL}')
- return json.loads(self.ydl.urlopen(API_URL).read().decode())
-
- @property
- def current_version(self):
- """Current version"""
- return __version__
-
- @property
- def new_version(self):
- """Version of the latest release"""
- return self._new_version_info['tag_name']
-
- @property
- def has_update(self):
- """Whether there is an update available"""
- return version_tuple(__version__) < version_tuple(self.new_version)
-
- @functools.cached_property
- def filename(self):
- """Filename of the executable"""
- return compat_realpath(_get_variant_and_executable_path()[1])
-
- def _download(self, name=None):
- name = name or self.release_name
- url = traverse_obj(self._new_version_info, (
- 'assets', lambda _, v: v['name'] == name, 'browser_download_url'), get_all=False)
- if not url:
- raise Exception('Unable to find download URL')
- self.ydl.write_debug(f'Downloading {name} from {url}')
- return self.ydl.urlopen(url).read()
-
- @functools.cached_property
- def release_name(self):
- """The release filename"""
- label = _FILE_SUFFIXES[detect_variant()]
- if label and platform.architecture()[0][:2] == '32':
- label = f'_x86{label}'
- return f'yt-dlp{label}'
-
- @functools.cached_property
- def release_hash(self):
- """Hash of the latest release"""
- hash_data = dict(ln.split()[::-1] for ln in self._download('SHA2-256SUMS').decode().splitlines())
- return hash_data[self.release_name]
-
- def _report_error(self, msg, expected=False):
- self.ydl.report_error(msg, tb=False if expected else None)
-
- def _report_permission_error(self, file):
- self._report_error(f'Unable to write to {file}; Try running as administrator', True)
-
- def _report_network_error(self, action, delim=';'):
- self._report_error(f'Unable to {action}{delim} Visit https://github.com/{REPOSITORY}/releases/latest', True)
-
- def check_update(self):
- """Report whether there is an update available"""
- try:
- self.ydl.to_screen(
- f'Latest version: {self.new_version}, Current version: {self.current_version}')
- except Exception:
- return self._report_network_error('obtain version info', delim='; Please try again later or')
-
- if not self.has_update:
- return self.ydl.to_screen(f'yt-dlp is up to date ({__version__})')
-
- if not is_non_updateable():
- self.ydl.to_screen(f'Current Build Hash {_sha256_file(self.filename)}')
- return True
-
- def update(self):
- """Update yt-dlp executable to the latest version"""
- if not self.check_update():
- return
- err = is_non_updateable()
- if err:
- return self._report_error(err, True)
- self.ydl.to_screen(f'Updating to version {self.new_version} ...')
-
- directory = os.path.dirname(self.filename)
- if not os.access(self.filename, os.W_OK):
- return self._report_permission_error(self.filename)
- elif not os.access(directory, os.W_OK):
- return self._report_permission_error(directory)
-
- new_filename, old_filename = f'{self.filename}.new', f'{self.filename}.old'
- if detect_variant() == 'zip': # Can be replaced in-place
- new_filename, old_filename = self.filename, None
-
- try:
- if os.path.exists(old_filename or ''):
- os.remove(old_filename)
- except OSError:
- return self._report_error('Unable to remove the old version')
-
- try:
- newcontent = self._download()
- except OSError:
- return self._report_network_error('download latest version')
- except Exception:
- return self._report_network_error('fetch updates')
-
- try:
- expected_hash = self.release_hash
- except Exception:
- self.ydl.report_warning('no hash information found for the release')
- else:
- if hashlib.sha256(newcontent).hexdigest() != expected_hash:
- return self._report_network_error('verify the new executable')
-
- try:
- with open(new_filename, 'wb') as outf:
- outf.write(newcontent)
- except OSError:
- return self._report_permission_error(new_filename)
-
- try:
- if old_filename:
- os.rename(self.filename, old_filename)
- except OSError:
- return self._report_error('Unable to move current version')
- try:
- if old_filename:
- os.rename(new_filename, self.filename)
- except OSError:
- self._report_error('Unable to overwrite current version')
- return os.rename(old_filename, self.filename)
-
- if detect_variant() not in ('win32_exe', 'py2exe'):
- if old_filename:
- os.remove(old_filename)
- else:
- atexit.register(Popen, f'ping 127.0.0.1 -n 5 -w 1000 & del /F "{old_filename}"',
- shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
-
- self.ydl.to_screen(f'Updated yt-dlp to version {self.new_version}')
- return True
-
- @functools.cached_property
- def cmd(self):
- """The command-line to run the executable, if known"""
- # There is no sys.orig_argv in py < 3.10. Also, it can be [] when frozen
- if getattr(sys, 'orig_argv', None):
- return sys.orig_argv
- elif hasattr(sys, 'frozen'):
- return sys.argv
-
- def restart(self):
- """Restart the executable"""
- assert self.cmd, 'Must be frozen or Py >= 3.10'
- self.ydl.write_debug(f'Restarting: {shell_quote(self.cmd)}')
- _, _, returncode = Popen.run(self.cmd)
- return returncode
-
-
-def run_update(ydl):
- """Update the program file with the latest version from the repository
- @returns Whether there was a successfull update (No update = False)
- """
- return Updater(ydl).update()
-
-
-# Deprecated
-def update_self(to_screen, verbose, opener):
- import traceback
-
- from .utils import write_string
-
- write_string(
- 'DeprecationWarning: "yt_dlp.update.update_self" is deprecated and may be removed in a future version. '
- 'Use "yt_dlp.update.run_update(ydl)" instead\n')
-
- printfn = to_screen
-
- class FakeYDL():
- to_screen = printfn
-
- def report_warning(self, msg, *args, **kwargs):
- return printfn(f'WARNING: {msg}', *args, **kwargs)
-
- def report_error(self, msg, tb=None):
- printfn(f'ERROR: {msg}')
- if not verbose:
- return
- if tb is None:
- # Copied from YoutubeDL.trouble
- if sys.exc_info()[0]:
- tb = ''
- if hasattr(sys.exc_info()[1], 'exc_info') and sys.exc_info()[1].exc_info[0]:
- tb += ''.join(traceback.format_exception(*sys.exc_info()[1].exc_info))
- tb += traceback.format_exc()
- else:
- tb_data = traceback.format_list(traceback.extract_stack())
- tb = ''.join(tb_data)
- if tb:
- printfn(tb)
-
- def write_debug(self, msg, *args, **kwargs):
- printfn(f'[debug] {msg}', *args, **kwargs)
-
- def urlopen(self, url):
- return opener.open(url)
-
- return run_update(FakeYDL())
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py
index 46a6c9fce..fba64be5a 100644
--- a/yt_dlp/utils.py
+++ b/yt_dlp/utils.py
@@ -980,10 +980,9 @@ def make_HTTPS_handler(params, **kwargs):
def bug_reports_message(before=';'):
- from .update import REPOSITORY
-
- msg = (f'please report this issue on https://github.com/{REPOSITORY}/issues?q= , '
- 'filling out the appropriate issue template. Confirm you are on the latest version using yt-dlp -U')
+ msg = ('please report this issue on https://issues.hyperbola.info/ , '
+ 'filling out the appropriate issue template. '
+ 'Confirm you are on the latest version using pacman -Su')
before = before.rstrip()
if not before or before.endswith(('.', '!', '?')):