Here's some example code I wrote, in the form of a few ZSH shell scripts:
https://github.com/chbarts/kodi-command-line
The logic should port nicely to other languages. In particular, it shows how to do things like playing a YouTube video using either the URL or just the hash, plus, of course, a way to play videos on the computer you're running the commands from.