Exemplo n.º 1
0
    public static bool CleanupTitle(MovieInfo movieInfo)
    {
      string originalTitle = movieInfo.MovieName;
      foreach (Regex regex in REGEXP_CLEANUPS)
        movieInfo.MovieName = regex.Replace(movieInfo.MovieName, "");

      return originalTitle != movieInfo.MovieName;
    }
Exemplo n.º 2
0
    public MovieItem(MediaItem mediaItem) : base(mediaItem)
    {
      MovieInfo movieInfo = new MovieInfo();
      MediaItemAspect movieAspect;
      if (!mediaItem.Aspects.TryGetValue(MovieAspect.ASPECT_ID, out movieAspect)) 
        return;

      MovieName = (string)movieAspect[MovieAspect.ATTR_MOVIE_NAME] ?? string.Empty;
      CollectionName = movieInfo.CollectionName = (string)movieAspect[MovieAspect.ATTR_COLLECTION_NAME] ?? string.Empty;
    }
Exemplo n.º 3
0
 public static bool CleanupTitle(MovieInfo movieInfo)
 {
   if (string.IsNullOrEmpty(movieInfo.MovieName))
     return false;
   string originalTitle = movieInfo.MovieName;
   foreach (Regex regex in REGEXP_CLEANUPS)
     movieInfo.MovieName = regex.Replace(movieInfo.MovieName, "");
   movieInfo.MovieName = CleanupWhiteSpaces(movieInfo.MovieName);
   return originalTitle != movieInfo.MovieName;
 }
Exemplo n.º 4
0
    public override void Update(MediaItem mediaItem)
    {
      base.Update(mediaItem);
      MovieInfo movieInfo = new MovieInfo();
      MediaItemAspect movieAspect;
      if (!mediaItem.Aspects.TryGetValue(MovieAspect.ASPECT_ID, out movieAspect))
        return;

      MovieName = (string)movieAspect[MovieAspect.ATTR_MOVIE_NAME] ?? string.Empty;
      CollectionName = movieInfo.CollectionName = (string)movieAspect[MovieAspect.ATTR_COLLECTION_NAME] ?? string.Empty;
      FireChange();
    }
Exemplo n.º 5
0
 public static bool MatchTitleYear(MovieInfo movieInfo)
 {
   foreach (Regex regex in REGEXP_TITLE_YEAR)
   {
     Match match = regex.Match(movieInfo.MovieName);
     if (match.Groups[GROUP_TITLE].Length > 0 || match.Groups[GROUP_YEAR].Length > 0)
     {
       movieInfo.MovieName = match.Groups[GROUP_TITLE].Value.Trim(new[] { ' ', '-' });
       movieInfo.Year = int.Parse(match.Groups[GROUP_YEAR].Value);
       return true;
     }
   }
   return false;
 }
    private bool ExtractMovieData(ILocalFsResourceAccessor lfsra, IDictionary<Guid, MediaItemAspect> extractedAspectData)
    {
      // Calling EnsureLocalFileSystemAccess not necessary; only string operation
      string[] pathsToTest = new[] { lfsra.LocalFileSystemPath, lfsra.CanonicalLocalResourcePath.ToString() };
      string title;
      // VideoAspect must be present to be sure it is actually a video resource.
      if (!extractedAspectData.ContainsKey(VideoAspect.ASPECT_ID))
        return false;

      if (!MediaItemAspect.TryGetAttribute(extractedAspectData, MediaAspect.ATTR_TITLE, out title) || string.IsNullOrEmpty(title))
        return false;

      MovieInfo movieInfo = new MovieInfo
        {
          MovieName = title,
        };

      // Allow the online lookup to choose best matching language for metadata
      ICollection<string> movieLanguages;
      if (MediaItemAspect.TryGetAttribute(extractedAspectData, VideoAspect.ATTR_AUDIOLANGUAGES, out movieLanguages) && movieLanguages.Count > 0)
        movieInfo.Languages.AddRange(movieLanguages);

      // Try to use an existing IMDB id for exact mapping
      string imdbId;
      if (MediaItemAspect.TryGetAttribute(extractedAspectData, MovieAspect.ATTR_IMDB_ID, out imdbId) ||
          pathsToTest.Any(path => ImdbIdMatcher.TryMatchImdbId(path, out imdbId)) ||
          MatroskaMatcher.TryMatchImdbId(lfsra, out imdbId))
        movieInfo.ImdbId = imdbId;

      // Also test the full path year, using a dummy. This is useful if the path contains the real name and year.
      foreach (string path in pathsToTest)
      {
        MovieInfo dummy = new MovieInfo { MovieName = path };
        if (NamePreprocessor.MatchTitleYear(dummy))
        {
          movieInfo.MovieName = dummy.MovieName;
          movieInfo.Year = dummy.Year;
          break;
        }
      }

      // When searching movie title, the year can be relevant for multiple titles with same name but different years
      DateTime recordingDate;
      if (MediaItemAspect.TryGetAttribute(extractedAspectData, MediaAspect.ATTR_RECORDINGTIME, out recordingDate))
        movieInfo.Year = recordingDate.Year;

      if (MovieTheMovieDbMatcher.Instance.FindAndUpdateMovie(movieInfo))
      {
        if (!_onlyFanArt)
          movieInfo.SetMetadata(extractedAspectData);
        if (_onlyFanArt && movieInfo.MovieDbId > 0)
          MediaItemAspect.SetAttribute(extractedAspectData, MovieAspect.ATTR_TMDB_ID, movieInfo.MovieDbId);
        if (_onlyFanArt && movieInfo.CollectionMovieDbId > 0)
          MediaItemAspect.SetAttribute(extractedAspectData, MovieAspect.ATTR_COLLECTION_ID, movieInfo.CollectionMovieDbId);
        return true;
      }
      return false;
    }