aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Entities/BaseItem.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Controller/Entities/BaseItem.cs')
-rw-r--r--MediaBrowser.Controller/Entities/BaseItem.cs225
1 files changed, 90 insertions, 135 deletions
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index 990ea49f6..29f13fad5 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -53,16 +53,6 @@ namespace MediaBrowser.Controller.Entities
public static string ThemeSongFilename = "theme";
public static string ThemeVideosFolderName = "backdrops";
- public static List<KeyValuePair<string, ExtraType>> ExtraSuffixes = new List<KeyValuePair<string, ExtraType>>
- {
- new KeyValuePair<string,ExtraType>("-trailer", ExtraType.Trailer),
- new KeyValuePair<string,ExtraType>("-deleted", ExtraType.DeletedScene),
- new KeyValuePair<string,ExtraType>("-behindthescenes", ExtraType.BehindTheScenes),
- new KeyValuePair<string,ExtraType>("-interview", ExtraType.Interview),
- new KeyValuePair<string,ExtraType>("-scene", ExtraType.Scene),
- new KeyValuePair<string,ExtraType>("-sample", ExtraType.Sample)
- };
-
public List<ItemImageInfo> ImageInfos { get; set; }
[IgnoreDataMember]
@@ -222,6 +212,20 @@ namespace MediaBrowser.Controller.Entities
}
}
+ [IgnoreDataMember]
+ public virtual string FileNameWithoutExtension
+ {
+ get
+ {
+ if (LocationType == LocationType.FileSystem)
+ {
+ return System.IO.Path.GetFileNameWithoutExtension(Path);
+ }
+
+ return null;
+ }
+ }
+
/// <summary>
/// This is just a helper for convenience
/// </summary>
@@ -361,6 +365,15 @@ namespace MediaBrowser.Controller.Entities
}
}
+ public bool ContainsPerson(string name)
+ {
+ if (string.IsNullOrWhiteSpace(name))
+ {
+ throw new ArgumentNullException("name");
+ }
+ return People.Any(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase));
+ }
+
public string GetInternalMetadataPath()
{
return GetInternalMetadataPath(ConfigurationManager.ApplicationPaths.InternalMetadataPath);
@@ -594,118 +607,6 @@ namespace MediaBrowser.Controller.Entities
}
/// <summary>
- /// Loads local trailers from the file system
- /// </summary>
- /// <returns>List{Video}.</returns>
- private IEnumerable<Trailer> LoadLocalTrailers(List<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService)
- {
- var files = fileSystemChildren.OfType<DirectoryInfo>()
- .Where(i => string.Equals(i.Name, TrailerFolderName, StringComparison.OrdinalIgnoreCase))
- .SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly))
- .ToList();
-
- var extraTypes = new List<ExtraType> { ExtraType.Trailer };
- var suffixes = ExtraSuffixes.Where(i => extraTypes.Contains(i.Value))
- .Select(i => i.Key)
- .ToList();
-
- files.AddRange(fileSystemChildren.OfType<FileInfo>()
- .Where(i =>
- {
- var nameEithoutExtension = FileSystem.GetFileNameWithoutExtension(i);
-
- if (!suffixes.Any(s => nameEithoutExtension.EndsWith(s, StringComparison.OrdinalIgnoreCase)))
- {
- return false;
- }
-
- return !string.Equals(Path, i.FullName, StringComparison.OrdinalIgnoreCase);
- }));
-
- return LibraryManager.ResolvePaths<Trailer>(files, directoryService, null).Select(video =>
- {
- // Try to retrieve it from the db. If we don't find it, use the resolved version
- var dbItem = LibraryManager.GetItemById(video.Id) as Trailer;
-
- if (dbItem != null)
- {
- video = dbItem;
- }
-
- if (video != null)
- {
- video.ExtraType = ExtraType.Trailer;
- }
-
- return video;
-
- // Sort them so that the list can be easily compared for changes
- }).OrderBy(i => i.Path).ToList();
- }
-
- protected IEnumerable<Video> LoadSpecialFeatures(List<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService)
- {
- var files = fileSystemChildren.OfType<DirectoryInfo>()
- .Where(i => string.Equals(i.Name, "extras", StringComparison.OrdinalIgnoreCase) || string.Equals(i.Name, "specials", StringComparison.OrdinalIgnoreCase))
- .SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly))
- .ToList();
-
- var extraTypes = new List<ExtraType> { ExtraType.BehindTheScenes, ExtraType.DeletedScene, ExtraType.Interview, ExtraType.Sample, ExtraType.Scene, ExtraType.Clip };
- var suffixes = ExtraSuffixes.Where(i => extraTypes.Contains(i.Value))
- .Select(i => i.Key)
- .ToList();
-
- files.AddRange(fileSystemChildren.OfType<FileInfo>()
- .Where(i =>
- {
- var nameEithoutExtension = FileSystem.GetFileNameWithoutExtension(i);
-
- if (!suffixes.Any(s => nameEithoutExtension.EndsWith(s, StringComparison.OrdinalIgnoreCase)))
- {
- return false;
- }
-
- return !string.Equals(Path, i.FullName, StringComparison.OrdinalIgnoreCase);
- }));
-
- return LibraryManager.ResolvePaths<Video>(files, directoryService, null).Select(video =>
- {
- // Try to retrieve it from the db. If we don't find it, use the resolved version
- var dbItem = LibraryManager.GetItemById(video.Id) as Video;
-
- if (dbItem != null)
- {
- video = dbItem;
- }
-
- if (video != null)
- {
- SetExtraTypeFromFilename(video);
- }
-
- return video;
-
- // Sort them so that the list can be easily compared for changes
- }).OrderBy(i => i.Path).ToList();
- }
-
- private void SetExtraTypeFromFilename(Video item)
- {
- var name = System.IO.Path.GetFileNameWithoutExtension(item.Path) ?? string.Empty;
-
- foreach (var suffix in ExtraSuffixes)
- {
- if (name.EndsWith(suffix.Key, StringComparison.OrdinalIgnoreCase))
- {
- item.ExtraType = suffix.Value;
- return;
- }
- }
-
- item.ExtraType = ExtraType.Clip;
- }
-
- /// <summary>
/// Loads the theme songs.
/// </summary>
/// <returns>List{Audio.Audio}.</returns>
@@ -721,7 +622,9 @@ namespace MediaBrowser.Controller.Entities
.Where(i => string.Equals(FileSystem.GetFileNameWithoutExtension(i), ThemeSongFilename, StringComparison.OrdinalIgnoreCase))
);
- return LibraryManager.ResolvePaths<Audio.Audio>(files, directoryService, null).Select(audio =>
+ return LibraryManager.ResolvePaths(files, directoryService, null)
+ .OfType<Audio.Audio>()
+ .Select(audio =>
{
// Try to retrieve it from the db. If we don't find it, use the resolved version
var dbItem = LibraryManager.GetItemById(audio.Id) as Audio.Audio;
@@ -731,10 +634,7 @@ namespace MediaBrowser.Controller.Entities
audio = dbItem;
}
- if (audio != null)
- {
- audio.ExtraType = ExtraType.ThemeSong;
- }
+ audio.ExtraType = ExtraType.ThemeSong;
return audio;
@@ -752,7 +652,9 @@ namespace MediaBrowser.Controller.Entities
.Where(i => string.Equals(i.Name, ThemeVideosFolderName, StringComparison.OrdinalIgnoreCase))
.SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly));
- return LibraryManager.ResolvePaths<Video>(files, directoryService, null).Select(item =>
+ return LibraryManager.ResolvePaths(files, directoryService, null)
+ .OfType<Video>()
+ .Select(item =>
{
// Try to retrieve it from the db. If we don't find it, use the resolved version
var dbItem = LibraryManager.GetItemById(item.Id) as Video;
@@ -762,10 +664,7 @@ namespace MediaBrowser.Controller.Entities
item = dbItem;
}
- if (item != null)
- {
- item.ExtraType = ExtraType.ThemeVideo;
- }
+ item.ExtraType = ExtraType.ThemeVideo;
return item;
@@ -870,7 +769,8 @@ namespace MediaBrowser.Controller.Entities
private async Task<bool> RefreshLocalTrailers(IHasTrailers item, MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
{
- var newItems = LoadLocalTrailers(fileSystemChildren, options.DirectoryService).ToList();
+ var newItems = LibraryManager.FindTrailers(this, fileSystemChildren, options.DirectoryService).ToList();
+
var newItemIds = newItems.Select(i => i.Id).ToList();
var itemsChanged = !item.LocalTrailerIds.SequenceEqual(newItemIds);
@@ -995,6 +895,28 @@ namespace MediaBrowser.Controller.Entities
return Id.ToString();
}
+ internal virtual bool IsValidFromResolver(BaseItem newItem)
+ {
+ var current = this;
+
+ var currentAsPlaceHolder = current as ISupportsPlaceHolders;
+
+ if (currentAsPlaceHolder != null)
+ {
+ var newHasPlaceHolder = newItem as ISupportsPlaceHolders;
+
+ if (newHasPlaceHolder != null)
+ {
+ if (currentAsPlaceHolder.IsPlaceHolder != newHasPlaceHolder.IsPlaceHolder)
+ {
+ return false;
+ }
+ }
+ }
+
+ return current.IsInMixedFolder == newItem.IsInMixedFolder;
+ }
+
/// <summary>
/// Gets the preferred metadata language.
/// </summary>
@@ -1390,7 +1312,7 @@ namespace MediaBrowser.Controller.Entities
/// <param name="resetPosition">if set to <c>true</c> [reset position].</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
- public virtual async Task MarkPlayed(User user,
+ public virtual async Task MarkPlayed(User user,
DateTime? datePlayed,
bool resetPosition)
{
@@ -1820,9 +1742,42 @@ namespace MediaBrowser.Controller.Entities
if (pct > 0)
{
pct = userData.PlaybackPositionTicks / pct;
- dto.PlayedPercentage = 100 * pct;
+
+ if (pct > 0)
+ {
+ dto.PlayedPercentage = 100 * pct;
+ }
}
}
}
+
+ protected Task RefreshMetadataForOwnedVideo(MetadataRefreshOptions options, string path, CancellationToken cancellationToken)
+ {
+ var newOptions = new MetadataRefreshOptions(options.DirectoryService)
+ {
+ ImageRefreshMode = options.ImageRefreshMode,
+ MetadataRefreshMode = options.MetadataRefreshMode,
+ ReplaceAllMetadata = options.ReplaceAllMetadata
+ };
+
+ var id = LibraryManager.GetNewItemId(path, typeof(Video));
+
+ // Try to retrieve it from the db. If we don't find it, use the resolved version
+ var video = LibraryManager.GetItemById(id) as Video;
+
+ if (video == null)
+ {
+ video = LibraryManager.ResolvePath(new FileInfo(path)) as Video;
+
+ newOptions.ForceSave = true;
+ }
+
+ if (video == null)
+ {
+ return Task.FromResult(true);
+ }
+
+ return video.RefreshMetadata(newOptions, cancellationToken);
+ }
}
}