2023-01-15, 23:29
I've spent days/weeks/months/hours trying to achieve launching the cinemavision addon directly with a random movie, and i finally have. I'll share to spare anyone else the headache of having to go through this. My ultimate purpose for this is to integrate this in home assistant via script.
Script Outline: This script is designed to parse through ALL movies that have not been watched (playcount less than 1) , of the list of movies that have not been watched, a random movie is selected and the movie ID is stored into a variable to then pass to the cinemavision api call.
Assumptions: You will need to have mapped your sequences based on genre type so Kodi already knows which sequence to play when a movie ID is passed to it. If the script fails to play a movie, it means that no sequence (again, based on genre) has been mapped for that type of movie.
What you need to do: in the username password and host name variables, you will need to provide the sign on that you would typically use for logging on to the web interface for Kodi for each call, there are 2 calls.
Script Outline: This script is designed to parse through ALL movies that have not been watched (playcount less than 1) , of the list of movies that have not been watched, a random movie is selected and the movie ID is stored into a variable to then pass to the cinemavision api call.
Assumptions: You will need to have mapped your sequences based on genre type so Kodi already knows which sequence to play when a movie ID is passed to it. If the script fails to play a movie, it means that no sequence (again, based on genre) has been mapped for that type of movie.
What you need to do: in the username password and host name variables, you will need to provide the sign on that you would typically use for logging on to the web interface for Kodi for each call, there are 2 calls.
powershell:
#Returns a list movie and movie ID
#required param ID
$username ='username'
$pwd = 'password'
$hostname = 'ipaddress'
$port = '8080'
$secpwd = ConvertTo-SecureString $pwd -AsPlainText -Force
$data = @{
'jsonrpc' = '2.0'
'method' = 'VideoLibrary.GetMovies'
'id' = 1
params = @{
properties = @(
'genre',
'playcount',
'runtime'
)
filter = @{
field = 'playcount'
operator = 'lessthan'
value = '1'
}
}
}
$json = $data | ConvertTo-Json -Depth 100
$url = 'http://'+$hostname+':'+$port+'/jsonrpc'
$mycreds = New-Object System.Management.Automation.PSCredential ($username, $secpwd)
$webreq = Invoke-WebRequest -Uri $url -Credential $mycreds -Body $json -ContentType application/json -Method POST -AllowUnencryptedAuthentication
$webreq
$unwatchedfulllist = ($webreq.content|convertfrom-json).result.movies|get-random
$pickedmovie = $unwatchedfulllist.movieid
#Starts cinemavision sequence
#required param ID
$username ='username'
$pwd = 'password'
$hostname = 'ipaddress'
$port = '8080'
$secpwd = ConvertTo-SecureString $pwd -AsPlainText -Force
$data = @{
'jsonrpc' = '2.0'
'method' = 'Addons.ExecuteAddon'
'id' = 1
params = @{
addonid = 'script.cinemavision'
params = @{movieid = "$pickedmovie"}
}
}
$json = $data | ConvertTo-Json -Depth 100
$url = 'http://'+$hostname+':'+$port+'/jsonrpc'
$mycreds = New-Object System.Management.Automation.PSCredential ($username, $secpwd)
Invoke-WebRequest -Uri $url -Credential $mycreds -Body $json -ContentType application/json -Method POST -AllowUnencryptedAuthentication