@ -273,11 +273,6 @@ namespace MediaBrowser.Providers.Movies
if ( string . IsNullOrEmpty ( id ) )
if ( string . IsNullOrEmpty ( id ) )
{
{
id = await FindId ( item , cancellationToken ) . ConfigureAwait ( false ) ;
id = await FindId ( item , cancellationToken ) . ConfigureAwait ( false ) ;
if ( ! string . IsNullOrEmpty ( id ) )
{
item . SetProviderId ( MetadataProviders . Tmdb , id ) ;
}
}
}
if ( ! string . IsNullOrEmpty ( id ) )
if ( ! string . IsNullOrEmpty ( id ) )
@ -506,6 +501,8 @@ namespace MediaBrowser.Providers.Movies
var dataFilePath = GetDataFilePath ( item ) ;
var dataFilePath = GetDataFilePath ( item ) ;
var tmdbId = item . GetProviderId ( MetadataProviders . Tmdb ) ;
if ( string . IsNullOrEmpty ( dataFilePath ) | | ! File . Exists ( dataFilePath ) | | ! File . Exists ( GetImagesDataFilePath ( item ) ) )
if ( string . IsNullOrEmpty ( dataFilePath ) | | ! File . Exists ( dataFilePath ) | | ! File . Exists ( GetImagesDataFilePath ( item ) ) )
{
{
var isBoxSet = item is BoxSet ;
var isBoxSet = item is BoxSet ;
@ -514,7 +511,9 @@ namespace MediaBrowser.Providers.Movies
if ( mainResult = = null ) return ;
if ( mainResult = = null ) return ;
var movieDataPath = GetMovieDataPath ( ConfigurationManager . ApplicationPaths , isBoxSet , mainResult . id . ToString ( _usCulture ) ) ;
tmdbId = mainResult . id . ToString ( _usCulture ) ;
var movieDataPath = GetMovieDataPath ( ConfigurationManager . ApplicationPaths , isBoxSet , tmdbId ) ;
dataFilePath = Path . Combine ( movieDataPath , language + ".json" ) ;
dataFilePath = Path . Combine ( movieDataPath , language + ".json" ) ;
@ -534,7 +533,7 @@ namespace MediaBrowser.Providers.Movies
if ( isForcedRefresh | | ConfigurationManager . Configuration . EnableTmdbUpdates | | ! HasAltMeta ( item ) )
if ( isForcedRefresh | | ConfigurationManager . Configuration . EnableTmdbUpdates | | ! HasAltMeta ( item ) )
{
{
dataFilePath = GetDataFilePath ( item );
dataFilePath = GetDataFilePath ( item , tmdbId );
if ( ! string . IsNullOrEmpty ( dataFilePath ) )
if ( ! string . IsNullOrEmpty ( dataFilePath ) )
{
{
@ -582,8 +581,6 @@ namespace MediaBrowser.Providers.Movies
/// <returns>System.String.</returns>
/// <returns>System.String.</returns>
internal string GetDataFilePath ( BaseItem item )
internal string GetDataFilePath ( BaseItem item )
{
{
var language = ConfigurationManager . Configuration . PreferredMetadataLanguage ;
var id = item . GetProviderId ( MetadataProviders . Tmdb ) ;
var id = item . GetProviderId ( MetadataProviders . Tmdb ) ;
if ( string . IsNullOrEmpty ( id ) )
if ( string . IsNullOrEmpty ( id ) )
@ -591,7 +588,14 @@ namespace MediaBrowser.Providers.Movies
return null ;
return null ;
}
}
var path = GetMovieDataPath ( ConfigurationManager . ApplicationPaths , item is BoxSet , id ) ;
return GetDataFilePath ( item , id ) ;
}
internal string GetDataFilePath ( BaseItem item , string tmdbId )
{
var language = ConfigurationManager . Configuration . PreferredMetadataLanguage ;
var path = GetMovieDataPath ( ConfigurationManager . ApplicationPaths , item is BoxSet , tmdbId ) ;
path = Path . Combine ( path , language + ".json" ) ;
path = Path . Combine ( path , language + ".json" ) ;
@ -682,198 +686,195 @@ namespace MediaBrowser.Providers.Movies
/// <param name="movieData">The movie data.</param>
/// <param name="movieData">The movie data.</param>
private void ProcessMainInfo ( BaseItem movie , CompleteMovieData movieData )
private void ProcessMainInfo ( BaseItem movie , CompleteMovieData movieData )
{
{
if ( movie ! = null & & movieData ! = null )
if ( ! movie . LockedFields . Contains ( MetadataFields . Name ) )
{
{
if ( ! movie . LockedFields . Contains ( MetadataFields . Name ) )
movie . Name = movieData . title ? ? movieData . original_title ? ? movieData . name ? ? movie . Name ;
{
}
movie . Name = movieData . title ? ? movieData . original_title ? ? movieData . name ? ? movie . Name ;
if ( ! movie . LockedFields . Contains ( MetadataFields . Overview ) )
}
{
if ( ! movie . LockedFields . Contains ( MetadataFields . Overview ) )
movie . Overview = WebUtility . HtmlDecode ( movieData . overview ) ;
{
movie . Overview = movie . Overview ! = null ? movie . Overview . Replace ( "\n\n" , "\n" ) : null ;
movie . Overview = WebUtility . HtmlDecode ( movieData . overview ) ;
}
movie . Overview = movie . Overview ! = null ? movie . Overview . Replace ( "\n\n" , "\n" ) : null ;
movie . HomePageUrl = movieData . homepage ;
}
movie . HomePageUrl = movieData . homepage ;
movie . Budget = movieData . budget ;
movie . Budget = movieData . budget ;
movie . Revenue = movieData . revenue ;
movie . Revenue = movieData . revenue ;
if ( ! string . IsNullOrEmpty ( movieData . tagline ) )
if ( ! string . IsNullOrEmpty ( movieData . tagline ) )
{
{
movie . Taglines . Clear ( ) ;
movie . Taglines . Clear ( ) ;
movie . AddTagline ( movieData . tagline ) ;
movie . AddTagline ( movieData . tagline ) ;
}
}
movie . SetProviderId ( MetadataProviders . Imdb , movieData . imdb_id ) ;
movie . SetProviderId ( MetadataProviders . Tmdb , movieData . id . ToString ( _usCulture ) ) ;
movie . SetProviderId ( MetadataProviders . Imdb , movieData . imdb_id ) ;
if ( movieData . belongs_to_collection ! = null )
if ( movieData . belongs_to_collection ! = null )
{
{
movie . SetProviderId ( MetadataProviders . TmdbCollection ,
movie . SetProviderId ( MetadataProviders . TmdbCollection ,
movieData . belongs_to_collection . id . ToString ( CultureInfo . InvariantCulture ) ) ;
movieData . belongs_to_collection . id . ToString ( CultureInfo . InvariantCulture ) ) ;
var movieItem = movie as Movie ;
var movieItem = movie as Movie ;
if ( movieItem ! = null )
if ( movieItem ! = null )
{
movieItem . TmdbCollectionName = movieData . belongs_to_collection . name ;
}
}
else
{
{
movie . SetProviderId ( MetadataProviders . TmdbCollection , null ) ; // clear out any old entry
movieItem . TmdbCollectionName = movieData . belongs_to_collection . name ;
}
}
}
else
{
movie . SetProviderId ( MetadataProviders . TmdbCollection , null ) ; // clear out any old entry
}
float rating ;
float rating ;
string voteAvg = movieData . vote_average . ToString ( CultureInfo . InvariantCulture ) ;
string voteAvg = movieData . vote_average . ToString ( CultureInfo . InvariantCulture ) ;
// tmdb appears to have unified their numbers to always report "7.3" regardless of country
// tmdb appears to have unified their numbers to always report "7.3" regardless of country
// so I removed the culture-specific processing here because it was not working for other countries -ebr
// so I removed the culture-specific processing here because it was not working for other countries -ebr
// Movies get this from imdb
// Movies get this from imdb
if ( movie is BoxSet & & float . TryParse ( voteAvg , NumberStyles . AllowDecimalPoint , CultureInfo . InvariantCulture , out rating ) )
if ( movie is BoxSet & & float . TryParse ( voteAvg , NumberStyles . AllowDecimalPoint , CultureInfo . InvariantCulture , out rating ) )
{
{
movie . CommunityRating = rating ;
movie . CommunityRating = rating ;
}
}
// Movies get this from imdb
// Movies get this from imdb
if ( movie is BoxSet )
if ( movie is BoxSet )
{
movie . VoteCount = movieData . vote_count ;
}
//release date and certification are retrieved based on configured country and we fall back on US if not there and to minimun release date if still no match
if ( movieData . releases ! = null & & movieData . releases . countries ! = null )
{
var ourRelease = movieData . releases . countries . FirstOrDefault ( c = > c . iso_3166_1 . Equals ( ConfigurationManager . Configuration . MetadataCountryCode , StringComparison . OrdinalIgnoreCase ) ) ? ? new Country ( ) ;
var usRelease = movieData . releases . countries . FirstOrDefault ( c = > c . iso_3166_1 . Equals ( "US" , StringComparison . OrdinalIgnoreCase ) ) ? ? new Country ( ) ;
var minimunRelease = movieData . releases . countries . OrderBy ( c = > c . release_date ) . FirstOrDefault ( ) ? ? new Country ( ) ;
if ( ! movie . LockedFields . Contains ( MetadataFields . OfficialRating ) )
{
{
movie . VoteCount = movieData . vote_count ;
var ratingPrefix = ConfigurationManager . Configuration . MetadataCountryCode . Equals ( "us" , StringComparison . OrdinalIgnoreCase ) ? "" : ConfigurationManager . Configuration . MetadataCountryCode + "-" ;
movie . OfficialRating = ! string . IsNullOrEmpty ( ourRelease . certification )
? ratingPrefix + ourRelease . certification
: ! string . IsNullOrEmpty ( usRelease . certification )
? usRelease . certification
: ! string . IsNullOrEmpty ( minimunRelease . certification )
? minimunRelease . iso_3166_1 + "-" + minimunRelease . certification
: null ;
}
}
//release date and certification are retrieved based on configured country and we fall back on US if not there and to minimun release date if still no match
if ( ourRelease . release_date ! = default ( DateTime ) )
if ( movieData . releases ! = null & & movieData . releases . countries ! = null )
{
{
var ourRelease = movieData . releases . countries . FirstOrDefault ( c = > c . iso_3166_1 . Equals ( ConfigurationManager . Configuration . MetadataCountryCode , StringComparison . OrdinalIgnoreCase ) ) ? ? new Country ( ) ;
if ( ourRelease . release_date . Year ! = 1 )
var usRelease = movieData . releases . countries . FirstOrDefault ( c = > c . iso_3166_1 . Equals ( "US" , StringComparison . OrdinalIgnoreCase ) ) ? ? new Country ( ) ;
var minimunRelease = movieData . releases . countries . OrderBy ( c = > c . release_date ) . FirstOrDefault ( ) ? ? new Country ( ) ;
if ( ! movie . LockedFields . Contains ( MetadataFields . OfficialRating ) )
{
{
var ratingPrefix = ConfigurationManager . Configuration . MetadataCountryCode . Equals ( "us" , StringComparison . OrdinalIgnoreCase ) ? "" : ConfigurationManager . Configuration . MetadataCountryCode + "-" ;
movie . PremiereDate = ourRelease . release_date . ToUniversalTime ( ) ;
movie . OfficialRating = ! string . IsNullOrEmpty ( ourRelease . certification )
movie . ProductionYear = ourRelease . release_date . Year ;
? ratingPrefix + ourRelease . certification
: ! string . IsNullOrEmpty ( usRelease . certification )
? usRelease . certification
: ! string . IsNullOrEmpty ( minimunRelease . certification )
? minimunRelease . iso_3166_1 + "-" + minimunRelease . certification
: null ;
}
if ( ourRelease . release_date ! = default ( DateTime ) )
{
if ( ourRelease . release_date . Year ! = 1 )
{
movie . PremiereDate = ourRelease . release_date . ToUniversalTime ( ) ;
movie . ProductionYear = ourRelease . release_date . Year ;
}
}
}
else if ( usRelease . release_date ! = default ( DateTime ) )
}
{
else if ( usRelease . release_date ! = default ( DateTime ) )
if ( usRelease . release_date . Year ! = 1 )
{
{
if ( usRelease . release_date . Year ! = 1 )
movie . PremiereDate = usRelease . release_date . ToUniversalTime ( ) ;
movie . ProductionYear = usRelease . release_date . Year ;
}
}
else if ( minimunRelease . release_date ! = default ( DateTime ) )
{
{
if ( minimunRelease . release_date . Year ! = 1 )
movie . PremiereDate = usRelease . release_date . ToUniversalTime ( ) ;
{
movie . ProductionYear = usRelease . release_date . Year ;
movie . PremiereDate = minimunRelease . release_date . ToUniversalTime ( ) ;
movie . ProductionYear = minimunRelease . release_date . Year ;
}
}
}
}
}
else
else if ( minimunRelease . release_date ! = default ( DateTime ) )
{
{
if ( m ovieData . release_date . Year ! = 1 )
if ( minimunRelease . release_date . Year ! = 1 )
{
{
//no specific country release info at all
movie . PremiereDate = m ovieData . release_date . ToUniversalTime ( ) ;
movie . PremiereDate = m inimunRelease . release_date . ToUniversalTime ( ) ;
movie . ProductionYear = m ovieData . release_date . Year ;
movie . ProductionYear = m inimunRelease . release_date . Year ;
}
}
}
}
}
//if that didn't find a rating and we are a boxset, use the one from our first child
else
if ( movie . OfficialRating = = null & & movie is BoxSet & & ! movie . LockedFields . Contains ( MetadataFields . OfficialRating ) )
{
if ( movieData . release_date . Year ! = 1 )
{
{
var boxset = movie as BoxSet ;
//no specific country release info at all
Logger . Info ( "MovieDbProvider - Using rating of first child of boxset..." ) ;
movie . PremiereDate = movieData . release_date . ToUniversalTime ( ) ;
movie . ProductionYear = movieData . release_date . Year ;
}
}
var firstChild = boxset . Children . Concat ( boxset . GetLinkedChildren ( ) ) . FirstOrDefault ( ) ;
//if that didn't find a rating and we are a boxset, use the one from our first child
if ( movie . OfficialRating = = null & & movie is BoxSet & & ! movie . LockedFields . Contains ( MetadataFields . OfficialRating ) )
{
var boxset = movie as BoxSet ;
Logger . Info ( "MovieDbProvider - Using rating of first child of boxset..." ) ;
boxset . OfficialRating = firstChild ! = null ? firstChild . OfficialRating : null ;
var firstChild = boxset . Children . Concat ( boxset . GetLinkedChildren ( ) ) . FirstOrDefault ( ) ;
}
if ( movieData . runtime > 0 )
boxset . OfficialRating = firstChild ! = null ? firstChild . OfficialRating : null ;
movie . OriginalRunTimeTicks = TimeSpan . FromMinutes ( movieData . runtime ) . Ticks ;
}
//studios
if ( movieData . runtime > 0 )
if ( movieData . production_companies ! = null & & ! movie . LockedFields . Contains ( MetadataFields . Studios ) )
movie . OriginalRunTimeTicks = TimeSpan . FromMinutes ( movieData . runtime ) . Ticks ;
{
movie . Studios . Clear ( ) ;
foreach ( var studio in movieData . production_companies . Select ( c = > c . name ) )
//studios
{
if ( movieData . production_companies ! = null & & ! movie . LockedFields . Contains ( MetadataFields . Studios ) )
movie . AddStudio ( studio ) ;
{
}
movie . Studios . Clear ( ) ;
}
// genres
foreach ( var studio in movieData . production_companies . Select ( c = > c . name ) )
// Movies get this from imdb
if ( movieData . genres ! = null & & ! movie . LockedFields . Contains ( MetadataFields . Genres ) )
{
{
// Only grab them if a boxset or there are no genres.
movie . AddStudio ( studio ) ;
// For movies and trailers we'll use imdb via omdb
if ( movie is BoxSet | | movie . Genres . Count = = 0 )
{
movie . Genres . Clear ( ) ;
foreach ( var genre in movieData . genres . Select ( g = > g . name ) )
{
movie . AddGenre ( genre ) ;
}
}
}
}
}
if ( ! movie . LockedFields . Contains ( MetadataFields . Cast ) )
// genres
// Movies get this from imdb
if ( movieData . genres ! = null & & ! movie . LockedFields . Contains ( MetadataFields . Genres ) )
{
// Only grab them if a boxset or there are no genres.
// For movies and trailers we'll use imdb via omdb
if ( movie is BoxSet | | movie . Genres . Count = = 0 )
{
{
movie . People . Clear ( ) ;
movie . Genres . Clear ( ) ;
//Actors, Directors, Writers - all in People
//actors come from cast
if ( movieData . casts ! = null & & movieData . casts . cast ! = null )
{
foreach ( var actor in movieData . casts . cast . OrderBy ( a = > a . order ) ) movie . AddPerson ( new PersonInfo { Name = actor . name . Trim ( ) , Role = actor . character , Type = PersonType . Actor , SortOrder = actor . order } ) ;
}
//and the rest from crew
foreach ( var genre in movieData . genres . Select ( g = > g . name ) )
if ( movieData . casts ! = null & & movieData . casts . crew ! = null )
{
{
foreach ( var person in movieData . casts . crew ) movie . AddPerson ( new PersonInfo { Name = person . name . Trim ( ) , Role = person . job , Type = person . department } ) ;
movie . AddGenre ( genre ) ;
}
}
}
}
}
if ( movieData . keywords ! = null & & movieData . keywords . keywords ! = null & & ! movie . LockedFields . Contains ( MetadataFields . Tags ) )
if ( ! movie . LockedFields . Contains ( MetadataFields . Cast ) )
{
movie . People . Clear ( ) ;
//Actors, Directors, Writers - all in People
//actors come from cast
if ( movieData . casts ! = null & & movieData . casts . cast ! = null )
{
{
movie . Tags = movieData . keywords . keywords . Select ( i = > i . name ) . ToList ( ) ;
foreach ( var actor in movieData . casts . cast . OrderBy ( a = > a . order ) ) movie . AddPerson ( new PersonInfo { Name = actor . name . Trim ( ) , Role = actor . character , Type = PersonType . Actor , SortOrder = actor . order } ) ;
}
}
if ( movieData . trailers ! = null & & movieData . trailers . youtube ! = null & &
//and the rest from crew
movieData . trailers . youtube . Count > 0 )
if ( movieData . casts ! = null & & movieData . casts . crew ! = null )
{
{
movie . RemoteTrailers = movieData . trailers . youtube . Select ( i = > new MediaUrl
foreach ( var person in movieData . casts . crew ) movie . AddPerson ( new PersonInfo { Name = person . name . Trim ( ) , Role = person . job , Type = person . department } ) ;
{
Url = string . Format ( "http://www.youtube.com/watch?v={0}" , i . source ) ,
IsDirectLink = false ,
Name = i . name ,
VideoSize = string . Equals ( "hd" , i . size , StringComparison . OrdinalIgnoreCase ) ? VideoSize . HighDefinition : VideoSize . StandardDefinition
} ) . ToList ( ) ;
}
}
}
}
if ( movieData . keywords ! = null & & movieData . keywords . keywords ! = null & & ! movie . LockedFields . Contains ( MetadataFields . Tags ) )
{
movie . Tags = movieData . keywords . keywords . Select ( i = > i . name ) . ToList ( ) ;
}
if ( movieData . trailers ! = null & & movieData . trailers . youtube ! = null & &
movieData . trailers . youtube . Count > 0 )
{
movie . RemoteTrailers = movieData . trailers . youtube . Select ( i = > new MediaUrl
{
Url = string . Format ( "http://www.youtube.com/watch?v={0}" , i . source ) ,
IsDirectLink = false ,
Name = i . name ,
VideoSize = string . Equals ( "hd" , i . size , StringComparison . OrdinalIgnoreCase ) ? VideoSize . HighDefinition : VideoSize . StandardDefinition
} ) . ToList ( ) ;
}
}
}
private DateTime _lastRequestDate = DateTime . MinValue ;
private DateTime _lastRequestDate = DateTime . MinValue ;