From cd859ac2e6d499ce2cdf531058e64a4c3402910f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 19 Dec 2013 16:51:32 -0500 Subject: added IHasImages and IHasUserData --- MediaBrowser.Controller/Drawing/IImageProcessor.cs | 8 +- .../Drawing/ImageProcessingOptions.cs | 2 +- MediaBrowser.Controller/Entities/BaseItem.cs | 69 +++++++-------- MediaBrowser.Controller/Entities/IHasImages.cs | 97 ++++++++++++++++++++++ MediaBrowser.Controller/Entities/IHasUserData.cs | 15 ++++ MediaBrowser.Controller/Entities/TV/Series.cs | 4 +- .../Library/IUserDataManager.cs | 2 +- .../Library/UserDataSaveEventArgs.cs | 2 +- MediaBrowser.Controller/LiveTv/Channel.cs | 75 ----------------- MediaBrowser.Controller/LiveTv/ChannelInfo.cs | 12 ++- MediaBrowser.Controller/LiveTv/ILiveTvManager.cs | 10 ++- MediaBrowser.Controller/LiveTv/ILiveTvService.cs | 6 +- MediaBrowser.Controller/LiveTv/LiveTvChannel.cs | 57 +++++++++++++ MediaBrowser.Controller/LiveTv/LiveTvProgram.cs | 33 ++++++++ MediaBrowser.Controller/LiveTv/LiveTvRecording.cs | 43 ++++++++++ MediaBrowser.Controller/LiveTv/ProgramInfo.cs | 20 ++++- MediaBrowser.Controller/LiveTv/RecordingInfo.cs | 12 ++- .../MediaBrowser.Controller.csproj | 6 +- MediaBrowser.Controller/MediaInfo/FFMpegManager.cs | 26 ++---- .../MediaInfo/MediaEncoderHelpers.cs | 40 ++++++--- .../Providers/IImageEnhancer.cs | 8 +- 21 files changed, 377 insertions(+), 170 deletions(-) create mode 100644 MediaBrowser.Controller/Entities/IHasImages.cs create mode 100644 MediaBrowser.Controller/Entities/IHasUserData.cs delete mode 100644 MediaBrowser.Controller/LiveTv/Channel.cs create mode 100644 MediaBrowser.Controller/LiveTv/LiveTvChannel.cs create mode 100644 MediaBrowser.Controller/LiveTv/LiveTvProgram.cs create mode 100644 MediaBrowser.Controller/LiveTv/LiveTvRecording.cs (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Drawing/IImageProcessor.cs b/MediaBrowser.Controller/Drawing/IImageProcessor.cs index 1a8583489b..2ecf3ec9ae 100644 --- a/MediaBrowser.Controller/Drawing/IImageProcessor.cs +++ b/MediaBrowser.Controller/Drawing/IImageProcessor.cs @@ -47,7 +47,7 @@ namespace MediaBrowser.Controller.Drawing /// The item. /// Type of the image. /// IEnumerable{IImageEnhancer}. - IEnumerable GetSupportedEnhancers(BaseItem item, ImageType imageType); + IEnumerable GetSupportedEnhancers(IHasImages item, ImageType imageType); /// /// Gets the image cache tag. @@ -56,7 +56,7 @@ namespace MediaBrowser.Controller.Drawing /// Type of the image. /// The image path. /// Guid. - Guid GetImageCacheTag(BaseItem item, ImageType imageType, string imagePath); + Guid GetImageCacheTag(IHasImages item, ImageType imageType, string imagePath); /// /// Gets the image cache tag. @@ -67,7 +67,7 @@ namespace MediaBrowser.Controller.Drawing /// The date modified. /// The image enhancers. /// Guid. - Guid GetImageCacheTag(BaseItem item, ImageType imageType, string originalImagePath, DateTime dateModified, + Guid GetImageCacheTag(IHasImages item, ImageType imageType, string originalImagePath, DateTime dateModified, List imageEnhancers); /// @@ -85,6 +85,6 @@ namespace MediaBrowser.Controller.Drawing /// Type of the image. /// Index of the image. /// Task{System.String}. - Task GetEnhancedImage(BaseItem item, ImageType imageType, int imageIndex); + Task GetEnhancedImage(IHasImages item, ImageType imageType, int imageIndex); } } diff --git a/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs b/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs index ce4bf6c32e..506d6fd3d2 100644 --- a/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs +++ b/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs @@ -9,7 +9,7 @@ namespace MediaBrowser.Controller.Drawing { public class ImageProcessingOptions { - public BaseItem Item { get; set; } + public IHasImages Item { get; set; } public ImageType ImageType { get; set; } diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 541887598d..2aa3e5eccc 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -22,7 +22,7 @@ namespace MediaBrowser.Controller.Entities /// /// Class BaseItem /// - public abstract class BaseItem : IHasProviderIds, ILibraryItem + public abstract class BaseItem : IHasProviderIds, ILibraryItem, IHasImages, IHasUserData { protected BaseItem() { @@ -132,8 +132,8 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public string PrimaryImagePath { - get { return GetImage(ImageType.Primary); } - set { SetImage(ImageType.Primary, value); } + get { return this.GetImagePath(ImageType.Primary); } + set { this.SetImagePath(ImageType.Primary, value); } } /// @@ -1310,31 +1310,10 @@ namespace MediaBrowser.Controller.Entities /// Gets an image /// /// The type. - /// System.String. - /// Backdrops should be accessed using Item.Backdrops - public string GetImage(ImageType type) - { - if (type == ImageType.Backdrop) - { - throw new ArgumentException("Backdrops should be accessed using Item.Backdrops"); - } - if (type == ImageType.Screenshot) - { - throw new ArgumentException("Screenshots should be accessed using Item.Screenshots"); - } - - string val; - Images.TryGetValue(type, out val); - return val; - } - - /// - /// Gets an image - /// - /// The type. + /// Index of the image. /// true if the specified type has image; otherwise, false. /// Backdrops should be accessed using Item.Backdrops - public bool HasImage(ImageType type) + public bool HasImage(ImageType type, int imageIndex) { if (type == ImageType.Backdrop) { @@ -1345,16 +1324,10 @@ namespace MediaBrowser.Controller.Entities throw new ArgumentException("Screenshots should be accessed using Item.Screenshots"); } - return !string.IsNullOrEmpty(GetImage(type)); + return !string.IsNullOrEmpty(this.GetImagePath(type)); } - /// - /// Sets an image - /// - /// The type. - /// The path. - /// Backdrops should be accessed using Item.Backdrops - public void SetImage(ImageType type, string path) + public void SetImagePath(ImageType type, int index, string path) { if (type == ImageType.Backdrop) { @@ -1423,10 +1396,10 @@ namespace MediaBrowser.Controller.Entities else { // Delete the source file - DeleteImagePath(GetImage(type)); + DeleteImagePath(this.GetImagePath(type)); // Remove it from the item - SetImage(type, null); + this.SetImagePath(type, null); } // Refresh metadata @@ -1597,13 +1570,13 @@ namespace MediaBrowser.Controller.Entities { if (imageType == ImageType.Backdrop) { - return BackdropImagePaths[imageIndex]; + return BackdropImagePaths.Count > imageIndex ? BackdropImagePaths[imageIndex] : null; } if (imageType == ImageType.Screenshot) { var hasScreenshots = (IHasScreenshots)this; - return hasScreenshots.ScreenshotImagePaths[imageIndex]; + return hasScreenshots.ScreenshotImagePaths.Count > imageIndex ? hasScreenshots.ScreenshotImagePaths[imageIndex] : null; } if (imageType == ImageType.Chapter) @@ -1611,7 +1584,9 @@ namespace MediaBrowser.Controller.Entities return ItemRepository.GetChapter(Id, imageIndex).ImagePath; } - return GetImage(imageType); + string val; + Images.TryGetValue(imageType, out val); + return val; } /// @@ -1658,5 +1633,21 @@ namespace MediaBrowser.Controller.Entities { return new[] { Path }; } + + public Task SwapImages(ImageType type, int index1, int index2) + { + if (type != ImageType.Screenshot && type != ImageType.Backdrop) + { + throw new ArgumentException("The change index operation is only applicable to backdrops and screenshots"); + } + + var file1 = GetImagePath(type, index1); + var file2 = GetImagePath(type, index2); + + FileSystem.SwapFiles(file1, file2); + + // Directory watchers should repeat this, but do a quick refresh first + return RefreshMetadata(CancellationToken.None, forceSave: true, allowSlowProviders: false); + } } } diff --git a/MediaBrowser.Controller/Entities/IHasImages.cs b/MediaBrowser.Controller/Entities/IHasImages.cs new file mode 100644 index 0000000000..f8cbfc6abc --- /dev/null +++ b/MediaBrowser.Controller/Entities/IHasImages.cs @@ -0,0 +1,97 @@ +using MediaBrowser.Model.Entities; +using System; +using System.Threading.Tasks; + +namespace MediaBrowser.Controller.Entities +{ + public interface IHasImages + { + /// + /// Gets the name. + /// + /// The name. + string Name { get; } + + /// + /// Gets the path. + /// + /// The path. + string Path { get; } + + /// + /// Gets the identifier. + /// + /// The identifier. + Guid Id { get; } + + /// + /// Gets the image path. + /// + /// Type of the image. + /// Index of the image. + /// System.String. + string GetImagePath(ImageType imageType, int imageIndex); + + /// + /// Gets the image date modified. + /// + /// The image path. + /// DateTime. + DateTime GetImageDateModified(string imagePath); + + /// + /// Sets the image. + /// + /// The type. + /// The index. + /// The path. + void SetImagePath(ImageType type, int index, string path); + + /// + /// Determines whether the specified type has image. + /// + /// The type. + /// Index of the image. + /// true if the specified type has image; otherwise, false. + bool HasImage(ImageType type, int imageIndex); + + /// + /// Swaps the images. + /// + /// The type. + /// The index1. + /// The index2. + /// Task. + Task SwapImages(ImageType type, int index1, int index2); + } + + public static class HasImagesExtensions + { + /// + /// Gets the image path. + /// + /// The item. + /// Type of the image. + /// System.String. + public static string GetImagePath(this IHasImages item, ImageType imageType) + { + return item.GetImagePath(imageType, 0); + } + + public static bool HasImage(this IHasImages item, ImageType imageType) + { + return item.HasImage(imageType, 0); + } + + /// + /// Sets the image path. + /// + /// The item. + /// Type of the image. + /// The path. + public static void SetImagePath(this IHasImages item, ImageType imageType, string path) + { + item.SetImagePath(imageType, 0, path); + } + } +} diff --git a/MediaBrowser.Controller/Entities/IHasUserData.cs b/MediaBrowser.Controller/Entities/IHasUserData.cs new file mode 100644 index 0000000000..780181a61d --- /dev/null +++ b/MediaBrowser.Controller/Entities/IHasUserData.cs @@ -0,0 +1,15 @@ + +namespace MediaBrowser.Controller.Entities +{ + /// + /// Interface IHasUserData + /// + public interface IHasUserData + { + /// + /// Gets the user data key. + /// + /// System.String. + string GetUserDataKey(); + } +} diff --git a/MediaBrowser.Controller/Entities/TV/Series.cs b/MediaBrowser.Controller/Entities/TV/Series.cs index 1565de4f8d..71785fa7a7 100644 --- a/MediaBrowser.Controller/Entities/TV/Series.cs +++ b/MediaBrowser.Controller/Entities/TV/Series.cs @@ -183,7 +183,9 @@ namespace MediaBrowser.Controller.Entities.TV episodes = episodes.Where(i => !i.IsVirtualUnaired); } - return LibraryManager.Sort(episodes, user, new[] { ItemSortBy.AiredEpisodeOrder }, SortOrder.Ascending) + var sortBy = seasonNumber == 0 ? ItemSortBy.SortName : ItemSortBy.AiredEpisodeOrder; + + return LibraryManager.Sort(episodes, user, new[] { sortBy }, SortOrder.Ascending) .Cast(); } diff --git a/MediaBrowser.Controller/Library/IUserDataManager.cs b/MediaBrowser.Controller/Library/IUserDataManager.cs index d6d5f99aa0..2bec9e3deb 100644 --- a/MediaBrowser.Controller/Library/IUserDataManager.cs +++ b/MediaBrowser.Controller/Library/IUserDataManager.cs @@ -25,7 +25,7 @@ namespace MediaBrowser.Controller.Library /// The reason. /// The cancellation token. /// Task. - Task SaveUserData(Guid userId, BaseItem item, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken); + Task SaveUserData(Guid userId, IHasUserData item, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken); /// /// Gets the user data. diff --git a/MediaBrowser.Controller/Library/UserDataSaveEventArgs.cs b/MediaBrowser.Controller/Library/UserDataSaveEventArgs.cs index 87e7f647ac..ba328ff754 100644 --- a/MediaBrowser.Controller/Library/UserDataSaveEventArgs.cs +++ b/MediaBrowser.Controller/Library/UserDataSaveEventArgs.cs @@ -37,6 +37,6 @@ namespace MediaBrowser.Controller.Library /// Gets or sets the item. /// /// The item. - public BaseItem Item { get; set; } + public IHasUserData Item { get; set; } } } diff --git a/MediaBrowser.Controller/LiveTv/Channel.cs b/MediaBrowser.Controller/LiveTv/Channel.cs deleted file mode 100644 index 7186cfaf30..0000000000 --- a/MediaBrowser.Controller/LiveTv/Channel.cs +++ /dev/null @@ -1,75 +0,0 @@ -using MediaBrowser.Controller.Entities; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.LiveTv; -using System; -using System.Collections.Generic; -using System.Runtime.Serialization; - -namespace MediaBrowser.Controller.LiveTv -{ - public class Channel : BaseItem, IItemByName - { - public Channel() - { - UserItemCountList = new List(); - } - - /// - /// Gets the user data key. - /// - /// System.String. - public override string GetUserDataKey() - { - return "Channel-" + Name; - } - - [IgnoreDataMember] - public List UserItemCountList { get; set; } - - /// - /// Gets or sets the number. - /// - /// The number. - public string ChannelNumber { get; set; } - - /// - /// Get or sets the Id. - /// - /// The id of the channel. - public string ChannelId { get; set; } - - /// - /// Gets or sets the name of the service. - /// - /// The name of the service. - public string ServiceName { get; set; } - - /// - /// Gets or sets the type of the channel. - /// - /// The type of the channel. - public ChannelType ChannelType { get; set; } - - public bool? HasProviderImage { get; set; } - - protected override string CreateSortName() - { - double number = 0; - - if (!string.IsNullOrEmpty(ChannelNumber)) - { - double.TryParse(ChannelNumber, out number); - } - - return number.ToString("000-") + (Name ?? string.Empty); - } - - public override string MediaType - { - get - { - return ChannelType == ChannelType.Radio ? Model.Entities.MediaType.Audio : Model.Entities.MediaType.Video; - } - } - } -} diff --git a/MediaBrowser.Controller/LiveTv/ChannelInfo.cs b/MediaBrowser.Controller/LiveTv/ChannelInfo.cs index bb06366739..9bc37fcc0b 100644 --- a/MediaBrowser.Controller/LiveTv/ChannelInfo.cs +++ b/MediaBrowser.Controller/LiveTv/ChannelInfo.cs @@ -32,9 +32,15 @@ namespace MediaBrowser.Controller.LiveTv public ChannelType ChannelType { get; set; } /// - /// Set this value to true or false if it is known via channel info whether there is an image or not. - /// Leave it null if the only way to determine is by requesting the image and handling the failure. + /// Supply the image path if it can be accessed directly from the file system /// - public bool? HasImage { get; set; } + /// The image path. + public string ImagePath { get; set; } + + /// + /// Supply the image url if it can be downloaded + /// + /// The image URL. + public string ImageUrl { get; set; } } } diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index 8e711d28c9..e7226e9b5a 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -144,8 +144,16 @@ namespace MediaBrowser.Controller.LiveTv /// /// The identifier. /// Channel. - Channel GetChannel(string id); + LiveTvChannel GetInternalChannel(string id); + /// + /// Gets the recording. + /// + /// The identifier. + /// The cancellation token. + /// LiveTvRecording. + Task GetInternalRecording(string id, CancellationToken cancellationToken); + /// /// Gets the program. /// diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs index 2cd768a937..1c88629f09 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvService.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvService.cs @@ -79,7 +79,7 @@ namespace MediaBrowser.Controller.LiveTv Task UpdateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken); /// - /// Gets the channel image asynchronous. + /// Gets the channel image asynchronous. This only needs to be implemented if an image path or url cannot be supplied to ChannelInfo /// /// The channel identifier. /// The cancellation token. @@ -87,7 +87,7 @@ namespace MediaBrowser.Controller.LiveTv Task GetChannelImageAsync(string channelId, CancellationToken cancellationToken); /// - /// Gets the recording image asynchronous. + /// Gets the recording image asynchronous. This only needs to be implemented if an image path or url cannot be supplied to RecordingInfo /// /// The recording identifier. /// The cancellation token. @@ -95,7 +95,7 @@ namespace MediaBrowser.Controller.LiveTv Task GetRecordingImageAsync(string recordingId, CancellationToken cancellationToken); /// - /// Gets the program image asynchronous. + /// Gets the program image asynchronous. This only needs to be implemented if an image path or url cannot be supplied to ProgramInfo /// /// The program identifier. /// The channel identifier. diff --git a/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs new file mode 100644 index 0000000000..1e6d74ce82 --- /dev/null +++ b/MediaBrowser.Controller/LiveTv/LiveTvChannel.cs @@ -0,0 +1,57 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.LiveTv; +using System.Collections.Generic; +using System.Runtime.Serialization; + +namespace MediaBrowser.Controller.LiveTv +{ + public class LiveTvChannel : BaseItem, IItemByName + { + public LiveTvChannel() + { + UserItemCountList = new List(); + } + + /// + /// Gets the user data key. + /// + /// System.String. + public override string GetUserDataKey() + { + return GetClientTypeName() + "-" + Name; + } + + [IgnoreDataMember] + public List UserItemCountList { get; set; } + + public ChannelInfo ChannelInfo { get; set; } + + public string ServiceName { get; set; } + + protected override string CreateSortName() + { + double number = 0; + + if (!string.IsNullOrEmpty(ChannelInfo.Number)) + { + double.TryParse(ChannelInfo.Number, out number); + } + + return number.ToString("000-") + (Name ?? string.Empty); + } + + public override string MediaType + { + get + { + return ChannelInfo.ChannelType == ChannelType.Radio ? Model.Entities.MediaType.Audio : Model.Entities.MediaType.Video; + } + } + + public override string GetClientTypeName() + { + return "Channel"; + } + } +} diff --git a/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs new file mode 100644 index 0000000000..babd9f54c5 --- /dev/null +++ b/MediaBrowser.Controller/LiveTv/LiveTvProgram.cs @@ -0,0 +1,33 @@ +using MediaBrowser.Controller.Entities; + +namespace MediaBrowser.Controller.LiveTv +{ + public class LiveTvProgram : BaseItem + { + /// + /// Gets the user data key. + /// + /// System.String. + public override string GetUserDataKey() + { + return GetClientTypeName() + "-" + Name; + } + + public ProgramInfo ProgramInfo { get; set; } + + public string ServiceName { get; set; } + + public override string MediaType + { + get + { + return ProgramInfo.IsVideo ? Model.Entities.MediaType.Video : Model.Entities.MediaType.Audio; + } + } + + public override string GetClientTypeName() + { + return "Program"; + } + } +} diff --git a/MediaBrowser.Controller/LiveTv/LiveTvRecording.cs b/MediaBrowser.Controller/LiveTv/LiveTvRecording.cs new file mode 100644 index 0000000000..1c453ab5a1 --- /dev/null +++ b/MediaBrowser.Controller/LiveTv/LiveTvRecording.cs @@ -0,0 +1,43 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.LiveTv; + +namespace MediaBrowser.Controller.LiveTv +{ + public class LiveTvRecording : BaseItem + { + /// + /// Gets the user data key. + /// + /// System.String. + public override string GetUserDataKey() + { + return GetClientTypeName() + "-" + Name; + } + + public RecordingInfo RecordingInfo { get; set; } + + public string ServiceName { get; set; } + + public override string MediaType + { + get + { + return RecordingInfo.ChannelType == ChannelType.Radio ? Model.Entities.MediaType.Audio : Model.Entities.MediaType.Video; + } + } + + public override LocationType LocationType + { + get + { + return LocationType.Remote; + } + } + + public override string GetClientTypeName() + { + return "Recording"; + } + } +} diff --git a/MediaBrowser.Controller/LiveTv/ProgramInfo.cs b/MediaBrowser.Controller/LiveTv/ProgramInfo.cs index 15b55f50eb..959f677403 100644 --- a/MediaBrowser.Controller/LiveTv/ProgramInfo.cs +++ b/MediaBrowser.Controller/LiveTv/ProgramInfo.cs @@ -98,10 +98,16 @@ namespace MediaBrowser.Controller.LiveTv public string EpisodeTitle { get; set; } /// - /// Set this value to true or false if it is known via program info whether there is an image or not. - /// Leave it null if the only way to determine is by requesting the image and handling the failure. + /// Supply the image path if it can be accessed directly from the file system /// - public bool? HasImage { get; set; } + /// The image path. + public string ImagePath { get; set; } + + /// + /// Supply the image url if it can be downloaded + /// + /// The image URL. + public string ImageUrl { get; set; } /// /// Gets or sets a value indicating whether this instance is movie. @@ -120,7 +126,13 @@ namespace MediaBrowser.Controller.LiveTv /// /// true if this instance is series; otherwise, false. public bool IsSeries { get; set; } - + + /// + /// Gets or sets a value indicating whether this instance is video. + /// + /// true if this instance is video; otherwise, false. + public bool IsVideo { get; set; } + public ProgramInfo() { Genres = new List(); diff --git a/MediaBrowser.Controller/LiveTv/RecordingInfo.cs b/MediaBrowser.Controller/LiveTv/RecordingInfo.cs index 40a53e6591..ee3d945942 100644 --- a/MediaBrowser.Controller/LiveTv/RecordingInfo.cs +++ b/MediaBrowser.Controller/LiveTv/RecordingInfo.cs @@ -114,10 +114,16 @@ namespace MediaBrowser.Controller.LiveTv public float? CommunityRating { get; set; } /// - /// Set this value to true or false if it is known via recording info whether there is an image or not. - /// Leave it null if the only way to determine is by requesting the image and handling the failure. + /// Supply the image path if it can be accessed directly from the file system /// - public bool? HasImage { get; set; } + /// The image path. + public string ImagePath { get; set; } + + /// + /// Supply the image url if it can be downloaded + /// + /// The image URL. + public string ImageUrl { get; set; } public RecordingInfo() { diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 705a0ea685..a200f610b5 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -85,6 +85,7 @@ + @@ -94,6 +95,7 @@ + @@ -106,11 +108,13 @@ - + + + diff --git a/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs b/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs index e4f4e8bbb7..ced53299d8 100644 --- a/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs +++ b/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs @@ -170,7 +170,7 @@ namespace MediaBrowser.Controller.MediaInfo InputType type; - var inputPath = MediaEncoderHelpers.GetInputArgument(video, null, out type); + var inputPath = MediaEncoderHelpers.GetInputArgument(video.Path, false, video.VideoType, video.IsoType, null, video.PlayableStreamFileNames, out type); try { @@ -233,33 +233,23 @@ namespace MediaBrowser.Controller.MediaInfo /// /// Gets the subtitle cache path. /// - /// The input. - /// Index of the subtitle stream. + /// The media path. + /// The subtitle stream. /// The offset. /// The output extension. /// System.String. - public string GetSubtitleCachePath(Video input, int subtitleStreamIndex, TimeSpan? offset, string outputExtension) + public string GetSubtitleCachePath(string mediaPath, MediaStream subtitleStream, TimeSpan? offset, string outputExtension) { var ticksParam = offset.HasValue ? "_" + offset.Value.Ticks : ""; - var stream = _itemRepo.GetMediaStreams(new MediaStreamQuery + if (subtitleStream.IsExternal) { - ItemId = input.Id, - Index = subtitleStreamIndex - - }).FirstOrDefault(); - - if (stream == null) - { - return null; + ticksParam += _fileSystem.GetLastWriteTimeUtc(subtitleStream.Path).Ticks; } - if (stream.IsExternal) - { - ticksParam += _fileSystem.GetLastWriteTimeUtc(stream.Path).Ticks; - } + var date = _fileSystem.GetLastWriteTimeUtc(mediaPath); - var filename = (input.Id + "_" + subtitleStreamIndex.ToString(_usCulture) + "_" + input.DateModified.Ticks.ToString(_usCulture) + ticksParam).GetMD5() + outputExtension; + var filename = (mediaPath + "_" + subtitleStream.Index.ToString(_usCulture) + "_" + date.Ticks.ToString(_usCulture) + ticksParam).GetMD5() + outputExtension; var prefix = filename.Substring(0, 1); diff --git a/MediaBrowser.Controller/MediaInfo/MediaEncoderHelpers.cs b/MediaBrowser.Controller/MediaInfo/MediaEncoderHelpers.cs index 8c2f7c219c..904ecdf93f 100644 --- a/MediaBrowser.Controller/MediaInfo/MediaEncoderHelpers.cs +++ b/MediaBrowser.Controller/MediaInfo/MediaEncoderHelpers.cs @@ -1,5 +1,8 @@ -using MediaBrowser.Common.MediaInfo; -using MediaBrowser.Controller.Entities; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using MediaBrowser.Common.MediaInfo; using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; @@ -13,43 +16,47 @@ namespace MediaBrowser.Controller.MediaInfo /// /// Gets the input argument. /// - /// The video. + /// The video path. + /// if set to true [is remote]. + /// Type of the video. + /// Type of the iso. /// The iso mount. + /// The playable stream file names. /// The type. /// System.String[][]. - public static string[] GetInputArgument(Video video, IIsoMount isoMount, out InputType type) + public static string[] GetInputArgument(string videoPath, bool isRemote, VideoType videoType, IsoType? isoType, IIsoMount isoMount, IEnumerable playableStreamFileNames, out InputType type) { - var inputPath = isoMount == null ? new[] { video.Path } : new[] { isoMount.MountedPath }; + var inputPath = isoMount == null ? new[] { videoPath } : new[] { isoMount.MountedPath }; type = InputType.VideoFile; - switch (video.VideoType) + switch (videoType) { case VideoType.BluRay: type = InputType.Bluray; break; case VideoType.Dvd: type = InputType.Dvd; - inputPath = video.GetPlayableStreamFiles(inputPath[0]).ToArray(); + inputPath = GetPlayableStreamFiles(inputPath[0], playableStreamFileNames).ToArray(); break; case VideoType.Iso: - if (video.IsoType.HasValue) + if (isoType.HasValue) { - switch (video.IsoType.Value) + switch (isoType.Value) { case IsoType.BluRay: type = InputType.Bluray; break; case IsoType.Dvd: type = InputType.Dvd; - inputPath = video.GetPlayableStreamFiles(inputPath[0]).ToArray(); + inputPath = GetPlayableStreamFiles(inputPath[0], playableStreamFileNames).ToArray(); break; } } break; case VideoType.VideoFile: { - if (video.LocationType == LocationType.Remote) + if (isRemote) { type = InputType.Url; } @@ -60,6 +67,17 @@ namespace MediaBrowser.Controller.MediaInfo return inputPath; } + public static List GetPlayableStreamFiles(string rootPath, IEnumerable filenames) + { + var allFiles = Directory + .EnumerateFiles(rootPath, "*", SearchOption.AllDirectories) + .ToList(); + + return filenames.Select(name => allFiles.FirstOrDefault(f => string.Equals(Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase))) + .Where(f => !string.IsNullOrEmpty(f)) + .ToList(); + } + /// /// Gets the type of the input. /// diff --git a/MediaBrowser.Controller/Providers/IImageEnhancer.cs b/MediaBrowser.Controller/Providers/IImageEnhancer.cs index 54ba6d3228..ae605ec0d5 100644 --- a/MediaBrowser.Controller/Providers/IImageEnhancer.cs +++ b/MediaBrowser.Controller/Providers/IImageEnhancer.cs @@ -14,7 +14,7 @@ namespace MediaBrowser.Controller.Providers /// The item. /// Type of the image. /// true if this enhancer will enhance the supplied image for the supplied item, false otherwise - bool Supports(BaseItem item, ImageType imageType); + bool Supports(IHasImages item, ImageType imageType); /// /// Gets the priority or order in which this enhancer should be run. @@ -28,7 +28,7 @@ namespace MediaBrowser.Controller.Providers /// The item. /// Type of the image. /// Cache key relating to the current state of this item and configuration - string GetConfigurationCacheKey(BaseItem item, ImageType imageType); + string GetConfigurationCacheKey(IHasImages item, ImageType imageType); /// /// Gets the size of the enhanced image. @@ -38,7 +38,7 @@ namespace MediaBrowser.Controller.Providers /// Index of the image. /// Size of the original image. /// ImageSize. - ImageSize GetEnhancedImageSize(BaseItem item, ImageType imageType, int imageIndex, ImageSize originalImageSize); + ImageSize GetEnhancedImageSize(IHasImages item, ImageType imageType, int imageIndex, ImageSize originalImageSize); /// /// Enhances the image async. @@ -49,6 +49,6 @@ namespace MediaBrowser.Controller.Providers /// Index of the image. /// Task{Image}. /// - Task EnhanceImageAsync(BaseItem item, Image originalImage, ImageType imageType, int imageIndex); + Task EnhanceImageAsync(IHasImages item, Image originalImage, ImageType imageType, int imageIndex); } } \ No newline at end of file -- cgit v1.2.3