v19 [SOLVED] How to "Typing" numbers during video to jump to the right time position?
#1
(Windows x64 matrix 19.1) 

Hi guys,
Sry for my english!

I was wondering if it would be possible to type numbers via Curl while playing video?
I was thinking about e.g.
02342,Return
this would jump to the 23:42 time position of the video

i'm still learning about this json-rpc so far i'm at the point where i can update the video library with this line in batch file Big Grin

.bat
@echo off
curl -i -X POST -d "{\"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.Scan\", \"id\": \"mybash\"}" -H "content-type:application/json" http://kodi:kodi@localhost:8080/jsonrpc
pause

output:
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Type: application/json
Content-Length: 45
Cache-Control: private, max-age=0, no-cache
Accept-Ranges: none
Date: Tue, 15 Jun 2021 18:12:30 GMT

{"id":"mybash","jsonrpc":"2.0","result":"OK"}


I found a very similar thread 
but no reply there
JSON command to seek at a specific time

if anyone has any advice or ideas, even if not with curl
but in some other way, I would be happy to hear them!
Reply
#2
I finally solved it but in a little different way


with this example I have saved the position of the video 27:45
change to 2745{enter}
save.bat
Code:
cd kodi
docker run -it screenbreak/singlefile-dockerized http://kodi:[email protected]:8080 > log.html
xidel -s log.html -e "<div class='playing-time-current'>{inner-html()}</div>" > time.txt
for /f "tokens=1,2,3 delims=:" %%G IN (time.txt) do (echo %%G%%H%%I{enter}) >load-pos.stro
del /f log.html
del /f time.txt
exit

with this save.bat I evaded the access denied error message
save-pos.bat
Code:
cd kodi
start /B "" "c:\kodi\save.bat"
exit

and this will type this 2745{enter}  directly into the screen of the kodi
load-pos.bat
Code:
@echo off
start /B "" "c:\kodi\WinSendKeys.exe" -f "c:\kodi\load-pos.stro" kodi
exit

then I added keyboard.xml to the two buttons of my remote control
Code:
<f1 mod="ctrl,alt">System.ExecWait(""c:\kodi\save-pos.bat"")</f1>
<f4 mod="ctrl,alt">System.ExecWait(""c:\kodi\load-pos.bat"")</f4>


requirements:
WinSendKeys.exe
xidel.exe
docker desktop
singlefile-dockerized
Reply
#3
With difficulty but I succeeded re-writing it in python and no more pop-up windowSmile

just copy the pynput folder from this file pynput-1.7.3.tar.gz (under lib directory) to where the .py files are
and you need to rewrite your ip,port,user and pass

after saving the position, these will appear in the save.txt file
example:

full path to the video file
003908
Mr. & Mrs. Smith

(the title of the video is just for information only, nothing to do with it)

because save.py also creates a bookmark with position it only works under Kodi

add to the buttons (keyboard.xml)

Code:
<keymap>
<global>
<keyboard>
<f1 mod="ctrl,alt">RunScript("c:\sleepy\save-pos.py")</f1>
<f4 mod="ctrl,alt">RunScript("c:\sleepy\load-pos.py")</f4>
<home>RunScript("c:\sleepy\save-pos.py")</home>
<end>RunScript("c:\sleepy\load-pos.py")</end>
</keyboard>
</global>
<keymap>

if your skin supports it, you can add this command and launch it from the main screen
RunScript("c:\sleepy\load-pos.py")

save-pos.py

Code:
import json
import base64
import requests
import xbmc

credentials = b'kodi:kodi'
encoded_credentials = base64.b64encode(credentials)
authorization = b'Basic ' + encoded_credentials
headers = { 'Content-Type': 'application/json', 'Authorization': authorization }
url = 'http://192.168.1.10:8080/jsonrpc?Base'
data = [
    {"jsonrpc":"2.0","method":"Player.GetProperties","params":[1,["time"]],"id":17},
    {"jsonrpc":"2.0","method":"Player.GetItem","params":[1,["file"]],"id":18}]
response = requests.post(url, headers=headers, data=json.dumps(data))
result = response.json()
h,m,s = map(int, [result[0]['result']['time'][val] for val in ['hours','minutes','seconds']])
time = f'{h:02}{m:02}{s:02}'
print(result[1]['result']['item']['file'],time,result[1]['result']['item']['label'], sep='\n', file=open("c:\\sleepy\\save.txt", "w"))
xbmc.executebuiltin('Action(CreateBookmark)')

load-pos.py

Code:
import requests
import time
import os
import webbrowser

file = open("c:\\sleepy\\save.txt")
lines2 = file.readlines()
url = lines2[0].split('\n')[0]

headers = {
    'Content-Type': 'application/json',
}

data = {"jsonrpc":"2.0","id":1,"method":"Player.Open","params":{"item":{"file":url}}}
requests.post('http://kodi:[email protected]:8080/jsonrpc?Base', headers = headers, json = data)

file = open("c:\\sleepy\\save.txt")
lines = file.readlines()
line = lines[1]

os.startfile("c:\\Program Files\\Kodi\\kodi.exe")
from pynput.keyboard import Key, Controller as K
time.sleep(3)
K().type(line+'  ')

for anyone who finds it easier I put it on MEGA
Reply

Logout Mark Read Team Forum Stats Members Help
[SOLVED] How to "Typing" numbers during video to jump to the right time position?0