Author Topic: Roles command kodi  (Read 2782 times)

0 Members and 1 Guest are viewing this topic.

MMatty1

  • Jr. Member
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
Roles command kodi
« on: December 20, 2016, 08:12:21 AM »
Hi James, i just found the roles command posted awhile back, and was wondering if i can still use it with another action to query database, cos i thought it was added but ive just looked in my tree and cant find it im on newest vox so im guessing you never added it, My wife would really love this command as she likes to know whos playing who in what??

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7715
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Roles command kodi
« Reply #1 on: December 20, 2016, 08:44:11 AM »
The default Kodi configuration contains a command "What movie is this" which lists the cast.

The cast is also announced when a new movie starts playing.

If that's not what you are talking about then please provide a link to the post you are referring to.
« Last Edit: December 20, 2016, 10:13:30 AM by jitterjames »

MMatty1

  • Jr. Member
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
Re: Roles command kodi
« Reply #2 on: December 22, 2016, 06:51:52 AM »
http://voxcommando.com/forum/index.php?topic=585.0 this one where you can ask who plays the character..

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Roles command kodi
« Reply #3 on: December 22, 2016, 12:14:28 PM »
You can adapt the command that James mentions above that is part of the standard config. ("What movie is this" or the event-triggered XBMC.Player.OnPlay.movie command, which is basically the same thing.)

If you run that command while a film is playing, and then check your VC log, you'll see that the xJson.Raw query is returning full cast info, which includes actor names and role names. So you can clone the existing command, or within the existing command change what you ask for, and change the regex used so that it captures both actor name and associated role. You'll probably need to use a Results.RegexSingle, instead of the current Results.Regex action, since actor "name" and the "role" are returned on separate lines of the json result.

The best option is probably to automatically look for actors and their roles when the movie starts and immediately generate a new payload XML file (this involves adding a few lines at the end of the current event-triggered command).

In the payload XML file, pass roles as the phrases, and actor names as the values. You can then create a separate command along the lines of "Who plays the character {1}". This command uses that payload XML file. It can be a very simple command, since all you should need is a TTS action and/or OSD that tells you what {1} is. ("The actor who plays {PF.1} is {1}.")
« Last Edit: December 23, 2016, 10:55:39 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

MMatty1

  • Jr. Member
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
Re: Roles command kodi
« Reply #4 on: December 28, 2016, 06:54:27 AM »
Hi Naomi, Thanks For the info, sorry late reply family issues, im trying my best to get this to work still but with no luck, have tried both regex and payload file comes out all wrong, i can get actor and roles names returned but cant create the payload file, any more help much appreciated from you  or from the James the creator of a great program.. ;)



Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.2.2-->
<command id="623" name="XBMC.Player.OnPlay.movie**Get Actor name and roles" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>XJson.Raw</cmdType>
    <params>
      <param>Player.GetItem</param>
      <param>"playerid":1,  "properties": ["title","cast"]</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>"name": (.*?),</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>Actornames</param>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>{#M}</cmdRepeat>
  </action>
  <action>
    <cmdType>XJson.Raw</cmdType>
    <params>
      <param>Player.GetItem</param>
      <param>"playerid":1,  "properties": ["title","cast"]</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>"role".*?"(.*)"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.SetVar</cmdType>
    <params>
      <param>Rolesnames</param>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>PayloadXML.AddPair</cmdType>
    <params>
      <param>E:\Vox\payloads\ActorandRoles</param>
      <param>{Var.Rolesnames}</param>
      <param>{Var.Actornames}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>XBMC.Player.OnPlay.movie</event>
</command>

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 2012
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Roles command kodi
« Reply #5 on: December 28, 2016, 10:59:40 AM »
Hi,

When you next have 15 minutes to spare, I do recommend watching James's tutorials on using regular expressions in VC because it will open up so many different possibilities with the program in the long run--not just with Kodi.

A key problem you're having above is that you're not actually accessing any regular expression matches in your command. Regular expression matches are not returned as {LastResult}.

As the Action Description says:

Quote
Performs regular expression matching against the {LastResult} from a previous action, and stores multiple matches in {Match.1} {Match.2} etc.

We perform regular expression matching on a result (hence the action names Results.Regex/Results.RegexSingle), but then each time the pattern is matched we access it as a {Match.#} – or {Match.#.1}, {Match.#.2} etc. if we want to capture more than one pattern in a single expression, as I suggested that you could do here.

No custom variables should need to be created if you capture both role and actor name in the same regex line.

Below was my suggested solution. There are 2 commands. The event-driven command can replace the default version that comes in your Kodi config.

OnPlay command, with a few lines added to generate the new payload xml
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.3.2-->
<command id="495" name="XBMC.Player.OnPlay.movie" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="For me, the Kodi &quot;cast&quot; json result returns name: ... then role: ... further down. This may not be true in your Kodi installation. If role is returned before name for you, change the Results.RegExSingle line accordingly.">
  <action>
    <cmdType>XJson.Raw</cmdType>
    <params>
      <param>Player.GetProperties</param>
      <param>"playerid":1, "properties": ["percentage"]</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>XJson.ParseTokens</cmdType>
    <params>
      <param>{percentage}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)&lt;(B)</ifType>
    <ifParams>{LastResult}&amp;&amp;0.1</ifParams>
    <then>
      <action>
        <cmdType>XJson.Raw</cmdType>
        <params>
          <param>Player.GetItem</param>
          <param>"playerid":1,  "properties": ["title","cast"]</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.RegEx</cmdType>
        <params>
          <param>"name".*?"(.*)"</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.MatchConcat</cmdType>
        <params>
          <param>, </param>
          <param>3</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>XJson.ParseTokens</cmdType>
        <params>
          <param>Now playing {item.title} starring {lastresult}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>XJson.SoftMute</cmdType>
        <params>
          <param>60</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.SpeakSync</cmdType>
        <params>
          <param>{LastResult}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>XJson.SoftUnMute</cmdType>
        <params />
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>VcAdvanced.Log</cmdType>
        <params>
          <param>Resuming movie - skip announcement.</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <action>
    <cmdType>PayloadXML.Clear</cmdType>
    <params>
      <param>XbmcPayloads\movie_roles.xml</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>XJson.Raw</cmdType>
    <params>
      <param>Player.GetItem</param>
      <param>"playerid":1,  "properties": ["cast"]</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExSingle</cmdType>
    <params>
      <param>"name":\s"(.*?)".*?"role":\s"(.*?)"</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.MatchToXML</cmdType>
    <params>
      <param>XbmcPayloads\movie_roles.xml</param>
      <param />
      <param>True</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <event>XBMC.Player.OnPlay.movie</event>
</command>

Command to ask who plays what:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.3.2-->
<command id="454" name="Who plays the character {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{1} plays the character {PF.1}.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Who plays the character</phrase>
  <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="False">XbmcPayloads\movie_roles.xml</payloadFromXML>
</command>



« Last Edit: December 28, 2016, 11:05:37 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

MMatty1

  • Jr. Member
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
Re: Roles command kodi
« Reply #6 on: December 29, 2016, 07:17:18 AM »
Awesome work Naomi Thanks   A lot, Ive watched all tutorials and have learned a lot, but of course always more learning to do, Ill watch again, and Thanks again from me and my wife... :) :)