Skip to content

Instantly share code, notes, and snippets.

@jihunhong
Forked from hamidzr/playYoutube.sh
Created November 16, 2020 14:02
Show Gist options
  • Save jihunhong/58d31f167310e601198bc44d974a1831 to your computer and use it in GitHub Desktop.
Save jihunhong/58d31f167310e601198bc44d974a1831 to your computer and use it in GitHub Desktop.
Play youtube videos from commandline to kodi / xbmc.
#!/bin/bash
REGEX="^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*"
ID=$1
if [ "$ID" == "" ];
then
echo "Syntax $0 <id|url>"
exit
fi
if [[ $ID =~ $REGEX ]]; then
ID=${BASH_REMATCH[7]}
fi
echo "Sending request to play youtube video: $ID"
curl -s --data-binary '{"jsonrpc":"2.0","id":"1","method":"Application.SetVolume","params":{"volume":70}}' -H 'content-type: application/json;' http://localhost:8080/jsonrpc
curl -s --data-binary '{"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"file":"plugin://plugin.video.youtube/?action=play_video&videoid='$ID'"}}}' -H 'content-type: application/json;' http://localhost:8080/jsonrpc
#xbmc-send --action="SetVolume(70)"
#xbmc-send --action="PlayMedia(plugin://plugin.video.youtube/?action=play_video&videoid=$ID)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment