From ce0435a66d98be8519a0c6e438674caf3badc076 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 9 Sep 2015 23:22:52 -0400 Subject: add movie resolver fix --- .../Library/Resolvers/Movies/MovieResolver.cs | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers') diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index 0d1e4202ca..d9f23977cf 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -309,20 +309,26 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies //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); - // check for tmdb id - var tmdbid = justName.GetAttributeValue("tmdbid"); - - if (!string.IsNullOrEmpty(tmdbid)) + if (!string.IsNullOrWhiteSpace(justName)) { - item.SetProviderId(MetadataProviders.Tmdb, tmdbid); - } + // check for tmdb id + var tmdbid = justName.GetAttributeValue("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.IsNullOrWhiteSpace(tmdbid)) + { + item.SetProviderId(MetadataProviders.Tmdb, tmdbid); + } + } - if (!string.IsNullOrEmpty(imdbid)) + if (!string.IsNullOrWhiteSpace(item.Path)) { - item.SetProviderId(MetadataProviders.Imdb, imdbid); + // 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.IsNullOrWhiteSpace(imdbid)) + { + item.SetProviderId(MetadataProviders.Imdb, imdbid); + } } } } -- cgit v1.2.3 From 25c37e40ad11006af1127355bd05ae1b16a5f7b6 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Sep 2015 13:28:32 -0400 Subject: update merge --- .../ScheduledTasks/IntervalTrigger.cs | 2 +- MediaBrowser.Model/Dlna/StreamBuilder.cs | 30 +++++++++++----------- MediaBrowser.Model/Net/MimeTypes.cs | 2 +- .../Library/Resolvers/Movies/MovieResolver.cs | 4 +-- 4 files changed, 19 insertions(+), 19 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers') diff --git a/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs b/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs index 42871866df..5858bdc529 100644 --- a/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs +++ b/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs @@ -104,4 +104,4 @@ namespace MediaBrowser.Common.ScheduledTasks } } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 43534efdae..db4f692973 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -157,7 +157,7 @@ namespace MediaBrowser.Model.Dlna if (all) { if (item.Protocol == MediaProtocol.File && - directPlayMethods.Contains(PlayMethod.DirectPlay) && + directPlayMethods.Contains(PlayMethod.DirectPlay) && _localPlayer.CanAccessFile(item.Path)) { playlistItem.PlayMethod = PlayMethod.DirectPlay; @@ -288,7 +288,7 @@ namespace MediaBrowser.Model.Dlna { _logger.Debug("Profile: {0}, No direct play profiles found for Path: {1}", options.Profile.Name ?? "Unknown Profile", - item.Path ?? "Unknown path"); + item.Path ?? "Unknown path"); } return playMethods; @@ -306,7 +306,7 @@ namespace MediaBrowser.Model.Dlna { highestScore = stream.Score.Value; } - } + } } List topStreams = new List(); @@ -540,8 +540,8 @@ namespace MediaBrowser.Model.Dlna { _logger.Debug("Profile: {0}, No direct play profiles found for Path: {1}", profile.Name ?? "Unknown Profile", - mediaSource.Path ?? "Unknown path"); - + mediaSource.Path ?? "Unknown path"); + return null; } @@ -658,7 +658,7 @@ namespace MediaBrowser.Model.Dlna if (!conditionProcessor.IsVideoAudioConditionSatisfied(i, audioChannels, audioBitrate, audioProfile, isSecondaryAudio)) { LogConditionFailure(profile, "VideoAudioCodecProfile", i, mediaSource); - + return null; } } @@ -725,7 +725,7 @@ namespace MediaBrowser.Model.Dlna public static SubtitleProfile GetSubtitleProfile(MediaStream subtitleStream, SubtitleProfile[] subtitleProfiles, EncodingContext context, PlayMethod playMethod) { - if (playMethod != PlayMethod.Transcode && !subtitleStream.IsExternal) + if (playMethod != PlayMethod.Transcode && !subtitleStream.IsExternal) { // Look for supported embedded subs foreach (SubtitleProfile profile in subtitleProfiles) @@ -749,11 +749,11 @@ namespace MediaBrowser.Model.Dlna // Look for an external profile that matches the stream type (text/graphical) foreach (SubtitleProfile profile in subtitleProfiles) - { - if (profile.Method != SubtitleDeliveryMethod.External) - { - continue; - } + { + if (profile.Method != SubtitleDeliveryMethod.External) + { + continue; + } if (!profile.SupportsLanguage(subtitleStream.Language)) { @@ -762,9 +762,9 @@ namespace MediaBrowser.Model.Dlna if (subtitleStream.IsTextSubtitleStream == MediaStream.IsTextFormat(profile.Format)) { - bool requiresConversion = !StringHelper.EqualsIgnoreCase(subtitleStream.Codec, profile.Format); + bool requiresConversion = !StringHelper.EqualsIgnoreCase(subtitleStream.Codec, profile.Format); - if (subtitleStream.IsTextSubtitleStream || !requiresConversion) + if (subtitleStream.IsTextSubtitleStream || !requiresConversion) { if (subtitleStream.SupportsExternalStream) { @@ -1042,4 +1042,4 @@ namespace MediaBrowser.Model.Dlna return true; } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Model/Net/MimeTypes.cs b/MediaBrowser.Model/Net/MimeTypes.cs index e905af58da..419809160b 100644 --- a/MediaBrowser.Model/Net/MimeTypes.cs +++ b/MediaBrowser.Model/Net/MimeTypes.cs @@ -321,4 +321,4 @@ namespace MediaBrowser.Model.Net return null; } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index d9f23977cf..f13d15502d 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -125,7 +125,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies } else if (IsIgnored(child.Name)) { - + } else { @@ -515,4 +515,4 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies return !validCollectionTypes.Contains(collectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase); } } -} +} \ No newline at end of file -- cgit v1.2.3 From d3b8557ab62a0e2f2f52285f792445186f0fe9f1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Sep 2015 13:36:09 -0400 Subject: update merge --- MediaBrowser.Server.Implementations/Devices/DeviceManager.cs | 2 +- MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs | 2 +- .../Library/Resolvers/Movies/MovieResolver.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers') diff --git a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs index 0feacc9751..0173f27847 100644 --- a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs +++ b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs @@ -290,4 +290,4 @@ namespace MediaBrowser.Server.Implementations.Devices return config.GetConfiguration("devices"); } } -} \ No newline at end of file +} diff --git a/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs b/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs index 3da7e20212..63067bf5a5 100644 --- a/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs +++ b/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs @@ -582,4 +582,4 @@ namespace MediaBrowser.Server.Implementations.Library public MediaSourceInfo MediaSource; } } -} \ No newline at end of file +} diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index f13d15502d..ff38e057b0 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -515,4 +515,4 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies return !validCollectionTypes.Contains(collectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase); } } -} \ No newline at end of file +} -- cgit v1.2.3 From 8ad702060ea31a3862598056509a2597f6a2b639 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 3 Oct 2015 23:38:46 -0400 Subject: begin file system rework --- MediaBrowser.Api/Playback/Dash/MpegDashService.cs | 4 +- MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs | 4 +- MediaBrowser.Api/System/SystemService.cs | 4 +- .../IO/CommonFileSystem.cs | 134 ++++++++++++------- MediaBrowser.Common/IO/FileSystemMetadata.cs | 32 +++++ MediaBrowser.Common/IO/IFileSystem.cs | 145 ++++++++++++++++++--- MediaBrowser.Common/MediaBrowser.Common.csproj | 1 + .../Entities/AggregateFolder.cs | 7 +- MediaBrowser.Controller/Entities/BaseItem.cs | 37 +++--- .../Entities/CollectionFolder.cs | 7 +- MediaBrowser.Controller/Entities/Folder.cs | 5 +- MediaBrowser.Controller/Entities/IHasImages.cs | 9 +- MediaBrowser.Controller/Entities/Movies/Movie.cs | 5 +- MediaBrowser.Controller/Entities/Video.cs | 3 +- MediaBrowser.Controller/IO/FileData.cs | 6 +- MediaBrowser.Controller/Library/ILibraryManager.cs | 19 ++- MediaBrowser.Controller/Library/ItemResolveArgs.cs | 15 ++- .../Providers/DirectoryService.cs | 28 ++-- .../Providers/IDirectoryService.cs | 13 +- .../Providers/LocalImageInfo.cs | 3 +- MediaBrowser.Controller/Resolvers/IItemResolver.cs | 9 +- MediaBrowser.LocalMetadata/BaseXmlProvider.cs | 2 +- .../Images/EpisodeLocalImageProvider.cs | 4 +- .../Images/LocalImageProvider.cs | 26 ++-- .../Parsers/EpisodeXmlParser.cs | 7 +- .../Providers/BoxSetXmlProvider.cs | 2 +- .../Providers/EpisodeXmlProvider.cs | 4 +- .../Providers/FolderXmlProvider.cs | 4 +- .../Providers/GameSystemXmlProvider.cs | 2 +- .../Providers/GameXmlProvider.cs | 6 +- .../Providers/MovieXmlProvider.cs | 15 +-- .../Providers/MusicVideoXmlProvider.cs | 2 +- .../Providers/PersonXmlProvider.cs | 2 +- .../Providers/PlaylistXmlProvider.cs | 2 +- .../Providers/SeasonXmlProvider.cs | 2 +- .../Providers/SeriesXmlProvider.cs | 2 +- .../Providers/VideoXmlProvider.cs | 2 +- MediaBrowser.Model/Devices/DeviceInfo.cs | 5 +- MediaBrowser.Providers/ImagesByName/ImageUtils.cs | 2 +- MediaBrowser.Providers/Manager/ImageSaver.cs | 2 +- .../MediaInfo/SubtitleResolver.cs | 2 +- .../Movies/FanArtMovieUpdatesPostScanTask.cs | 2 +- .../Movies/FanartMovieImageProvider.cs | 2 +- MediaBrowser.Providers/Movies/MovieDbProvider.cs | 2 +- .../Movies/MovieUpdatesPrescanTask.cs | 2 +- .../Music/FanArtAlbumProvider.cs | 2 +- .../Music/FanArtArtistProvider.cs | 2 +- .../Music/FanArtUpdatesPostScanTask.cs | 2 +- MediaBrowser.Providers/TV/FanArtSeasonProvider.cs | 2 +- .../TV/FanArtTvUpdatesPostScanTask.cs | 2 +- MediaBrowser.Providers/TV/FanartSeriesProvider.cs | 2 +- MediaBrowser.Providers/TV/MovieDbSeriesProvider.cs | 2 +- .../TV/TvdbEpisodeImageProvider.cs | 2 +- MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs | 10 +- MediaBrowser.Providers/TV/TvdbPrescanTask.cs | 2 +- .../TV/TvdbSeasonImageProvider.cs | 2 +- .../TV/TvdbSeriesImageProvider.cs | 2 +- .../Channels/ChannelManager.cs | 11 +- .../Dto/DtoService.cs | 2 +- .../FileOrganization/TvFolderOrganizer.cs | 17 ++- .../IO/LibraryMonitor.cs | 5 +- .../Library/LibraryManager.cs | 66 +++++++--- .../Library/ResolverHelper.cs | 4 +- .../Library/Resolvers/Audio/MusicAlbumResolver.cs | 2 +- .../Library/Resolvers/Movies/MovieResolver.cs | 19 +-- .../Library/Resolvers/TV/SeriesResolver.cs | 2 +- .../LiveTv/LiveTvManager.cs | 2 +- .../Sync/SyncJobProcessor.cs | 2 +- .../ApplicationHost.cs | 2 +- .../Providers/AlbumNfoProvider.cs | 2 +- .../Providers/ArtistNfoProvider.cs | 2 +- .../Providers/BaseNfoProvider.cs | 2 +- .../Providers/BaseVideoNfoProvider.cs | 2 +- .../Providers/EpisodeNfoProvider.cs | 2 +- .../Providers/SeasonNfoProvider.cs | 2 +- .../Providers/SeriesNfoProvider.cs | 2 +- MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs | 14 +- 77 files changed, 505 insertions(+), 282 deletions(-) create mode 100644 MediaBrowser.Common/IO/FileSystemMetadata.cs (limited to 'MediaBrowser.Server.Implementations/Library/Resolvers') diff --git a/MediaBrowser.Api/Playback/Dash/MpegDashService.cs b/MediaBrowser.Api/Playback/Dash/MpegDashService.cs index cbee821d2d..5a36b0aa25 100644 --- a/MediaBrowser.Api/Playback/Dash/MpegDashService.cs +++ b/MediaBrowser.Api/Playback/Dash/MpegDashService.cs @@ -322,7 +322,7 @@ namespace MediaBrowser.Api.Playback.Dash } } - private static List GetLastTranscodingFiles(string playlist, string segmentExtension, IFileSystem fileSystem, int count) + private static List GetLastTranscodingFiles(string playlist, string segmentExtension, IFileSystem fileSystem, int count) { var folder = Path.GetDirectoryName(playlist); @@ -336,7 +336,7 @@ namespace MediaBrowser.Api.Playback.Dash } catch (DirectoryNotFoundException) { - return new List(); + return new List(); } } diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index cb49e65c7e..39bdee6991 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -354,7 +354,7 @@ namespace MediaBrowser.Api.Playback.Hls } } - private void DeleteFile(FileInfo file, int retryCount) + private void DeleteFile(FileSystemMetadata file, int retryCount) { if (retryCount >= 5) { @@ -378,7 +378,7 @@ namespace MediaBrowser.Api.Playback.Hls } } - private static FileInfo GetLastTranscodingFile(string playlist, string segmentExtension, IFileSystem fileSystem) + private static FileSystemMetadata GetLastTranscodingFile(string playlist, string segmentExtension, IFileSystem fileSystem) { var folder = Path.GetDirectoryName(playlist); diff --git a/MediaBrowser.Api/System/SystemService.cs b/MediaBrowser.Api/System/SystemService.cs index 00935dd1e1..4ad8b3903a 100644 --- a/MediaBrowser.Api/System/SystemService.cs +++ b/MediaBrowser.Api/System/SystemService.cs @@ -118,7 +118,7 @@ namespace MediaBrowser.Api.System public object Get(GetServerLogs request) { - List files; + List files; try { @@ -128,7 +128,7 @@ namespace MediaBrowser.Api.System } catch (DirectoryNotFoundException) { - files = new List(); + files = new List(); } var result = files.Select(i => new LogFile diff --git a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs index b899e88c23..f13b9b1a94 100644 --- a/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs +++ b/MediaBrowser.Common.Implementations/IO/CommonFileSystem.cs @@ -27,7 +27,7 @@ namespace MediaBrowser.Common.Implementations.IO SetInvalidFileNameChars(usePresetInvalidFileNameChars); } - private void SetInvalidFileNameChars(bool usePresetInvalidFileNameChars) + protected void SetInvalidFileNameChars(bool usePresetInvalidFileNameChars) { // GetInvalidFileNameChars is less restrictive in Linux/Mac than Windows, this mimic Windows behavior for mono under Linux/Mac. @@ -115,7 +115,7 @@ namespace MediaBrowser.Common.Implementations.IO /// /// The path. /// FileSystemInfo. - public FileSystemInfo GetFileSystemInfo(string path) + public FileSystemMetadata GetFileSystemInfo(string path) { if (string.IsNullOrEmpty(path)) { @@ -129,10 +129,10 @@ namespace MediaBrowser.Common.Implementations.IO if (fileInfo.Exists) { - return fileInfo; + return GetFileSystemMetadata(fileInfo); } - return new DirectoryInfo(path); + return GetFileSystemMetadata(new DirectoryInfo(path)); } else { @@ -140,13 +140,63 @@ namespace MediaBrowser.Common.Implementations.IO if (fileInfo.Exists) { - return fileInfo; + return GetFileSystemMetadata(fileInfo); } - return new FileInfo(path); + return GetFileSystemMetadata(new FileInfo(path)); } } + public FileSystemMetadata GetFileInfo(string path) + { + if (string.IsNullOrEmpty(path)) + { + throw new ArgumentNullException("path"); + } + + var fileInfo = new FileInfo(path); + + return GetFileSystemMetadata(fileInfo); + } + + public FileSystemMetadata GetDirectoryInfo(string path) + { + if (string.IsNullOrEmpty(path)) + { + throw new ArgumentNullException("path"); + } + + var fileInfo = new DirectoryInfo(path); + + return GetFileSystemMetadata(fileInfo); + } + + private FileSystemMetadata GetFileSystemMetadata(FileSystemInfo info) + { + var result = new FileSystemMetadata(); + + result.Attributes = info.Attributes; + result.Exists = info.Exists; + result.FullName = info.FullName; + result.Extension = info.Extension; + result.Name = info.Name; + + if (result.Exists) + { + var fileInfo = info as FileInfo; + if (fileInfo != null) + { + result.Length = fileInfo.Length; + result.DirectoryName = fileInfo.DirectoryName; + } + + result.CreationTimeUtc = GetCreationTimeUtc(info); + result.LastWriteTimeUtc = GetLastWriteTimeUtc(info); + } + + return result; + } + /// /// The space char /// @@ -194,6 +244,26 @@ namespace MediaBrowser.Common.Implementations.IO } } + /// + /// Gets the creation time UTC. + /// + /// The path. + /// DateTime. + public DateTime GetCreationTimeUtc(string path) + { + return GetCreationTimeUtc(GetFileSystemInfo(path)); + } + + public DateTime GetCreationTimeUtc(FileSystemMetadata info) + { + return info.CreationTimeUtc; + } + + public DateTime GetLastWriteTimeUtc(FileSystemMetadata info) + { + return info.LastWriteTimeUtc; + } + /// /// Gets the creation time UTC. /// @@ -346,41 +416,9 @@ namespace MediaBrowser.Common.Implementations.IO return path.TrimEnd(Path.DirectorySeparatorChar); } - public string SubstitutePath(string path, string from, string to) + public string GetFileNameWithoutExtension(FileSystemMetadata info) { - if (string.IsNullOrWhiteSpace(path)) - { - throw new ArgumentNullException("path"); - } - if (string.IsNullOrWhiteSpace(from)) - { - throw new ArgumentNullException("from"); - } - if (string.IsNullOrWhiteSpace(to)) - { - throw new ArgumentNullException("to"); - } - - var newPath = path.Replace(from, to, StringComparison.OrdinalIgnoreCase); - - if (!string.Equals(newPath, path)) - { - if (to.IndexOf('/') != -1) - { - newPath = newPath.Replace('\\', '/'); - } - else - { - newPath = newPath.Replace('/', '\\'); - } - } - - return newPath; - } - - public string GetFileNameWithoutExtension(FileSystemInfo info) - { - if (info is DirectoryInfo) + if (info.IsDirectory) { return info.Name; } @@ -426,28 +464,28 @@ namespace MediaBrowser.Common.Implementations.IO { Directory.CreateDirectory(path); } - - public IEnumerable GetDirectories(string path, bool recursive = false) + + public IEnumerable GetDirectories(string path, bool recursive = false) { var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - return new DirectoryInfo (path).EnumerateDirectories("*", searchOption); + return new DirectoryInfo(path).EnumerateDirectories("*", searchOption).Select(GetFileSystemMetadata); } - public IEnumerable GetFiles(string path, bool recursive = false) + public IEnumerable GetFiles(string path, bool recursive = false) { var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - return new DirectoryInfo (path).EnumerateFiles("*", searchOption); + return new DirectoryInfo (path).EnumerateFiles("*", searchOption).Select(GetFileSystemMetadata); } - public IEnumerable GetFileSystemEntries(string path, bool recursive = false) + public IEnumerable GetFileSystemEntries(string path, bool recursive = false) { var directoryInfo = new DirectoryInfo (path); var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - return directoryInfo.EnumerateDirectories("*", searchOption) - .Concat(directoryInfo.EnumerateFiles("*", searchOption)); + return directoryInfo.EnumerateDirectories("*", searchOption).Select(GetFileSystemMetadata) + .Concat(directoryInfo.EnumerateFiles("*", searchOption).Select(GetFileSystemMetadata)); } public Stream OpenRead(string path) diff --git a/MediaBrowser.Common/IO/FileSystemMetadata.cs b/MediaBrowser.Common/IO/FileSystemMetadata.cs new file mode 100644 index 0000000000..ba8a1b8b87 --- /dev/null +++ b/MediaBrowser.Common/IO/FileSystemMetadata.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MediaBrowser.Common.IO +{ + public class FileSystemMetadata + { + public FileAttributes Attributes { get; set; } + + public bool Exists { get; set; } + public string FullName { get; set; } + public string Name { get; set; } + public string Extension { get; set; } + public long Length { get; set; } + public string DirectoryName { get; set; } + + public DateTime LastWriteTimeUtc { get; set; } + public DateTime CreationTimeUtc { get; set; } + + public bool IsDirectory + { + get + { + return (Attributes & FileAttributes.Directory) == FileAttributes.Directory; + } + } + } +} diff --git a/MediaBrowser.Common/IO/IFileSystem.cs b/MediaBrowser.Common/IO/IFileSystem.cs index ce15ad999c..e084f94ed2 100644 --- a/MediaBrowser.Common/IO/IFileSystem.cs +++ b/MediaBrowser.Common/IO/IFileSystem.cs @@ -36,8 +36,22 @@ namespace MediaBrowser.Common.IO /// /// The path. /// FileSystemInfo. - FileSystemInfo GetFileSystemInfo(string path); + FileSystemMetadata GetFileSystemInfo(string path); + /// + /// Gets the file information. + /// + /// The path. + /// FileSystemMetadata. + FileSystemMetadata GetFileInfo(string path); + + /// + /// Gets the directory information. + /// + /// The path. + /// FileSystemMetadata. + FileSystemMetadata GetDirectoryInfo(string path); + /// /// Gets the valid filename. /// @@ -48,17 +62,24 @@ namespace MediaBrowser.Common.IO /// /// Gets the creation time UTC. /// - /// The info. + /// The information. + /// DateTime. + DateTime GetCreationTimeUtc(FileSystemMetadata info); + + /// + /// Gets the creation time UTC. + /// + /// The path. /// DateTime. - DateTime GetCreationTimeUtc(FileSystemInfo info); + DateTime GetCreationTimeUtc(string path); /// /// Gets the last write time UTC. /// /// The information. /// DateTime. - DateTime GetLastWriteTimeUtc(FileSystemInfo info); - + DateTime GetLastWriteTimeUtc(FileSystemMetadata info); + /// /// Gets the last write time UTC. /// @@ -77,6 +98,11 @@ namespace MediaBrowser.Common.IO /// FileStream. Stream GetFileStream(string path, FileMode mode, FileAccess access, FileShare share, bool isAsync = false); + /// + /// Opens the read. + /// + /// The path. + /// Stream. Stream OpenRead(String path); /// @@ -108,21 +134,12 @@ namespace MediaBrowser.Common.IO /// System.String. string NormalizePath(string path); - /// - /// Substitutes the path. - /// - /// The path. - /// From. - /// To. - /// System.String. - string SubstitutePath(string path, string from, string to); - /// /// Gets the file name without extension. /// /// The information. /// System.String. - string GetFileNameWithoutExtension(FileSystemInfo info); + string GetFileNameWithoutExtension(FileSystemMetadata info); /// /// Gets the file name without extension. @@ -150,37 +167,125 @@ namespace MediaBrowser.Common.IO /// The path. /// if set to true [recursive]. void DeleteDirectory(string path, bool recursive); - - IEnumerable GetDirectories(string path, bool recursive = false); - IEnumerable GetFiles(string path, bool recursive = false); + /// + /// Gets the directories. + /// + /// The path. + /// if set to true [recursive]. + /// IEnumerable<DirectoryInfo>. + IEnumerable GetDirectories(string path, bool recursive = false); - IEnumerable GetFileSystemEntries(string path, bool recursive = false); + /// + /// Gets the files. + /// + /// The path. + /// if set to true [recursive]. + /// IEnumerable<FileInfo>. + IEnumerable GetFiles(string path, bool recursive = false); + + /// + /// Gets the file system entries. + /// + /// The path. + /// if set to true [recursive]. + /// IEnumerable<FileSystemMetadata>. + IEnumerable GetFileSystemEntries(string path, bool recursive = false); + /// + /// Creates the directory. + /// + /// The path. void CreateDirectory(string path); + /// + /// Copies the file. + /// + /// The source. + /// The target. + /// if set to true [overwrite]. void CopyFile(string source, string target, bool overwrite); + /// + /// Moves the file. + /// + /// The source. + /// The target. void MoveFile(string source, string target); + /// + /// Moves the directory. + /// + /// The source. + /// The target. void MoveDirectory(string source, string target); + /// + /// Directories the exists. + /// + /// The path. + /// true if XXXX, false otherwise. bool DirectoryExists(string path); + /// + /// Files the exists. + /// + /// The path. + /// true if XXXX, false otherwise. bool FileExists(string path); + /// + /// Reads all text. + /// + /// The path. + /// System.String. string ReadAllText(string path); + /// + /// Writes all text. + /// + /// The path. + /// The text. void WriteAllText(string path, string text); - + + /// + /// Writes all text. + /// + /// The path. + /// The text. + /// The encoding. void WriteAllText(string path, string text, Encoding encoding); + /// + /// Reads all text. + /// + /// The path. + /// The encoding. + /// System.String. string ReadAllText(string path, Encoding encoding); + /// + /// Gets the directory paths. + /// + /// The path. + /// if set to true [recursive]. + /// IEnumerable<System.String>. IEnumerable GetDirectoryPaths(string path, bool recursive = false); + /// + /// Gets the file paths. + /// + /// The path. + /// if set to true [recursive]. + /// IEnumerable<System.String>. IEnumerable GetFilePaths(string path, bool recursive = false); + /// + /// Gets the file system entry paths. + /// + /// The path. + /// if set to true [recursive]. + /// IEnumerable<System.String>. IEnumerable GetFileSystemEntryPaths(string path, bool recursive = false); } } diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index ad0c0cecdb..0476f3f602 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -60,6 +60,7 @@ + diff --git a/MediaBrowser.Controller/Entities/AggregateFolder.cs b/MediaBrowser.Controller/Entities/AggregateFolder.cs index 66a0d551b2..5af02e9bb6 100644 --- a/MediaBrowser.Controller/Entities/AggregateFolder.cs +++ b/MediaBrowser.Controller/Entities/AggregateFolder.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization; +using MediaBrowser.Common.IO; using MediaBrowser.Controller.Providers; namespace MediaBrowser.Controller.Entities @@ -62,7 +63,7 @@ namespace MediaBrowser.Controller.Entities public List PhysicalLocationsList { get; set; } - protected override IEnumerable GetFileSystemChildren(IDirectoryService directoryService) + protected override IEnumerable GetFileSystemChildren(IDirectoryService directoryService) { return CreateResolveArgs(directoryService).FileSystemChildren; } @@ -73,7 +74,7 @@ namespace MediaBrowser.Controller.Entities var args = new ItemResolveArgs(ConfigurationManager.ApplicationPaths , directoryService) { - FileInfo = new DirectoryInfo(path), + FileInfo = FileSystem.GetDirectoryInfo(path), Path = path, Parent = Parent }; @@ -94,7 +95,7 @@ namespace MediaBrowser.Controller.Entities { var paths = LibraryManager.NormalizeRootPathList(fileSystemDictionary.Keys); - fileSystemDictionary = paths.Select(i => (FileSystemInfo)new DirectoryInfo(i)).ToDictionary(i => i.FullName); + fileSystemDictionary = paths.Select(FileSystem.GetDirectoryInfo).ToDictionary(i => i.FullName); } args.FileSystemDictionary = fileSystemDictionary; diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 5403c16ddf..963f4725ad 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -676,7 +676,7 @@ namespace MediaBrowser.Controller.Entities /// Loads the theme songs. /// /// List{Audio.Audio}. - private IEnumerable LoadThemeSongs(List fileSystemChildren, IDirectoryService directoryService) + private IEnumerable LoadThemeSongs(List fileSystemChildren, IDirectoryService directoryService) { var files = fileSystemChildren.OfType() .Where(i => string.Equals(i.Name, ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase)) @@ -684,8 +684,8 @@ namespace MediaBrowser.Controller.Entities .ToList(); // Support plex/xbmc convention - files.AddRange(fileSystemChildren.OfType() - .Where(i => string.Equals(FileSystem.GetFileNameWithoutExtension(i), ThemeSongFilename, StringComparison.OrdinalIgnoreCase)) + files.AddRange(fileSystemChildren + .Where(i => !i.IsDirectory && string.Equals(FileSystem.GetFileNameWithoutExtension(i), ThemeSongFilename, StringComparison.OrdinalIgnoreCase)) ); return LibraryManager.ResolvePaths(files, directoryService, null) @@ -712,7 +712,7 @@ namespace MediaBrowser.Controller.Entities /// Loads the video backdrops. /// /// List{Video}. - private IEnumerable