Merge pull request #962 from MikePDev/MediaBrowser_Imdb_From_Media

Add imdbid detection from media file
This commit is contained in:
Luke 2015-01-04 09:29:03 -05:00
commit 3eb4ca598c
2 changed files with 24 additions and 5 deletions

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Text.RegularExpressions;
namespace MediaBrowser.Server.Implementations.Library namespace MediaBrowser.Server.Implementations.Library
{ {
@ -31,6 +32,14 @@ namespace MediaBrowser.Server.Implementations.Library
int end = str.IndexOf(']', start); int end = str.IndexOf(']', start);
return str.Substring(start, end - start); return str.Substring(start, end - start);
} }
// for imdbid we also accept pattern matching
if (attrib == "imdbid")
{
Regex imdbPattern = new Regex("tt\\d{7}");
var m = imdbPattern.Match(str);
return m.Success ? m.Value : null;
}
return null; return null;
} }
} }

View File

@ -228,24 +228,34 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
{ {
base.SetInitialItemValues(item, args); base.SetInitialItemValues(item, args);
SetProviderIdFromPath(item); SetProviderIdsFromPath(item);
} }
/// <summary> /// <summary>
/// Sets the provider id from path. /// Sets the provider id from path.
/// </summary> /// </summary>
/// <param name="item">The item.</param> /// <param name="item">The item.</param>
private void SetProviderIdFromPath(Video item) private void SetProviderIdsFromPath(Video item)
{ {
//we need to only look at the name of this actual item (not parents) //we need to only look at the name of this actual item (not parents)
var justName = item.IsInMixedFolder ? Path.GetFileName(item.Path) : Path.GetFileName(item.ContainingFolderPath); var justName = item.IsInMixedFolder ? Path.GetFileName(item.Path) : Path.GetFileName(item.ContainingFolderPath);
var id = justName.GetAttributeValue("tmdbid"); // check for tmdb id
var tmdbid = justName.GetAttributeValue("tmdbid");
if (!string.IsNullOrEmpty(id)) if (!string.IsNullOrEmpty(tmdbid))
{ {
item.SetProviderId(MetadataProviders.Tmdb, id); item.SetProviderId(MetadataProviders.Tmdb, tmdbid);
} }
// check for imdb id - we use full media path, as we can assume, that this will match in any use case (wither id in parent dir or in file name)
var imdbid = item.Path.GetAttributeValue("imdbid");
if (!string.IsNullOrEmpty(imdbid))
{
item.SetProviderId(MetadataProviders.Imdb, imdbid);
}
} }
/// <summary> /// <summary>