Skip to content

Instantly share code, notes, and snippets.

@zed
Last active June 3, 2017 10:59
Show Gist options
  • Save zed/2c4d48aa8a6acd1dcb3a596475d5c3d8 to your computer and use it in GitHub Desktop.
Save zed/2c4d48aa8a6acd1dcb3a596475d5c3d8 to your computer and use it in GitHub Desktop.

Revisions

  1. zed revised this gist Jun 3, 2017. No changes.
  2. zed revised this gist Jun 3, 2017. 1 changed file with 10 additions and 8 deletions.
    18 changes: 10 additions & 8 deletions __main__.py
    Original file line number Diff line number Diff line change
    @@ -1,28 +1,30 @@
    #!/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/
    Usage: play-youtube-video-on-remote-vlc <webpage-url>
    XXX find remote vlc using bonjour service
    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
    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
    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()
    urlopen(Request(url, headers={'Authorization': # send auth unconditionally
    b'Basic ' + base64.b64encode(credentials)})).close()
    headers = {'Authorization': # send auth unconditionally
    b'Basic ' + base64.b64encode(credentials)}
    urlopen(Request(url, headers=headers)).close()
  3. zed revised this gist Jun 3, 2017. 1 changed file with 13 additions and 17 deletions.
    30 changes: 13 additions & 17 deletions __main__.py
    Original 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 urlparse import quote

    #XXX use only stdlib
    import requests # $ pip install requests
    from urllib import quote
    from urllib2 import Request, urlopen

    #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"
    webpage_url = sys.argv[1]

    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)
    # 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()
  4. zed created this gist Jun 3, 2017.
    32 changes: 32 additions & 0 deletions __main__.py
    Original 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)