Webhook: Media.Scrobble Executes Minutes Before The Ending Credits In Movie

Why is it that when I watch the movie such as The Incredibles and I, Robot that the scrobble shows up in the Linux terminal about 5 minutes before the credits begin?

Here’s the JSON payload that I’m talking about:

Got webhook for media.scrobble
{
  event: 'media.scrobble',
  user: true,
  owner: true,
  Account: {
    // ...
    title: 'GraysonPeddie'
  },
  Server: {
    title: 'home-server',
    uuid: '[UUID REDACTED]'
  },
  Player: {
    local: false,
    publicAddress: '172.20.5.12',
    title: 'SHIELD Android TV',
    uuid: '[UUID REDACTED]'
  },
  Metadata: {
    librarySectionType: 'movie',
    ratingKey: '37',
    key: '/library/metadata/37',
    guid: 'com.plexapp.agents.imdb://tt0343818?lang=en',
    librarySectionTitle: 'Movies',
    librarySectionID: 1,
    librarySectionKey: '/library/sections/1',
    studio: '20th Century Fox',
    type: 'movie',
    title: 'I, Robot',
    contentRating: 'PG-13',
    summary: 'In 2035, where robots are common-place and abide by the three laws ' +
      'of robotics, a techno-phobic cop investigates an apparent suicide. ' +
      'Suspecting that a robot may be responsible for the death, his ' +
      'investigation leads him to believe that humanity may be in danger.',
    rating: 5.6,
    audienceRating: 7,
    viewCount: 5,
    lastViewedAt: 1559959681,
    year: 2004,
    tagline: 'Laws are made to be broken.',
    thumb: '/library/metadata/37/thumb/1557290785',
    art: '/library/metadata/37/art/1557290785',
    duration: 6900000,
    originallyAvailableAt: '2004-07-15',
    addedAt: 1429401104,
    updatedAt: 1557290785,
    audienceRatingImage: 'rottentomatoes://image.rating.upright',
    primaryExtraKey: '/library/metadata/142',
    ratingImage: 'rottentomatoes://image.rating.rotten',
    Genre: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
    Director: [ [Object] ],
    Writer: [ [Object], [Object] ],
    Producer: [ [Object], [Object], [Object], [Object], [Object] ],
    Country: [ [Object] ],
    Role: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object]
    ],
    Similar: [
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object],
      [Object], [Object]
    ]
  }
}

Here’s the code that controls my living room lights for Home Assistant:

var express = require('express')
  , request = require('request')
  , multer  = require('multer');

var app = express();
var upload = multer({ dest: '/tmp/' });
var hassURL = "https://homeassistant:8123/api/services"

app.post('/', upload.single('thumb'), function (req, res, next) {
  var payload = JSON.parse(req.body.payload);
  console.log('Got webhook for', payload.event);

  // Show the JSON payload in the log.
  console.log(payload);

  // Perform actions if a user is watching a movie in NVIDIA Shield Android TV.
  if (payload.Player.uuid == 'ee20b0d965dc8acb-com-plexapp-android' && payload.Metadata.type == 'movie') {
    var options = {
      method: 'POST',
      json: true,
      rejectUnauthorized: false,
      headers: {'Content-Type': 'application/json'}
    };

    if (payload.event == 'media.play' || payload.event == 'media.resume') {
      console.log('Plex client playing');
      options.body = { "entity_id": "light.lr_flamps" };
      request(hassURL + "/light/turn_off", options);
    } else if (payload.event == 'media.pause') {
      console.log('Plex client paused');
      options.body =
      {
          "entity_id": "light.lr_flamps",
          "brightness": "95"
      };
      //options.body = {'state':'Paused'};
      request(hassURL + "/light/turn_on", options);
    } else if (payload.event == 'media.stop'){
      console.log('Plex client stopped');
      options.body =
      {
          "entity_id": "light.lr_flamps",
          "brightness": "255"
      };
      //options.body = {'state':'Stopped'};
      request(hassURL + "/light/turn_on", options);
    } else if (payload.event == "media.scrobble"){
      console.log('Credits playing.');
      options.body =
      {
          "entity_id": "light.lr_flamps",
          "brightness": "191"
      };
      request(hassURL + "/light/turn_on", options);
    }
  }

  res.sendStatus(200);
});
// USER INPUT: Choose the port of your liking.
app.listen(24000);

Note: spoiler alert!

So within a 1 hour 43 minutes 18 to 20 seconds mark as Detective Spooner shook his hand with Sonny when the slow motion plays. As far as I know, the length of the ending movie credit is less than 10 minutes, so the credits began at 1:45:00 mark. If the scrobble executes at the point and I stop the movie a few minutes before a credit is shown, playing the movie starts from the beginning, so Plex does not ask me whether to resume the movie or not.

Here’s another example. Let’s say I’m watching The Incredibles (I don’t want anyone to assume II, so I’ll mention 1 from now on). So during the “Past versus Future” scene where Syndrome is at Mr. Incredible’s house and when Syndrome said “you took away my future,” just as Syndrome kidnapped Jack-Jack, my lights come on.

If I stop the movie (lights come on at full brightness) and play the movie, my lights turn off once the movie starts, so I didn’t get to see the rest of the movie before the credits start.

What about Tomorrowland, the movie that came out in 2015?

Casey Newton: First order of business?
Casey Newton: Get the door back open. (While the scene shows her dad just as the portal opens.)

Immediately before Casey said “Get the door back open,” my lights came on (media.scrobble webhook). The scrobble will also trigger even after Frank Walker said “so we’re making it work” and before “first order of business.” Once again, stopping the movie and playing the movie will start from the beginning instead of prompting me to whether to resume or start from beginning.

Note: Spoiler ended.

I can’t risk a copyright strike in YouTube and in the forums by showing a demonstration of what happened before the credits just to get my point across. I’m pretty sure Node-JS code is not the problem and so is Home Assistant as the REST APIs work fine, it only comes down to Plex.

Shouldn’t media.scrobble happen once the credits start? Surely, if the credits are playing, that means the movie is over, right? With that being said, is anyone in the same page as I am? Does anyone know what I’m talking about?

If my lights could come on just as the credits start, that would be so cool as I could replicate that commercial movie theater feel, just not in a commercial movie theater environment.

PS: Pardon my long post. I hope my thread is in the correct forum, because if it isn’t webhooks, I don’t know why Plex would think the movie is over even 3 to 5 minutes before the credits begin.

Well that makes sense. Is it possible if I could change the behavior so that when there’s 10 minutes left of the movie, that the movie can be marked as watched? Isn’t the length of credits about 10 minutes for most of the movies in average?

I do know that the classic Cinderella (pre-1966) only lasted for about few minutes. There are some movies out there that have very short credits at the end. (Hmm… What movies are they…?)

Are there any movies that have ending credits lasting for 15 minutes or more?

In my opinion, I do think that percentage is a poor metric for when the movie can be considered watched.

Thanks, I appreciate your help. I’ll just have to comment out the scrobble event, then.

I suppose I could have Home Assistant monitor the playback for when the credit starts, but if I do, I would have to assume the ending credits will show 10 minutes before the movie ends at 100%.

Update: I found a thread for anyone who’s interested, but I wouldn’t hold my breath in adjusting the time to mark the movie as watched.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.