Tdarr icon indicating copy to clipboard operation
Tdarr copied to clipboard

Movie / episode length checker

Open Jacob-Lasky opened this issue 3 years ago • 4 comments

Is your feature request related to a problem? Please describe. Every once in a while I find that a video file (usually a movie) is the wrong length, as in it is a sample or just a few minutes.

Describe the solution you'd like I would like a way to flag movies (and less importantly TV) that are outside of some threshold of the true video length. This would use OMDB/TVDB databases to confirm the video length. The threshold of some percent of what the true length (5% or something, perhaps set by the user) should be could be allow for different cuts, extended additions, etc.

Describe alternatives you've considered Alternatively, it could just flag videos that are below or above a certain length of time (less than 5 minutes, more than 400 minutes, etc). Perhaps set by the user.

Additional context I'm not sure if this is out of the context of what Tdarr wants to accomplish, but I do think that this could fit nicely in a holistic video library health checker.

Jacob-Lasky avatar Aug 18 '20 02:08 Jacob-Lasky

I second this as a great feature to implement. I am continuously finding items that were transcoded that, while tdarr reports them as complete and healthy, are only a fraction of what they should be, (e.g. a 90 minute film is transcoded to 4 minutes).

While this is more annoying than a deal breaker, I am concerned of files that are impacted and I have no easy way to find these other than browsing through my library and comparing duration to themoviedb. This forces me to reacquire these, which may be problematic for some of the harder-to-find media.

regorian avatar Apr 30 '21 18:04 regorian

This would be a great feature, although I think this is something that maybe sonarr and radarr should be handling.

ajw107 avatar May 15 '21 14:05 ajw107

I would agree, except that I believe that the health-checks actually could handle this really well.

I just went through 400 failed checks and 350 of them had errors on the last frame. It could be nice if Tdarr would flag bad meida lengths in that same health check, and perhaps even ignore health errors if they occur after 99% of the movie / tv show is complete, based on some sort of IMDB length check (or whatever percent)

Jacob-Lasky avatar May 16 '21 21:05 Jacob-Lasky

You can use this plugin to help prevent file duration errors when FFmpeg doesn't give an error during transcoding:

https://github.com/HaveAGitGat/Tdarr_Plugins/blob/master/Community/Tdarr_Plugin_a9hf_New_file_duration_check.js

Using IMDB/OMDB/TVDB could be possible but depends on the costs limits.

Also, people may or may not have all sorts of junk in their filenames so that would need to be cleaned up. I've noticed that most APIs can't even handle including the year in the filename when searching. So something like Anabolic Life 2017 won't work but Anabolic Life does work. Maybe there's a smarter API that someone knows.

HaveAGitGat avatar Feb 20 '22 07:02 HaveAGitGat

Think the duration and size check plugins have been enough for most people over the last year so will close this.

Just for fun I threw the request in Chatgpt4, result below. But yeah hard part would be accurately cleaning filenames and detecting if it's a movie/show etc.


Based on previous messages, make a plugin which checks if the movie duration is within 10% of the official OMDb duration using the OMDb api


To create a Tdarr plugin that checks if the movie duration is within 10% of the official OMDb duration using the OMDb API, you will need an API key for OMDb, which can be obtained from http://www.omdbapi.com/apikey.aspx. Here's an example plugin:

const omdbApiKey = 'YOUR_OMDB_API_KEY'; // Replace with your OMDb API key

const details = () => ({
  id: 'Tdarr_Plugin_duration_OmdbDurationCheck',
  Stage: 'Pre-processing',
  Name: 'Check Movie Duration with OMDb',
  Type: 'Video',
  Operation: 'Filter',
  Description: 'This plugin checks if the movie duration is within 10% of the official OMDb duration. If not, the movie is skipped.',
  Version: '1.00',
  Tags: 'pre-processing,ffmpeg,omdb,duration',
});

const plugin = async (file, librarySettings, inputs, otherArguments) => {
  const axios = require('axios');
  
  const response = {
    processFile: false,
    container: `.${file.container}`,
    handBrakeMode: false,
    FFmpegMode: false,
    infoLog: '',
    file,
    removeFromDB: false,
    updateDB: false,
  };

  try {
    const movieTitle = file.meta.Title || file.file;
    const omdbResponse = await axios.get(`http://www.omdbapi.com/?t=${encodeURIComponent(movieTitle)}&apikey=${omdbApiKey}`);

    if (omdbResponse.data.Response === 'True') {
      const officialDuration = parseInt(omdbResponse.data.Runtime, 10);
      const fileDuration = Math.floor(file.ffProbeData.streams[0].duration / 60);

      const minDuration = officialDuration * 0.9;
      const maxDuration = officialDuration * 1.1;

      if (fileDuration >= minDuration && fileDuration <= maxDuration) {
        response.processFile = true;
        response.infoLog += `Movie duration is within 10% of the official OMDb duration.\nOfficial: ${officialDuration} minutes\nFile: ${fileDuration} minutes\n`;
      } else {
        throw Error(`Movie duration is not within 10% of the official OMDb duration.\nOfficial: ${officialDuration} minutes\nFile: ${fileDuration} minutes\n`);
      }
    } else {
      response.infoLog += 'Movie not found on OMDb.\n';
    }
  } catch (error) {
    throw Error(`Error querying OMDb API: ${error.message}\n`);
  }

  return response;
};

module.exports.dependencies = ['axios'];
module.exports.details = details;
module.exports.plugin = plugin;

Replace YOUR_OMDB_API_KEY with your actual OMDb API key. This plugin uses the axios library to make HTTP requests, so make sure to include it in the dependencies array.

This plugin checks the movie duration against the official OMDb duration and skips the movie if it's not within 10% of the official duration. The plugin logs the results in the infoLog.

HaveAGitGat avatar Apr 08 '23 15:04 HaveAGitGat