Skip to content

Commit

Permalink
Fixed incompatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsvivek committed Aug 26, 2023
1 parent 1b892b5 commit 784c94e
Show file tree
Hide file tree
Showing 110 changed files with 13,556 additions and 9,123 deletions.
2 changes: 1 addition & 1 deletion plugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"uuid": "videofetch",
"name": "VideoFetch",
"description": "A plugin for Free Download Manager to easily download YouTube videos.",
"version": "1.0.1",
"version": "1.0.2",
"icon": "icon.svg",
"mediaParser": true,
"mediaListParser": true,
Expand Down
187 changes: 111 additions & 76 deletions plugin/yt-dlp/yt_dlp/YoutubeDL.py

Large diffs are not rendered by default.

32 changes: 21 additions & 11 deletions plugin/yt-dlp/yt_dlp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import os
import re
import sys
import traceback

from .compat import compat_shlex_quote
from .cookies import SUPPORTED_BROWSERS, SUPPORTED_KEYRINGS
Expand Down Expand Up @@ -187,8 +188,8 @@ def validate_minmax(min_val, max_val, min_name, max_name=None):
raise ValueError(f'{max_name} "{max_val}" must be must be greater than or equal to {min_name} "{min_val}"')

# Usernames and passwords
validate(not opts.usenetrc or (opts.username is None and opts.password is None),
'.netrc', msg='using {name} conflicts with giving username/password')
validate(sum(map(bool, (opts.usenetrc, opts.netrc_cmd, opts.username))) <= 1, '.netrc',
msg='{name}, netrc command and username/password are mutually exclusive options')
validate(opts.password is None or opts.username is not None, 'account username', msg='{name} missing')
validate(opts.ap_password is None or opts.ap_username is not None,
'TV Provider account username', msg='{name} missing')
Expand Down Expand Up @@ -435,6 +436,10 @@ def metadataparser_actions(f):
elif ed and proto == 'default':
default_downloader = ed.get_basename()

for policy in opts.color.values():
if policy not in ('always', 'auto', 'no_color', 'never'):
raise ValueError(f'"{policy}" is not a valid color policy')

warnings, deprecation_warnings = [], []

# Common mistake: -f best
Expand Down Expand Up @@ -736,6 +741,7 @@ def parse_options(argv=None):
return ParsedOptions(parser, opts, urls, {
'usenetrc': opts.usenetrc,
'netrc_location': opts.netrc_location,
'netrc_cmd': opts.netrc_cmd,
'username': opts.username,
'password': opts.password,
'twofactor': opts.twofactor,
Expand Down Expand Up @@ -893,7 +899,7 @@ def parse_options(argv=None):
'playlist_items': opts.playlist_items,
'xattr_set_filesize': opts.xattr_set_filesize,
'match_filter': opts.match_filter,
'no_color': opts.no_color,
'color': opts.color,
'ffmpeg_location': opts.ffmpeg_location,
'hls_prefer_native': opts.hls_prefer_native,
'hls_use_mpegts': opts.hls_use_mpegts,
Expand Down Expand Up @@ -937,14 +943,18 @@ def _real_main(argv=None):
if opts.rm_cachedir:
ydl.cache.remove()

updater = Updater(ydl, opts.update_self if isinstance(opts.update_self, str) else None)
if opts.update_self and updater.update() and actual_use:
if updater.cmd:
return updater.restart()
# This code is reachable only for zip variant in py < 3.10
# It makes sense to exit here, but the old behavior is to continue
ydl.report_warning('Restart yt-dlp to use the updated version')
# return 100, 'ERROR: The program must exit for the update to complete'
try:
updater = Updater(ydl, opts.update_self)
if opts.update_self and updater.update() and actual_use:
if updater.cmd:
return updater.restart()
# This code is reachable only for zip variant in py < 3.10
# It makes sense to exit here, but the old behavior is to continue
ydl.report_warning('Restart yt-dlp to use the updated version')
# return 100, 'ERROR: The program must exit for the update to complete'
except Exception:
traceback.print_exc()
ydl._download_retcode = 100

if not actual_use:
if pre_process:
Expand Down
5 changes: 5 additions & 0 deletions plugin/yt-dlp/yt_dlp/casefold.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import warnings

warnings.warn(DeprecationWarning(f'{__name__} is deprecated'))

casefold = str.casefold
7 changes: 7 additions & 0 deletions plugin/yt-dlp/yt_dlp/compat/urllib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# flake8: noqa: F405
from urllib import * # noqa: F403

from ..compat_utils import passthrough_module

passthrough_module(__name__, 'urllib')
del passthrough_module
40 changes: 40 additions & 0 deletions plugin/yt-dlp/yt_dlp/compat/urllib/request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# flake8: noqa: F405
from urllib.request import * # noqa: F403

from ..compat_utils import passthrough_module

passthrough_module(__name__, 'urllib.request')
del passthrough_module


from .. import compat_os_name

if compat_os_name == 'nt':
# On older python versions, proxies are extracted from Windows registry erroneously. [1]
# If the https proxy in the registry does not have a scheme, urllib will incorrectly add https:// to it. [2]
# It is unlikely that the user has actually set it to be https, so we should be fine to safely downgrade
# it to http on these older python versions to avoid issues
# This also applies for ftp proxy type, as ftp:// proxy scheme is not supported.
# 1: https://github.com/python/cpython/issues/86793
# 2: https://github.com/python/cpython/blob/51f1ae5ceb0673316c4e4b0175384e892e33cc6e/Lib/urllib/request.py#L2683-L2698
import sys
from urllib.request import getproxies_environment, getproxies_registry

def getproxies_registry_patched():
proxies = getproxies_registry()
if (
sys.version_info >= (3, 10, 5) # https://docs.python.org/3.10/whatsnew/changelog.html#python-3-10-5-final
or (3, 9, 13) <= sys.version_info < (3, 10) # https://docs.python.org/3.9/whatsnew/changelog.html#python-3-9-13-final
):
return proxies

for scheme in ('https', 'ftp'):
if scheme in proxies and proxies[scheme].startswith(f'{scheme}://'):
proxies[scheme] = 'http' + proxies[scheme][len(scheme):]

return proxies

def getproxies():
return getproxies_environment() or getproxies_registry_patched()

del compat_os_name
Loading

0 comments on commit 784c94e

Please sign in to comment.