Last active
June 3, 2017 10:59
-
-
Save zed/2c4d48aa8a6acd1dcb3a596475d5c3d8 to your computer and use it in GitHub Desktop.
Play Youtube video on remote VLC.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Play Youtube video on remote VLC. | |
Usage: play-youtube-video-on-remote-vlc <webpage-url> | |
Send media url to remote (desktop) VLC using (Lua) http interface | |
https://wiki.videolan.org/VLC_HTTP_requests/ | |
""" | |
import base64 | |
import os | |
import sys | |
try: | |
from urllib.parse import quote | |
from urllib.request import Request, urlopen | |
except ImportError: # Python 2 | |
from urllib import quote | |
from urllib2 import Request, urlopen | |
hostname, port = os.environ['VLC_HOST'], os.environ['VLC_PORT'] | |
username, password = '', os.environ['VLC_PASS'] | |
webpage_url = sys.argv[1] | |
# enqueue & play immediately | |
url = ('http://{hostname}:{port}/requests/status.xml'.format(**vars()) | |
+ '?command=in_play&input=' + quote(webpage_url)) | |
credentials = '{username}:{password}'.format(**vars()).encode() | |
headers = {'Authorization': # send auth unconditionally | |
b'Basic ' + base64.b64encode(credentials)} | |
urlopen(Request(url, headers=headers)).close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment