Skip to content

Instantly share code, notes, and snippets.

@zed
Last active June 3, 2017 10:59
Show Gist options
  • Select an option

  • Save zed/2c4d48aa8a6acd1dcb3a596475d5c3d8 to your computer and use it in GitHub Desktop.

Select an option

Save zed/2c4d48aa8a6acd1dcb3a596475d5c3d8 to your computer and use it in GitHub Desktop.
Play Youtube video on remote VLC.
#!/usr/bin/env python
"""Play Youtube video on remote VLC.
Send url to remote (desktop) VLC using http interface
https://wiki.videolan.org/VLC_HTTP_requests/
"""
import sys
try:
from urllib.parse import quote
except ImportError: # Python 2
from urlparse import quote
#XXX use only stdlib
import requests # $ pip install requests
#XXX find remote vlc using bonjour service
hostname, port = 'me', 8080
username, password = '', 'vlcremote' # same settings as for VLC Remote on iOS
webpage_url = sys.argv[1] if len(sys.argv) > 1 else "https://www.youtube.com/watch?v=ltAR3RadgQU"
media_url = webpage_url
#XXX get direct link to the media
# from youtube_dl import YoutubeDL # $ pip install youtube-dl
# with YoutubeDL(dict(forceurl=True)) as ydl:
# r = ydl.extract_info(webpage_url, download=False)
# media_url = r['formats'][-1]['url'] # best format
mrl = quote(media_url)
api_url = ('http://{hostname}:{port}/requests/status.xml?command=in_play&input={mrl}'
.format(**vars()))
r = requests.get(api_url, auth=(username, password))
print(r.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment