Author Topic: Kodi - Play TV Episode by season number from Episode list  (Read 4144 times)

0 Members and 1 Guest are viewing this topic.

Mace

  • $upporter
  • Contributor
  • *****
  • Posts: 77
  • Karma: 1
    • View Profile
Kodi - Play TV Episode by season number from Episode list
« on: March 25, 2015, 04:59:24 AM »
Here's a few commands to play a TV Episode by episode number from the TV Show->Season->Episode  window

Note: For this to work on all TV Shows you will need to tun off "Flatten TV show seasons" in Kodi.
Settings -> Video -> Library, change 'Flatten TV show seasons' to 'Never'. This stops Kodi displaying TV shows that only have 1 season differently to other multi season shows. The way Kodi reads these windows is different and screws up the command.


Big thanks to James for the inspiration: http://voxcommando.com/forum/index.php?topic=2059.0

How does it all work?
Everything runs from one single command "Play Episode {1}"
The other two commands will run depending on the outcome of "Play Episode {1}" command.
For this to work you need to be either watching a TV episode or viewing the episode list from the TV Show->Season.

Why bother?
1. Cause it's fun to learn all the cool stuff VC can do
2. Help others learn about how awesome Regular Expression is.
3. Cause it's nice to look at the screen and say "Play Episode 6"
4. ok, so on some systems it might be a little CPU Hungry.


Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<commandGroup open="True" name="Kodi TV Show Episodes" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="751" name="Play Episode {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>XJson.Raw</cmdType>
      <params>
        <param>Player.GetActivePlayers</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>(A)Contains(B)</ifType>
      <ifParams>{LastResult}&amp;&amp;"type": "video"</ifParams>
      <then>
        <action>
          <cmdType>VC.TellVox</cmdType>
          <params>
            <param>Play While Another Episode Currently Playing {1}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>VC.TellVox</cmdType>
          <params>
            <param>Play from Episode List on Screen {1}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <phrase>Play Episode</phrase>
    <payloadRange>1,30</payloadRange>
  </command>
  <command id="1509" name="Play from Epsode List on Screen" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>XJson.Raw</cmdType>
      <params>
        <param>XBMC.GetInfoLabels</param>
        <param>"labels" : ["Container.FolderPath"]</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegExSingle</cmdType>
      <params>
        <param>"Container.FolderPath": \s"videodb://tvshows/titles/*(\d.*?)/(\d.*?).*?"</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <if ifBlockDisabled="False" ifNot="True">
      <ifType>(A)&lt;(B)</ifType>
      <ifParams>0&amp;&amp;{Match. 1.1}</ifParams>
      <then>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>Please Select TV show and Season</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>XJson.ExecBuiltin</cmdType>
          <params>
            <param>Notification(Error:, Please Select Tv Show and Season First)</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>VC.StopMacro</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <action>
      <cmdType>XJson.Raw</cmdType>
      <params>
        <param>VideoLibrary.GetEpisodes</param>
        <param>"tvshowid":{Match.1.1}, "season":{Match.1.2}, "properties":["episode","season","tvshowid","title","showtitle"]</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegExSingle</cmdType>
      <params>
        <param>"episode":\s{1},.*?"episodeid":\s*(\d*?),.*?"label":\s"(.*?)",.*?"season":\s(\d.*?),.*?"showtitle":\s"(.*?)",.*?"title":\s"(.*?)",.*?"tvshowid":\s(\d*).*?</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <if ifBlockDisabled="False" ifNot="True">
      <ifType>LastActionSuccess</ifType>
      <ifParams>&amp;&amp;</ifParams>
      <then>
        <action>
          <cmdType>Results.RegExSingle</cmdType>
          <params>
            <param>"season":\s*(\d*?),.*?"showtitle":\s"(.*?)",.*?"tvshowid":\s(\d*).*?</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>Sorry, I found Season {Match.1.1} but not episode {1} - of {Match.1.2}</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>XJson.ExecBuiltin</cmdType>
          <params>
            <param>Notification(Not Found: No Episode {1} Found</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>XJson.Raw</cmdType>
          <params>
            <param>Gui.ActivateWindow</param>
            <param>"window":"video","parameters":["videodb://2/2/{Match.1.3}/{Match. 1.1}/"]</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>VC.StopMacro</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <action>
      <cmdType>XJson.Raw</cmdType>
      <params>
        <param>Player.Open</param>
        <param>"item":{"episodeid":{match.1.1}}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Episode {1} - {Match. 1.5}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Now playing : {Match.1.4} - {Match. 1.2}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>XJson.ExecBuiltin</cmdType>
      <params>
        <param>Notification(Now Playing:,{Match. 1.4}: {match. 1.2},5000)</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase optional="true">Do not Need to use this phase - Use 'Play Episode {1}' Command</phrase>
    <phrase>Play from Episode list on Screen</phrase>
    <payloadRange>1,50</payloadRange>
  </command>
  <command id="931" name="Play While Another Episode Currently Playing" 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", "season", "episode", "showtitle","tvshowid" ]</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegExSingle</cmdType>
      <params>
        <param>"episode":\s*(\d.*?),.*?"season":\s*(\d.*?),.*?"tvshowid":\s*(\d*?),.*?</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>XJson.Raw</cmdType>
      <params>
        <param>VideoLibrary.GetEpisodes</param>
        <param>"tvshowid":{Match.1.3}, "season":{Match.1.2}, "properties":["episode","season","tvshowid","title","showtitle"]</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegExSingle</cmdType>
      <params>
        <param>"episode":\s{1},.*?"episodeid":\s*(\d*?),.*?"label":\s"(.*?)",.*?"season":\s(\d.*?),.*?"showtitle":\s"(.*?)",.*?"title":\s"(.*?)",.*?"tvshowid":\s(.\d.*?)}.*?</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <if ifBlockDisabled="False" ifNot="True">
      <ifType>LastActionSuccess</ifType>
      <ifParams>&amp;&amp;</ifParams>
      <then>
        <action>
          <cmdType>OSD.ShowText</cmdType>
          <params>
            <param>Episode {1} not Found</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>Episode {1} not Found</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>XJson.ExecBuiltin</cmdType>
          <params>
            <param>Notification(Error:, No Episode {1} Found)</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>VC.StopMacro</cmdType>
          <params />
          <cmdRepeat>1</cmdRepeat>
        </action>
      </then>
      <else />
    </if>
    <action>
      <cmdType>XJson.Raw</cmdType>
      <params>
        <param>Player.Open</param>
        <param>"item":{"episodeid":{match.1.1}}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>Now Playing: {Match.1.4} - {Match. 1.2}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>Episode {1} - {Match.1.5}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>XJson.ExecBuiltin</cmdType>
      <params>
        <param>Notification(Now Playing:,{Match. 1.4}: {match. 1.2},5000)</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase optional="true">Do not Need to use this phase - Use 'Play Episode {1}' Command</phrase>
    <phrase>Play While Another Episode Currently Playing</phrase>
    <payloadRange>1,50</payloadRange>
  </command>
</commandGroup>

I'd like to put them all in one command but it will be rather large and there's not quite the logic i need to use the error support.

If you see any improvements feel free to comment.

vulcanjedi

  • $upporter
  • Sr. Member
  • *****
  • Posts: 213
  • Karma: 8
    • View Profile
Re: Kodi - Play TV Episode by season number from Episode list
« Reply #1 on: May 14, 2015, 12:18:00 PM »
Thanks Mace (and James)
I've actually wanted something like this a while. Played with one very briefly last night and seemed to do the trick.