Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] Add support for proxies #33

Merged
merged 25 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c22d116
[plugin] pass proxy to the server
grqz Sep 17, 2024
cb7067e
sort import block
grqz Sep 17, 2024
40e4a2e
[debug] print proxies
grqz Sep 17, 2024
6142dea
stringify proxies
grqz Sep 17, 2024
1813218
Server side implementation WIP
Brainicism Sep 17, 2024
b5665f9
use ydl.urlopen again
Brainicism Sep 18, 2024
472e7e1
remove dundant object.values
Brainicism Sep 18, 2024
5928cad
remove ellipsis from the features tuple
grqz Sep 18, 2024
2e5bfc5
[plugin] remove redundant assignment to rh.proxies
grqx Sep 18, 2024
4ead3d2
Add error handling for bgutils functions
Brainicism Sep 18, 2024
32dd899
add support for proxies in process.env
grqx Sep 18, 2024
70f344e
variable naming
grqx Sep 18, 2024
a80e3cf
code formatting
grqx Sep 18, 2024
51a217a
process undefined proxy
grqx Sep 18, 2024
756c316
Error handling for bgConfig fetch
Brainicism Sep 18, 2024
9645c41
Merge branch 'server/proxy' of github.com:Brainicism/bgutil-ytdlp-pot…
Brainicism Sep 18, 2024
8385c3c
Add support for env ALL_PROXY
grqx Sep 18, 2024
6f7ecd2
code formatting
grqx Sep 18, 2024
7a0a9b0
Simplify retrieving proxy from env variables
Brainicism Sep 18, 2024
06728e7
Add trailing comma for _SUPPORTED_FEATURES
Brainicism Sep 18, 2024
74d2ba0
prioritise env HTTPS_PROXY over ALL_PROXY
grqx Sep 18, 2024
9d02474
Select proxy for youtube
Brainicism Sep 19, 2024
d97049e
Merge branch 'server/proxy' of github.com:Brainicism/bgutil-ytdlp-pot…
Brainicism Sep 19, 2024
231045e
switch to select_proxy with yt api hostname
grqx Sep 19, 2024
e1f7ea2
fix proxy type: bool->str
grqx Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion plugin/yt_dlp_plugins/extractor/getpot_bgutil_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
if typing.TYPE_CHECKING:
from yt_dlp import YoutubeDL

from yt_dlp.networking.common import Request
from yt_dlp.networking.common import Request, Features
grqz marked this conversation as resolved.
Show resolved Hide resolved
from yt_dlp.networking.exceptions import RequestError, UnsupportedRequest

try:

Check failure on line 12 in plugin/yt_dlp_plugins/extractor/getpot_bgutil_http.py

View workflow job for this annotation

GitHub Actions / Lint and format check

Ruff (I001)

plugin/yt_dlp_plugins/extractor/getpot_bgutil_http.py:9:1: I001 Import block is un-sorted or un-formatted
from yt_dlp_plugins.extractor.getpot import GetPOTProvider, register_preference, register_provider
except ImportError as e:
e.msg += '\nyt-dlp-get-pot is missing! See https://github.com/coletdjnz/yt-dlp-get-pot?tab=readme-ov-file#installing.'
Expand All @@ -23,6 +23,8 @@
_PROVIDER_NAME = 'BgUtilHTTPPot'
_SUPPORTED_CLIENTS = ('web', 'web_safari', 'web_embedded', 'web_music', 'web_creator', 'mweb', 'tv_embedded', 'tv')
VERSION = __version__
_SUPPORTED_PROXY_SCHEMES = ('http', 'https', 'socks5', ...)
_SUPPORTED_FEATURES = (Features.ALL_PROXY, ...)

def _validate_get_pot(self, client: str, ydl: YoutubeDL, visitor_data=None, data_sync_id=None, player_url=None, **kwargs):
base_url = ydl.get_info_extractor('Youtube')._configuration_arg(
Expand Down Expand Up @@ -58,6 +60,7 @@
'client': client,
'visitor_data': visitor_data,
'data_sync_id': data_sync_id,
'proxy': self.proxies, # maybe?
}).encode(), headers={'Content-Type': 'application/json'},
extensions={'timeout': 12.5}))
except Exception as e:
Expand All @@ -80,4 +83,5 @@

@register_preference(BgUtilHTTPPotProviderRH)
def bgutil_HTTP_getpot_preference(rh, request):
rh.proxies = rh._get_proxies(request)
grqz marked this conversation as resolved.
Show resolved Hide resolved
return 0
6 changes: 6 additions & 0 deletions plugin/yt_dlp_plugins/extractor/getpot_bgutil_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

if typing.TYPE_CHECKING:
from yt_dlp import YoutubeDL
from yt_dlp.networking.common import Features
from yt_dlp.networking.exceptions import RequestError, UnsupportedRequest
from yt_dlp.utils import Popen, classproperty

Expand All @@ -25,6 +26,8 @@ class BgUtilScriptPotProviderRH(GetPOTProvider):
_PROVIDER_NAME = 'BgUtilScriptPot'
_SUPPORTED_CLIENTS = ('web', 'web_safari', 'web_embedded', 'web_music', 'web_creator', 'mweb', 'tv_embedded', 'tv')
VERSION = __version__
_SUPPORTED_PROXY_SCHEMES = ('http', 'https', 'socks5', ...)
_SUPPORTED_FEATURES = (Features.ALL_PROXY, ...)

@classproperty(cache=True)
def _default_script_path(self):
Expand Down Expand Up @@ -53,6 +56,8 @@ def _get_pot(self, client: str, ydl: YoutubeDL, visitor_data=None, data_sync_id=
f'Generating POT via script: {self.script_path}')

command_args = ['node', self.script_path]
if proxy := self.proxies: # maybe?
command_args.extend(['-p', proxy])
if data_sync_id:
command_args.extend(['-d', data_sync_id])
elif visitor_data:
Expand Down Expand Up @@ -94,4 +99,5 @@ def _get_pot(self, client: str, ydl: YoutubeDL, visitor_data=None, data_sync_id=

@register_preference(BgUtilScriptPotProviderRH)
def bgutil_script_getpot_preference(rh, request):
rh.proxies = rh._get_proxies(request)
return 100
Loading