Skip to content

Instantly share code, notes, and snippets.

@sphaero
Last active November 28, 2017 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sphaero/8de9b8fa65d589f50cc7afd315455286 to your computer and use it in GitHub Desktop.
Save sphaero/8de9b8fa65d589f50cc7afd315455286 to your computer and use it in GitHub Desktop.
Cast screen to kodi
#!/usr/bin/python3
#
# Cast screen to kodi, sort of like Chromecast functionality
#
# original version found on reddit:
# https://www.reddit.com/r/kodi/comments/5googi/push_stream_of_linux_desktop_to_kodi_using_vlc/
import sys
import time
import os
import subprocess
import json
import requests
import base64
str = subprocess.getstatusoutput("pacmd list-sources | awk '/name:.+\.monitor/'")[1]
sound_device = str[8:-1]
print(sound_device)
cmd = "cvlc screen:// :screen-fps=30.000 :screen-caching=80 :live-caching=300 --sout '#transcode{vcodec=mp4v,vb=4096,acodec=mpga,ab=128,sca=Auto,width=1024,height=768}:http{mux=ts,dst=:8080/}' --input-slave=pulse://"+sound_device+""
print(cmd)
subprocess.Popen(cmd, shell = True)
# PUSH TO KODI
time.sleep(.500)
usrPass = b"user_name:password"
b64Val = base64.b64encode(usrPass)
url = 'http://10.2.40.40:8080/jsonrpc'
payload = {"jsonrpc":"2.0", "id":1, "method": "Player.Open", "params":{"item":{"file":"http://10.2.40.97:8080?action=play_video"}}}
r=requests.post(url,
headers={"Authorization": "Basic %s" % b64Val,'content-type': 'application/json'},
data=json.dumps(payload))
print((r.content))
@sphaero
Copy link
Author

sphaero commented Nov 28, 2017

To stop casting just issue

pkill vlc

in a terminal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment