TV Series Episode Listings

I was working on putting together a video library for my vault, and I had the thought that it would be nice to list the episodes for the various series. I was aware of a website where one could get this information: epguides.com. With a little Google research, I discovered an API exists for it as described here. Using this I wrote a Templater template to show the episodes of every season of a given TV series. Hopefully this can be of use to folks, even if it’s just a starting point for your own ideas.

One big caveat. I used curl to pull down the information from the website. This tool is only natively available on Macintosh and Linux systems. On Windows systems it should be possible to use PowerShell’s Invoke-WebRequest commandlet to achieve the same end. I’m not sure what, if anything, is available on mobile platforms to do the equivalent.

Here’s the template:

<%*
   let series = await tp.system.prompt('TV Series','');
   let show = series.toLowerCase();
   show = show.replace(/^the /,'');            //remove leading The
   show = show.replace(/^a /,'');              //remove leading A
   show = show.replace(/^an /,'');             //remove leading An
   show = show.replace(/\s+/g,'');             //remove spaces
   show = show.replace(/[^\p{L}\p{N}]/gu, ''); //remove punctuation

   tR = `# ${series}\n\n`;

   const apiRoot = 'https://epguides.frecar.no/show/';
   const cmd = `curl "${apiRoot}${show}/"`;
   const { promisify } = require('util');
   const exec = promisify(require('child_process').exec);
   const result = await exec(cmd);
   const json = result.stdout.trim();

   if ((json.length < 10) || json.startsWith('{"error":'))
   {
      tR += 'Failed to find the episode list\n';
      tR += '```\n' + cmd + '\n```\n';
   }
   else
   {
      let eps = JSON.parse(json);
      let seasons = Object.keys(eps);
      for (let i = 0; i < seasons.length; i++)
      {
         let season = seasons[i];
         tR += `## Season ${season}\n`;

         let j = 0;
         let widthNum = 1;
         let widthTitle = 5;
         for (j = 0; j < eps[season].length; j++)
         {
            let num = `${eps[season][j].number}`;
            if (num.length > widthNum) { widthNum = num.length; }
            if (eps[season][j].title.length > widthTitle) { widthTitle = eps[season][j].title.length; }
         }

         tR += `| ${'#'.padStart(widthNum,' ')} | ${"Title".padEnd(widthTitle,' ')} | ${' Released '} |\n`;
         tR += `|-${'-'.padStart(widthNum,'-')}:|-${'-'.padEnd(widthTitle,'-')}-|------------|\n`;

         for (let j = 0; j < eps[season].length; j++)
         {
            let num = `${eps[season][j].number}`;
            tR += `| ${num.padStart(widthNum,' ')} | ${eps[season][j].title.padEnd(widthTitle,' ')} | ${eps[season][j].release_date} |\n`;
         }
         tR += '\n';
      }
   }
-%>

For example, here’s the partial output for entering Chuck:

# Chuck

## Season 1
|  # | Title                                 |  Released  |
|---:|---------------------------------------|------------|
|  1 | Chuck Versus the Intersect            | 2007-09-24 |
|  2 | Chuck Versus the Helicopter           | 2007-10-01 |
|  3 | Chuck Versus the Tango                | 2007-10-08 |
|  4 | Chuck Versus the Wookiee              | 2007-10-15 |
|  5 | Chuck Versus the Sizzling Shrimp      | 2007-10-22 |
|  6 | Chuck Versus the Sandworm             | 2007-10-29 |
|  7 | Chuck Versus the Alma Mater           | 2007-11-05 |
|  8 | Chuck Versus the Truth                | 2007-11-12 |
|  9 | Chuck Versus the Imported Hard Salami | 2007-11-19 |
| 10 | Chuck Versus the Nemesis              | 2007-11-26 |
| 11 | Chuck Versus the Crown Vic            | 2007-12-03 |
| 12 | Chuck Versus the Undercover Lover     | 2008-01-24 |
| 13 | Chuck Versus the Marlin               | 2008-01-24 |

## Season 2
|  # | Title                            |  Released  |
|---:|----------------------------------|------------|
|  1 | Chuck Versus the First Date      | 2008-09-29 |
|  2 | Chuck Versus the Seduction       | 2008-10-06 |
|  3 | Chuck Versus the Break-Up        | 2008-10-13 |
|  4 | Chuck Versus the Cougars         | 2008-10-20 |
2 Likes

For Windows users, apply the following modification to the template:

const cmd = `PowerShell -Command "(Invoke-WebRequest -Uri '${apiRoot}${show}/').Content"`;
2 Likes

You can get a curl on iOS/iPadOS via the app “a-Shell mini” (and possibly others), which can be controlled by Shortcut actions.