Resources needed for simple python code
#1
I'm a bit new to Python, Kodi and Raspberry, so pardon me for asking apparently simple question. I looked quite a lot to find resources/examples about it and did not find anything really, so please point me at the good direction if you know some.

The goal of my project is to play 4k, HDR video in loop on a Raspberry pi 4 automatically at startup and been able to restart the video with a button connected to GPIO.

I'v read the best way to play that kind of video is with Kodi (did not succeed to read it with VLC easily) with HEVC codec.

So, I figure there is a way to play a video file through Kodi from a python script?

How do we do that? I guess I need to use xbmc function like here https://alwinesch.github.io/group__pytho...30225e8669

But when I tried "import xbmc" in my script I get the error ModuleNotFoundError.

There must be something trivial I'm missing here.

Thanks
Reply
#2
When I type pip install xbmc, I get No matching distribution found.

I might need to understand some basics, but I don't find where they are.
Reply
#3
(2022-11-21, 15:46)julienrobert Wrote: When I type pip install xbmc, I get No matching distribution found.

That's probably because as per 2014, the XMBC name was changed into Kodi.
However, in the source code, some direct xbmc references still exist.

Also, when installing Kodi onto RaspberryPi OS, you'll need sudo apt install kodi if you want to install the full application.
I assume you are using RPiOS, I didn't see anything else mentioned in your posts.
Reply
#4
Modules like "xbmc" are only available in the Python environment of Kodi. You have to run the script in Kodi.

Alternatively, you could use the JSON interface to control Kodi from the outside, with a language of your choice.
Reply
#5
This is how I would do it, assuming this is dedicated to the Video playback.

Install - Raspberry Pi OS Lite

Install Kodi and make it auto start
 
Code:
sudo apt update
sudo apt upgrade -y
sudo apt install -y kodi
# add user to group input
sudo usermod -a -G input $USER

#prepare kodi startup in user session
mkdir -p ~/.config/systemd/user/

#create Kodi startup script
echo -e '[Unit]\n Description=kodi startup service\n\n[Service]\n ExecStart=/usr/lib/arm-linux-gnueabihf/kodi/kodi.bin\n TimeoutSec=0\n StandardOutput=journal\n StandardError=journal\n Restart = on-abort\n RemainAfterExit=yes\n\n[Install]\n WantedBy=default.target\n' > ~/.config/systemd/user/kodi.service

#enable kodi startup
systemctl --user daemon-reload
systemctl --user enable kodi.service

loginctl enable-linger $USER

sudo reboot

Kodi should automatically come up, now.

Next, enable http:// remote control interface in kodi
 
Code:
Settings/Services/Control
Allow remote control via http

Now create the python script "start_movie.py", make sure you set the correct passwd, and path_to_movie.py
 
Code:
#!/usr/bin/env python3
import requests
import sys
from requests.auth import HTTPBasicAuth

auth= HTTPBasicAuth('kodi', 'passwd')

filename = "path_to_movie.mp4"

resutl = requests.post(\
    "http://127.0.0.1:8080/jsonrpc",\
     data=\
     '{"jsonrpc": "2.0", "id": 1,\
     "method": "Player.Open",\
     "params": {"item":{"file":"%s"}}}'% filename,\
     auth = auth)

print(resutl)
print(resutl.text)

change rights and execute it.
Code:
chmod 754 start_movie.py
./start_movie.py
Reply
#6
The built-in commands PlayerControl and PlayMedia in connection with kodi-send.py seem much easier to me.

Code:
kodi-send.py --action="Playmedia($FILE1,,,,resume)"
kodi-send.py --action="PlayerControl(repeat,9999)"
Kodi 18.6 @ openSUSE 13.1 x86_64 - Asus E35M1-I DELUXE | 8GB Ram | 240G 2.5" SSD
Kodi 20.2 on 1st Raspberry Pi B @ XBian | Kodi 20.2 on Raspberry Pi 3B+ @ XBian | Kodi 21a2 on Raspberry Pi4B @ XBian | Kodi 19.0 on SolidRun i.MX6 @ XBian
VDR 2.4.5 & Tvheadend4.3-1917 (for recording) on Cubieboard2 @ Debian Buster
Reply

Logout Mark Read Team Forum Stats Members Help
Resources needed for simple python code0