Cinemavision - Random Movie launcher - Powershell
#1
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. 

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

Kodi ver.19.1  Aeon MQ 8 Matrix Mod Windows 10 
Reply
#2
Hi and thank you @Shredder_guitar !

I'm new to Kodi and have installed it on my Amazon FireStick just because of the Plugin "CinemaVision". Since then, I'm searching an integration into my Home Assistant.
Having a little bit of automation for my Home Cinema as music while pausing or an intro would be so cool... :-)

And here I find a first step into this jungle... I'm so happy!!

Since I'm a total beginner in Kodi and rather just only a user of Home Assistant (some automations and skripts I have and understand slowly their workings...) - I'm a little bit confused by using your script:
Please, could you give me a small hint where I use this script in? (In Kodi?? Where? In Home Assistant? The "language" seems just a bit different from the normal scripts, I'm using...)

I don't want you to explain the whole story, but it would be so nice to give just a little help how to use the script - thank you so much!

Greetings from Bavaria
Robert

Using:
Home Assistant with Kodi integration on my Synology NAS as a Virtual Machine
Kodi 17.6 with CinemaVision on Amazon FireStick
Home Cinema with Denon AVR, Optoma Beamer, Panasonic Blu-Ray Player
Reply

Logout Mark Read Team Forum Stats Members Help
Cinemavision - Random Movie launcher - Powershell0