2015-08-18, 17:30
Currently I'm working on my own implementation of a torrent-streaming plugin. Basically, its an analog of Pulsar but written in pure Python (except for python-libtorrent module, which is binary) and with some additional features, like seeding after playback and a web-UI for managing torrents.
Architecture-wise the plugin consists of a server and a client parts. The client is responsible for passing .torrent files and magnet links to the server and starting playback (via setResolvedUrl) once a video file is buffered enough for continuous playback. The server part is a simple torrent-client (based on libtorrent) and a web-server for serving media-files to Kodi.
One thing I'm struggling with is playback seek/jump support. The idea is that when a user wants to seek a video, the server receives an appropriate 'Content-Range' header from Kodi and prioritizes download of the parts that has been requested for playback. But it's not that simple because Kodi does not always issue a http request when a user performs a seek (especially for mkv files).
Basically, what I need to know is how to correctly serve a video file to Kodi via http protocol: what requests it normally issues and what replies it expects. And how to make it always issue a 'Content-Range' range request when a user wants to jump/skip a part of the video being played.
What I found out experimentally that starting a playback a remote file via http Kodi issues 3 requests: HEAD, GET from start ('Content-Range': '0-') and GET near the end of the file. And the piece requested at the end of a video file differs depending on the type of a video file. For mp4 and mkv Kodi requests the last 64KB and the last ~200KB for avi. I tried to provide the necessary http headers but obviously I'm missing something because, as I said, a http request with a 'Content-Range' header is not always issued after a video seek command - Kodi simply tries to grab the necessary pieces from the server without any http requests.
Just to be clear: the server part is based on Bottle web-framework and WSGIref server from Python standard library.
Architecture-wise the plugin consists of a server and a client parts. The client is responsible for passing .torrent files and magnet links to the server and starting playback (via setResolvedUrl) once a video file is buffered enough for continuous playback. The server part is a simple torrent-client (based on libtorrent) and a web-server for serving media-files to Kodi.
One thing I'm struggling with is playback seek/jump support. The idea is that when a user wants to seek a video, the server receives an appropriate 'Content-Range' header from Kodi and prioritizes download of the parts that has been requested for playback. But it's not that simple because Kodi does not always issue a http request when a user performs a seek (especially for mkv files).
Basically, what I need to know is how to correctly serve a video file to Kodi via http protocol: what requests it normally issues and what replies it expects. And how to make it always issue a 'Content-Range' range request when a user wants to jump/skip a part of the video being played.
What I found out experimentally that starting a playback a remote file via http Kodi issues 3 requests: HEAD, GET from start ('Content-Range': '0-') and GET near the end of the file. And the piece requested at the end of a video file differs depending on the type of a video file. For mp4 and mkv Kodi requests the last 64KB and the last ~200KB for avi. I tried to provide the necessary http headers but obviously I'm missing something because, as I said, a http request with a 'Content-Range' header is not always issued after a video seek command - Kodi simply tries to grab the necessary pieces from the server without any http requests.
Just to be clear: the server part is based on Bottle web-framework and WSGIref server from Python standard library.