2012-09-11 01:34:02 +00:00
using MediaBrowser.Model.Entities ;
2012-09-17 16:55:58 +00:00
using MediaBrowser.Controller.Library ;
2012-09-17 17:05:42 +00:00
using MediaBrowser.Controller.IO ;
2012-09-11 01:34:02 +00:00
using System ;
2012-09-20 15:25:16 +00:00
using System.Threading.Tasks ;
2012-07-12 06:55:27 +00:00
using System.Collections.Generic ;
2012-08-18 08:22:54 +00:00
using System.Linq ;
2012-07-12 06:55:27 +00:00
2012-09-11 01:34:02 +00:00
namespace MediaBrowser.Controller.Entities
2012-07-12 06:55:27 +00:00
{
2012-08-18 08:22:54 +00:00
public abstract class BaseItem : BaseEntity , IHasProviderIds
2012-07-12 06:55:27 +00:00
{
2012-09-20 17:52:56 +00:00
public IEnumerable < string > PhysicalLocations
{
get
{
return _resolveArgs . PhysicalLocations ;
}
}
2012-07-20 02:22:44 +00:00
public string SortName { get ; set ; }
2012-07-12 06:55:27 +00:00
2012-07-20 02:22:44 +00:00
/// <summary>
/// When the item first debuted. For movies this could be premiere date, episodes would be first aired
/// </summary>
public DateTime ? PremiereDate { get ; set ; }
public string LogoImagePath { get ; set ; }
2012-08-18 08:22:54 +00:00
2012-07-20 02:22:44 +00:00
public string ArtImagePath { get ; set ; }
2012-08-18 08:22:54 +00:00
2012-07-20 02:22:44 +00:00
public string ThumbnailImagePath { get ; set ; }
2012-08-18 08:22:54 +00:00
2012-07-20 02:22:44 +00:00
public string BannerImagePath { get ; set ; }
2012-07-12 06:55:27 +00:00
2012-07-20 02:22:44 +00:00
public IEnumerable < string > BackdropImagePaths { get ; set ; }
2012-07-12 06:55:27 +00:00
2012-07-20 02:22:44 +00:00
public string OfficialRating { get ; set ; }
2012-08-17 13:16:50 +00:00
2012-07-20 02:22:44 +00:00
public string CustomRating { get ; set ; }
2012-09-02 05:30:42 +00:00
public string CustomPin { get ; set ; }
2012-07-12 06:55:27 +00:00
2012-08-20 02:05:55 +00:00
public string Language { get ; set ; }
2012-07-20 02:22:44 +00:00
public string Overview { get ; set ; }
2012-08-24 12:45:54 +00:00
public List < string > Taglines { get ; set ; }
2012-07-12 06:55:27 +00:00
2012-08-24 16:24:29 +00:00
/// <summary>
/// Using a Dictionary to prevent duplicates
/// </summary>
public Dictionary < string , PersonInfo > People { get ; set ; }
2012-07-12 06:55:27 +00:00
2012-08-24 12:45:54 +00:00
public List < string > Studios { get ; set ; }
2012-07-12 06:55:27 +00:00
2012-08-24 12:45:54 +00:00
public List < string > Genres { get ; set ; }
2012-07-12 06:55:27 +00:00
2012-07-20 02:22:44 +00:00
public string DisplayMediaType { get ; set ; }
2012-07-12 06:55:27 +00:00
2012-09-18 00:08:21 +00:00
public float? CommunityRating { get ; set ; }
2012-08-18 08:22:54 +00:00
public long? RunTimeTicks { get ; set ; }
2012-07-12 06:55:27 +00:00
2012-07-20 02:22:44 +00:00
public string AspectRatio { get ; set ; }
public int? ProductionYear { get ; set ; }
/// <summary>
/// If the item is part of a series, this is it's number in the series.
/// This could be episode number, album track number, etc.
/// </summary>
public int? IndexNumber { get ; set ; }
2012-07-12 06:55:27 +00:00
2012-08-20 02:05:55 +00:00
/// <summary>
/// For an episode this could be the season number, or for a song this could be the disc number.
/// </summary>
public int? ParentIndexNumber { get ; set ; }
2012-07-20 02:22:44 +00:00
public IEnumerable < Video > LocalTrailers { get ; set ; }
public string TrailerUrl { get ; set ; }
2012-08-15 13:20:29 +00:00
public Dictionary < string , string > ProviderIds { get ; set ; }
2012-08-18 08:22:54 +00:00
public Dictionary < Guid , UserItemData > UserData { get ; set ; }
2012-08-15 13:20:29 +00:00
2012-09-10 02:30:34 +00:00
public UserItemData GetUserData ( User user , bool createIfNull )
2012-08-15 13:20:29 +00:00
{
2012-08-18 08:22:54 +00:00
if ( UserData = = null | | ! UserData . ContainsKey ( user . Id ) )
2012-08-15 13:20:29 +00:00
{
2012-09-10 02:30:34 +00:00
if ( createIfNull )
{
AddUserData ( user , new UserItemData ( ) ) ;
}
else
{
return null ;
}
2012-08-15 13:20:29 +00:00
}
2012-08-18 08:22:54 +00:00
return UserData [ user . Id ] ;
2012-08-15 13:20:29 +00:00
}
2012-09-10 02:30:34 +00:00
private void AddUserData ( User user , UserItemData data )
2012-08-15 13:20:29 +00:00
{
2012-08-18 08:22:54 +00:00
if ( UserData = = null )
2012-08-15 13:20:29 +00:00
{
2012-08-18 08:22:54 +00:00
UserData = new Dictionary < Guid , UserItemData > ( ) ;
2012-08-15 13:20:29 +00:00
}
2012-08-18 08:22:54 +00:00
UserData [ user . Id ] = data ;
2012-08-15 13:20:29 +00:00
}
/// <summary>
2012-08-18 08:22:54 +00:00
/// Determines if a given user has access to this item
2012-08-15 13:20:29 +00:00
/// </summary>
2012-08-18 08:22:54 +00:00
internal bool IsParentalAllowed ( User user )
2012-08-15 13:20:29 +00:00
{
2012-08-18 08:22:54 +00:00
return true ;
2012-08-15 13:20:29 +00:00
}
2012-08-17 17:37:26 +00:00
/// <summary>
2012-08-18 08:22:54 +00:00
/// Finds an item by ID, recursively
2012-08-17 17:37:26 +00:00
/// </summary>
2012-08-18 08:22:54 +00:00
public virtual BaseItem FindItemById ( Guid id )
2012-08-17 17:37:26 +00:00
{
2012-08-18 08:22:54 +00:00
if ( Id = = id )
{
return this ;
}
if ( LocalTrailers ! = null )
{
return LocalTrailers . FirstOrDefault ( i = > i . Id = = id ) ;
}
return null ;
2012-08-17 17:37:26 +00:00
}
2012-08-19 17:00:52 +00:00
2012-08-20 00:14:12 +00:00
public virtual bool IsFolder
{
get
{
return false ;
}
}
2012-09-17 15:12:43 +00:00
/// <summary>
/// Determine if we have changed vs the passed in copy
/// </summary>
2012-09-20 17:52:56 +00:00
/// <param name="copy"></param>
2012-09-17 15:12:43 +00:00
/// <returns></returns>
2012-09-20 17:52:56 +00:00
public virtual bool IsChanged ( BaseItem copy )
2012-09-17 15:12:43 +00:00
{
2012-09-20 17:52:56 +00:00
bool changed = copy . DateModified ! = this . DateModified ;
if ( changed ) MediaBrowser . Common . Logging . Logger . LogDebugInfo ( this . Name + " changed - original creation: " + this . DateCreated + " new creation: " + copy . DateCreated + " original modified: " + this . DateModified + " new modified: " + copy . DateModified ) ;
2012-09-17 15:12:43 +00:00
return changed ;
}
2012-08-19 17:00:52 +00:00
/// <summary>
/// Determines if the item is considered new based on user settings
/// </summary>
public bool IsRecentlyAdded ( User user )
{
2012-09-04 19:23:15 +00:00
return ( DateTime . UtcNow - DateCreated ) . TotalDays < user . RecentItemDays ;
2012-08-19 17:00:52 +00:00
}
2012-08-24 16:24:29 +00:00
public void AddPerson ( PersonInfo person )
{
if ( People = = null )
{
People = new Dictionary < string , PersonInfo > ( StringComparer . OrdinalIgnoreCase ) ;
}
People [ person . Name ] = person ;
}
2012-09-10 02:30:34 +00:00
/// <summary>
/// Marks the item as either played or unplayed
/// </summary>
public virtual void SetPlayedStatus ( User user , bool wasPlayed )
{
UserItemData data = GetUserData ( user , true ) ;
if ( wasPlayed )
{
data . PlayCount = Math . Max ( data . PlayCount , 1 ) ;
}
else
{
data . PlayCount = 0 ;
data . PlaybackPositionTicks = 0 ;
}
}
2012-09-20 15:25:16 +00:00
/// <summary>
/// Do whatever refreshing is necessary when the filesystem pertaining to this item has changed.
/// </summary>
/// <returns></returns>
public virtual Task ChangedExternally ( )
{
return Task . Run ( ( ) = > RefreshMetadata ( ) ) ;
}
2012-07-12 06:55:27 +00:00
}
}