Issue with IMDB example script

I’m getting the following error when I run the add to watch list script:

2018-10-27 14:23:25: Error: TypeError: null is not an object (evaluating ‘matches.length’)

I’m going to the IMDB app and I find the movie then I click on the share button. Then I chose share then run script. I chose Add to watch list and it brought me to the editor with the above error at the bottom. Any idea what I’m doing wrong?

I’m going to guess that the issue’s in this particular function

// Extracts movie information from an IMDb description.
function extractMovieInfo(text) {
  let regex = /^(.*) \(([0-9]{4})\)/
  let matches = regex.exec(text)
  if (matches.length >= 3) {
    return {
      "name": matches[1],
      "year": matches[2]
  } else {
    return null

It the data is shared from IMDB, and the regex doesn’t match a name an year format, it will be null which isn’t an object of length and would cause the issue.

If I share something like Incredibles 2, I get a match as it has a bracketed date.

Incredibles 2 (2018)
Bob Parr (Mr. Incredible) is left to care for the kids while Helen (Elastigirl) is out saving the world.

If however I grab something that is a series rather than a movie, there is no date. For example, this behind the scenes interview for an upcoming film. Hence the match fails, returns a null and would error out.

IMDb on the Scene - Interviews: Ralph Breaks the Internet (S1.E17)
IMDb talks to the creators and stars of Disney Animation's sequel that welcomes back video-game bad guy Ralph and sidekick Vanellope von Schweetz for an adventure in the uncharted world of the internet.

It would be good to know what you’re passing into the script exactly.

It also looks like a good exercise to tweak the function to get it to look for any identifier in brackets at the end, rather than 4 numeric digits for a year. :wink:


I’ll take a look at that function for fun. Here’s the url to the series I was adding to the list