ihabunek / twitch-dl

CLI tool for downloading videos from Twitch.
GNU General Public License v3.0
661 stars 84 forks source link

[Feature Request] Support proxy for download connection #127

Closed templateK closed 1 year ago

templateK commented 1 year ago

Twitch VOD/Clips are geo-blocked in some region. It will be nice to be able to use socks5 proxy for downloading just like yt-dlp

ihabunek commented 1 year ago

twitch-dl uses httpx which supports proxy configuration via environment variables. Could you try setting up a proxy using these? Docs here: https://www.python-httpx.org/environment_variables/#http_proxy-https_proxy-all_proxy

templateK commented 1 year ago

after setting ALL_PROXY I got following error message.

Looking up video...
Traceback (most recent call last):
  File "/tools/python/bin/twitch-dl", line 8, in <module>
    sys.exit(main())
  File "/tools/python/lib/python3.10/site-packages/twitchdl/console.py", line 321, in main
    args.func(args)
  File "/tools/python/lib/python3.10/site-packages/twitchdl/commands/download.py", line 170, in download
    download_one(video_id, args)
  File "/tools/python/lib/python3.10/site-packages/twitchdl/commands/download.py", line 176, in download_one
    return _download_video(video_id, args)
  File "/tools/python/lib/python3.10/site-packages/twitchdl/commands/download.py", line 268, in _download_video
    video = twitch.get_video(video_id)
  File "/tools/python/lib/python3.10/site-packages/twitchdl/twitch.py", line 103, in get_video
    response = gql_query(query)
  File "/tools/python/lib/python3.10/site-packages/twitchdl/twitch.py", line 44, in gql_query
    response = authenticated_post(url, json={"query": query}, headers=headers).json()
  File "/tools/python/lib/python3.10/site-packages/twitchdl/twitch.py", line 22, in authenticated_post
    response = httpx.post(url, data=data, json=json, headers=headers)
  File "/tools/python/lib/python3.10/site-packages/httpx/_api.py", line 304, in post
    return request(
  File "/tools/python/lib/python3.10/site-packages/httpx/_api.py", line 92, in request
    with Client(
  File "/tools/python/lib/python3.10/site-packages/httpx/_client.py", line 682, in __init__
    self._mounts: typing.Dict[URLPattern, typing.Optional[BaseTransport]] = {
  File "/tools/python/lib/python3.10/site-packages/httpx/_client.py", line 685, in <dictcomp>
    else self._init_proxy_transport(
  File "/tools/python/lib/python3.10/site-packages/httpx/_client.py", line 739, in _init_proxy_transport
    return HTTPTransport(
  File "/tools/python/lib/python3.10/site-packages/httpx/_transports/default.py", line 161, in __init__
    raise ImportError(
ImportError: Using SOCKS proxy, but the 'socksio' package is not installed. Make sure to install httpx using `pip install httpx[socks]`

So , I installed dependency with pip install httpx[socks]. After that It works like charm.

Thank you.