Last active
June 3, 2017 10:59
-
-
Save zed/2c4d48aa8a6acd1dcb3a596475d5c3d8 to your computer and use it in GitHub Desktop.
Revisions
-
zed revised this gist
Jun 3, 2017 . No changes.There are no files selected for viewing
-
zed revised this gist
Jun 3, 2017 . 1 changed file with 10 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,28 +1,30 @@ #!/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() -
zed revised this gist
Jun 3, 2017 . 1 changed file with 13 additions and 17 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,30 +3,26 @@ Send url to remote (desktop) VLC using http interface https://wiki.videolan.org/VLC_HTTP_requests/ XXX find remote vlc using bonjour service """ import base64 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 = 'me', 8080 username, password = '', 'vlcremote' # same settings as for VLC Remote on iOS 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() urlopen(Request(url, headers={'Authorization': # send auth unconditionally b'Basic ' + base64.b64encode(credentials)})).close() -
zed created this gist
Jun 3, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ #!/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)