Skip to content

Instantly share code, notes, and snippets.

@vzhd1701
Last active June 1, 2022 06:04
Show Gist options
  • Save vzhd1701/f8f8b2ee7b83baaa85fde4e37f02e3e6 to your computer and use it in GitHub Desktop.
Save vzhd1701/f8f8b2ee7b83baaa85fde4e37f02e3e6 to your computer and use it in GitHub Desktop.
How to use http proxy with python-vlc (libvlc)
import os
import platform
import time
from pathlib import Path
import vlc
if __name__ == "__main__":
# win32
# reads config
# https://github.com/videolan/vlc/blob/5e70837d8d766db6ca5052a2d4f503ad37243d9c/src/win32/netconf.c#L36
# char *proxy = config_GetPsz( (vlc_object_t *)(NULL), "http-proxy" );
# posix
# fallback to env variable http_proxy
# https://github.com/videolan/vlc/blob/5e70837d8d766db6ca5052a2d4f503ad37243d9c/src/posix/netconf.c#L119
# char *var = getenv("http_proxy");
# darwin
# only depends on system settings?
# https://github.com/videolan/vlc/blob/5e70837d8d766db6ca5052a2d4f503ad37243d9c/src/darwin/netconf.c#L45
test_proxy = "http://127.0.0.1:8080"
if platform.system() == "Windows":
config_file = Path("vlcrc")
config_file.write_text(f"http-proxy={test_proxy}\n")
vlc_instance = vlc.Instance(
[
"--no-ignore-config",
f"--config={config_file}",
]
)
else:
# doesn't actually work though, VLC Player ignores http proxy setting in Linux
# https://code.videolan.org/videolan/vlc/-/issues/26548
# https://code.videolan.org/videolan/vlc/-/issues/21226
os.environ["http_proxy"] = test_proxy
vlc_instance = vlc.Instance()
test_url = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
media_player = vlc_instance.media_player_new(test_url)
media_player.play()
while True:
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment