Author Topic: Find song info for TV shows  (Read 6048 times)

0 Members and 1 Guest are viewing this topic.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Find song info for TV shows
« on: November 04, 2016, 12:19:51 PM »
TUNEFIND NO LONGER OFFERS A FREE API.
The minimum plan starts at $25/month.

Now that TV shows are often creative with their soundtracks, we keep wondering what songs (or artists) are playing while watching TV.

I just discovered TuneFind, which has an API we can use in VC. The standard API is free, though it seems to have a few limitations.

I've been testing it out by grabbing show info from Kodi when an episode is playing, and then passing it to Tunefind to get episode soundtrack data (using our trusty Scrape and Regex actions).

The data is crowd-sourced. The site seems quite good for U.S. shows and possibly UK TV, but my test of our non-English-language TV shows suggests it's probably not great for global content.

If anyone is interested, let me know and I'll post some details about how I've implemented it. As always, there are different ways one could approach it.

There are a number of steps, so I don't want to spend half an hour posting an explanation unless it's wortwhile to others. :biglaugh (I live and learn!)

cheers.

« Last Edit: August 14, 2017, 09:27:45 AM by jitterjames »
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)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Find song info for TV shows
« Reply #1 on: November 08, 2016, 09:59:49 AM »
Kodi-specific implementation:

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.3.0-->
<commandGroup open="True" name="TuneFind API commands for Kodi" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="111" name="Tell me about the soundtrack" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Song data is used under license from TuneFind LLC. Here I use XJson.ParseTokens to parse json data from TuneFind.">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>result = {var.episode}-1</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>ep_array</param>
        <param>{LastResult}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Scrape</cmdType>
      <params>
        <param>https://www.tunefind.com/api/v1/show/{var.show}/season-{var.season}</param>
        <param>YOUR TUNEFIND API USERNAME</param>
        <param>YOUR TUNEFIND API PASSWORD</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>XJson.ParseTokens</cmdType>
      <params>
        <param>{episodes[{var.ep_array}].tunefind_api_url}</param>
        <param>{LastResult}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Scrape</cmdType>
      <params>
        <param>{LastResult}</param>
        <param>YOUR TUNEFIND API USERNAME</param>
        <param>YOUR TUNEFIND API PASSWORD</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <params>
        <param>","name":"(.*?)",.*?"artist.*?"name":"(.*?)"</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <if ifBlockDisabled="False" ifNot="False">
      <ifType>LastActionSuccess</ifType>
      <ifParams>&amp;&amp;</ifParams>
      <then>
        <action>
          <cmdType>OSD.ShowText</cmdType>
          <params>
            <param>Songs in the episode "{var.ep_title}", season {var.season} of {var.show_title}:</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>OSD.AddText</cmdType>
          <params>
            <param>"{Match.{i}.1}", by {Match.{i}.2}</param>
          </params>
          <cmdRepeat>{#M}</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.SpeakSync</cmdType>
          <params>
            <param>Songs in this episode of {var.show_title} are:</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>{i}. {Match.{i}.1}, by {Match.{i}.2}</param>
          </params>
          <cmdRepeat>{#M}</cmdRepeat>
        </action>
      </then>
      <else>
        <action>
          <cmdType>OSD.ShowText</cmdType>
          <params>
            <param>Sorry. I couldn't find soundtrack information for that episode.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
        <action>
          <cmdType>TTS.Speak</cmdType>
          <params>
            <param>Sorry. I couldn't find soundtrack information for that episode.</param>
          </params>
          <cmdRepeat>1</cmdRepeat>
        </action>
      </else>
    </if>
    <phrase>tell me about the soundtrack</phrase>
  </command>
  <command id="127" name="show me the soundtrack (in Tunefind)" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description=" ">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>result = {var.episode}-1</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>ep_array</param>
        <param>{LastResult}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Scrape</cmdType>
      <params>
        <param>https://www.tunefind.com/api/v1/show/{var.show}/season-{var.season}</param>
        <param>YOUR TUNEFIND API USERNAME</param>
        <param>YOUR TUNEFIND API PASSWORD</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>XJson.ParseTokens</cmdType>
      <params>
        <param>{episodes[{var.ep_array}].tunefind_url}</param>
        <param>{LastResult}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Launch.OpenURL</cmdType>
      <params>
        <param>{LastResult}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>show me the soundtrack</phrase>
  </command>
  <command id="117" name="save now playing episode info" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="var.show_title stores friendly show name. var.show will store the show name in format needed by TuneFind.">
    <action>
      <cmdType>XJson.Raw</cmdType>
      <params>
        <param>Player.GetItem</param>
        <param>"playerid":1,  "properties": ["showtitle","season","episode","title"]</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>XJson.ParseTokens</cmdType>
      <params>
        <param>show:"{item.showtitle}" season:"{item.season}" episode:"{item.episode}" ep_title:"{item.title}"</param>
        <param>{LastResult}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <params>
        <param>"(.*?)"</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>season</param>
        <param>{Match.2}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>episode</param>
        <param>{Match.3}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>show_title</param>
        <param>{Match.1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>ep_title</param>
        <param>{Match.4}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>result = "{Match.1}".replace(" ","-").lower()</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.SetVar</cmdType>
      <params>
        <param>show</param>
        <param>{LastResult}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>Kodi.Player.OnPlay.episode</event>
    <event>XBMC.Player.OnPlay.episode</event>
  </command>
</commandGroup>

To sign up for your own api username and password: http://www.tunefind.com/api

The trial license has a limit that prevents us from accessing song data from shows aired in the last year. Technically, I think we meet their terms of use and should have access to the full data, but I haven't followed up with them.
« Last Edit: December 11, 2016, 11:06:33 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)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Find song info for TV shows
« Reply #2 on: November 08, 2016, 01:56:59 PM »

There are a number of steps, so I don't want to spend half an hour posting an explanation unless it's wortwhile to others. :biglaugh (I live and learn!)

cheers.

Do you though?  ::dis

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Find song info for TV shows
« Reply #3 on: November 08, 2016, 02:15:47 PM »
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: Find song info for TV shows
« Reply #4 on: December 11, 2016, 05:21:53 AM »
Hey Nimster do you think this could be adapted for movies easy??

MMatty1

  • Jr. Member
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
Re: Find song info for TV shows
« Reply #5 on: December 11, 2016, 05:24:09 AM »
Lol Nime5ster

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Find song info for TV shows
« Reply #6 on: December 11, 2016, 09:03:25 AM »
I guess that depends on what "easy" means to you. :)

It would be easier to do than the TV episodes, because for movies you can go directly to the correct URL on TuneFind to scrape songs for that movie, whereas I had to jump through several hoops to get to specific episode info.

For example, to get song info from The School of Rock (2003) you'd just scrape the URL:
Code: [Select]
https://www.tunefind.com/api/v1/movie/school-of-rock-2003
You would need to get the movie title and year of the movie from Kodi (or whatever media player you use). Since Kodi will not put dashes between the words -- and TuneFind also requires all lowercase characters -- you'll have to customize the Kodi data in VC to create a string in the required format (which I had to do for the TV episode data as well).

The regex required to get the song info from the TuneFind site looks the same as the regular expression that I used in the example above.
« Last Edit: December 11, 2016, 01:47:06 PM 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)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Find song info for TV shows
« Reply #7 on: December 11, 2016, 11:08:23 AM »
If it's easier, feel free to use my real name -- Naomi

In my experience people struggle to spell that correctly even more often.  :bonk
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)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Find song info for TV shows
« Reply #8 on: December 11, 2016, 02:48:12 PM »
Hey Nimster do you think this could be adapted for movies easy??

Here's a movie soundtrack solution for Kodi that does not require an API key.

http://voxcommando.com/forum/index.php?topic=2675.0
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: Find song info for TV shows
« Reply #9 on: December 12, 2016, 05:21:19 AM »
Thnxxx Naomi.. :) :)

MMatty1

  • Jr. Member
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
Re: Find song info for TV shows
« Reply #10 on: December 12, 2016, 08:25:30 AM »
Hi Naomi im getting a 401 error when i use command for soundtrack eps, any clues you think. Why,  can post my group with username and password if you need I'm just at a lost any help appreciated

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Find song info for TV shows
« Reply #11 on: December 12, 2016, 08:35:33 AM »
Hi MMatty1,

Before posting your command group etc., are you sure you're using an API key and password?  This is distinct from the username and password that you use when signing up to Tunefind. You have to actually apply for the key by filling out a special form:

http://www.tunefind.com/api

If I remember correctly, the key and pw are then issued automatically, but with the limit that you can't run queries on episodes released in the past year.
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: Find song info for TV shows
« Reply #12 on: December 13, 2016, 12:43:10 AM »
 :bonk :bonk :bonk :bonk Thnx just created it and working great for tvshows and movies command works great Thnxxx so much... :-*

MMatty1

  • Jr. Member
  • **
  • Posts: 40
  • Karma: 4
    • View Profile
Re: Find song info for TV shows
« Reply #13 on: August 14, 2017, 05:09:34 AM »
Hi I haven't used this command for awhile due to upgrading pc, it seems it won't work anymore they deactivated my account and tunefind now want 25 a month to request data just thought I'd post let you know