Use existing tag data in script

Hey all, I was looking for some advice on how to do a thing.

I was trying to build a script for TMDB.org that would pull TV episode info and ran into a snag since all the info is down behind season and episode subdirectories. I know there should be a way to have the script grab the season and episode numbers from the existing tag, but I can't seem to find it in the documentation.

f someone could direct me to the right part of the documentation or has some advice that would be great.

OK I was trying to figure this out, why is this not working?

  json_select "id"
 SayRest
 Say "/season/"
 $num(%tvseason%,)
 SayRest
 Say "/episode/"
 $num(%tvepisode%,)
 SayRest
 Say "?api_key=XXXXXXXXXXXX&language=English" # USE SAME API KEY AND LANGUAGE AS MENTIONED ABOVE
 Say "|"

Yes, it is not possible to access the tag data from the script. Also, scripting functions like $num() are not available there.

You can use the input from the search parameters to compose the target URL, or let the user enter the direct URL and append the API key in the script.

Please also see this topic for an existing Tag Source for TMDB:

Would it be possible to get more detail on how to use the input from the search parameters to compose a target URL?

Like Morningstar, I also got stuck trying to build a script for TMDB.org that would pull TV episode info.

Ideally, an example that, given input search parameters series_id, season_number and episode_number, could get details constructing a URL like this:

https://api.themoviedb.org/3/tv/{series_id}/season/{season_number}/episode/{episode_number}?api_key=XXXXXXXXXXXX&language=en-GB

As per TMDB API reference page for TV episode details: Details

Ah-ha! I got tag sources to work at TV episode level.

At first, I was trying to modify the logic in Sweder's excellent TheMovieDB script.

That approach for movies can be made to work well in searching for TV series by name and year.
I use Mp3tag's album field for series name (suffixed with season number in the format - S99), so my SearchBy and IndexUrl for series level tagging are set up as follows:

[SearchBy]=Series||$regexp(%album%,'(.*)( - S\d\d)',$1)||&query=%s||Year||%year%||&year=%s
[IndexUrl]=https://api.themoviedb.org/3/search/tv?query=%s&api_key=XXXXXXXXXXXX&language=en-GB

However, once series level tags are populated this way, in particular, ensuring that TMDB tag is populated...

OutputTo "TMDB"
json_select "id"
SayRest

... then, assuming you already have (or can input) season number and episode number, you can call a second tag source script to get TV episode level information (for example, episode name).

The trick with the episode level script is to leave out IndexUrl, and have an empty ParserScriptIndex section, as you don't need to search and select from query results when you have unique identifiers.

Instead (as I figured out after looking at Cover Art#Discogs Release ID.src), you can just use SearchBy criteria to construct AlbumUrl directly.

Bearing in mind that I use %discnumber% rather than %tvepisiode% (as Mp3tag's TVEPISIODE field isn't mapped properly for MKV), SearchBy and AlbumUrl are thus set in my TV episode script as follows:

[SearchBy]=SeriesId||%tmdb%||%s||Season||%tvseason%||/season/%s||Episode||%discnumber%||/episode/%s 
[AlbumUrl]=https://api.themoviedb.org/3/tv/%s?append_to_response=credits,external_ids&api_key=XXXXXXXXXXXX&language=en-GB

A more detailed (and more up-to-date) response describing how to retrieve TV episode information from TMDB has been posted on the TheMovieDB web sources script topic.