Telegram Bot or how to play video through terminal

I’m building a telegram bot. I use OSMC in Kodi shell. When I run Kodi, I run a script. And I want to add a command to play music or a movie. Through the bot I can run all the commands that can be used in the terminal. But I don’t know which command runs the movie or music playback. Could you tell me please what command Kodi is launching films. Thanks

Check out the json api
https://kodi.wiki/view/JSON-RPC_API

You can use the command “kodi-send” instead of json calls. Up to you :grinning:

https://forum.kodi.tv/showthread.php?tid=344076

I do not understand how to do(
for Example
I have video file /home/osmc/test.mp4
And I want this video to start 1 minute after kodi starts.

#Python Code
import xbmc

def runVideo():
#I do not understand what code to write in this function

time.sleep (60)
runVideo()

This my post. I read this document but still didn’t understand how to do it

Kodi-send is a command in shell:

And here is a list of actions:

https://kodi.wiki/view/List_of_built-in_functions

If I understand you correctly, it should turn out this way? ->

#Python Code
import xbmc

def runVideo():
kodi-send --action=PlayMedia(/home/osmc/test.mp4)

time.sleep (60)
runVideo()

What language are you writing your bot in? What you posted above it a mix of bash and python.

I write on phyton. But I do not understand how to write code for phyton to run a video file.

I’m not a python programmer, but this is what I understand a way to do it:

xbmc.PlayMedia(/home/osmc/test.mp4)

Here’s a python example that can run from any system, not just on the OSMC box:

#!/usr/bin/python

# Requirements:
# sudo apt install python-pip
# pip install kodi-json

from __future__ import print_function
from kodijson import Kodi

filename = '/path/to/file.mkv'
host = 'osmc.local' # Can also be localhost
port = '8080'

# Connect to kodi.
kodi = Kodi('http://{}:{}/jsonrpc'.format(host, port))

# Start playing the file
r = kodi.Player.Open({'item': {'file': filename}})

if 'error' in r:
    print("Item failed to play: {}".format(r['error']['message']))
if 'result' in r:
    print("Result: {}".format(r['result']))
2 Likes

Traceback (most recent call last):
File “tg.py”, line 18, in
r = kodi.Player.Open({‘item’: {‘file’: filename}})
File “build/bdist.linux-armv7l/egg/kodijson/kodijson.py”, line 97, in hook
File “build/bdist.linux-armv7l/egg/kodijson/kodijson.py”, line 63, in execute
File “/usr/lib/python2.7/dist-packages/requests/api.py”, line 110, in post
return request(‘post’, url, data=data, json=json, **kwargs)
File “/usr/lib/python2.7/dist-packages/requests/api.py”, line 56, in request
return session.request(method=method, url=url, **kwargs)
File “/usr/lib/python2.7/dist-packages/requests/sessions.py”, line 488, in request
resp = self.send(prep, **send_kwargs)
File “/usr/lib/python2.7/dist-packages/requests/sessions.py”, line 609, in send
r = adapter.send(request, **kwargs)
File “/usr/lib/python2.7/dist-packages/requests/adapters.py”, line 487, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host=‘localhost’, port=8080): Max retries exceeded with url: /jsonrpc (Caused by NewConnectionError(’<requests.packages.urllib3.connection.HTTPConnection object at 0x76719350>: Failed to establish a new connection: [Errno 111] Connection refused’,))

I have error

many thanks!
I fixed your code because the port was causing an error.
You helped me a lot)

Thank you all for your help

You did not ‘fix’ my code, you configured it to work in your environment :wink:

Glad to have been able to help, have fun with your project!