Merge pull request #2830 from Bond-009/dvdlib

DvdLib: remove dependency on MediaBrowser.Model
This commit is contained in:
Vasily 2020-04-16 00:53:25 +03:00 committed by GitHub
commit e1fb24c9ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 56 deletions

View File

@ -1,4 +1,4 @@
using System; using System.Buffers.Binary;
using System.IO; using System.IO;
namespace DvdLib namespace DvdLib
@ -12,19 +12,12 @@ namespace DvdLib
public override ushort ReadUInt16() public override ushort ReadUInt16()
{ {
return BitConverter.ToUInt16(ReadAndReverseBytes(2), 0); return BinaryPrimitives.ReadUInt16BigEndian(base.ReadBytes(2));
} }
public override uint ReadUInt32() public override uint ReadUInt32()
{ {
return BitConverter.ToUInt32(ReadAndReverseBytes(4), 0); return BinaryPrimitives.ReadUInt32BigEndian(base.ReadBytes(4));
}
private byte[] ReadAndReverseBytes(int count)
{
byte[] val = base.ReadBytes(count);
Array.Reverse(val, 0, count);
return val;
} }
} }
} }

View File

@ -4,10 +4,6 @@
<Compile Include="..\SharedVersion.cs" /> <Compile Include="..\SharedVersion.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
</ItemGroup>
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> <GenerateAssemblyInfo>false</GenerateAssemblyInfo>

View File

@ -2,7 +2,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using MediaBrowser.Model.IO;
namespace DvdLib.Ifo namespace DvdLib.Ifo
{ {
@ -13,13 +12,10 @@ namespace DvdLib.Ifo
private ushort _titleCount; private ushort _titleCount;
public readonly Dictionary<ushort, string> VTSPaths = new Dictionary<ushort, string>(); public readonly Dictionary<ushort, string> VTSPaths = new Dictionary<ushort, string>();
private readonly IFileSystem _fileSystem; public Dvd(string path)
public Dvd(string path, IFileSystem fileSystem)
{ {
_fileSystem = fileSystem;
Titles = new List<Title>(); Titles = new List<Title>();
var allFiles = _fileSystem.GetFiles(path, true).ToList(); var allFiles = new DirectoryInfo(path).GetFiles(path, SearchOption.AllDirectories);
var vmgPath = allFiles.FirstOrDefault(i => string.Equals(i.Name, "VIDEO_TS.IFO", StringComparison.OrdinalIgnoreCase)) ?? var vmgPath = allFiles.FirstOrDefault(i => string.Equals(i.Name, "VIDEO_TS.IFO", StringComparison.OrdinalIgnoreCase)) ??
allFiles.FirstOrDefault(i => string.Equals(i.Name, "VIDEO_TS.BUP", StringComparison.OrdinalIgnoreCase)); allFiles.FirstOrDefault(i => string.Equals(i.Name, "VIDEO_TS.BUP", StringComparison.OrdinalIgnoreCase));
@ -76,7 +72,7 @@ namespace DvdLib.Ifo
} }
} }
private void ReadVTS(ushort vtsNum, IEnumerable<FileSystemMetadata> allFiles) private void ReadVTS(ushort vtsNum, IReadOnlyList<FileInfo> allFiles)
{ {
var filename = string.Format("VTS_{0:00}_0.IFO", vtsNum); var filename = string.Format("VTS_{0:00}_0.IFO", vtsNum);

View File

@ -2364,7 +2364,7 @@ namespace Emby.Server.Implementations.Library
string videoPath, string videoPath,
string[] files) string[] files)
{ {
new SubtitleResolver(BaseItem.LocalizationManager, _fileSystem).AddExternalSubtitleStreams(streams, videoPath, streams.Count, files); new SubtitleResolver(BaseItem.LocalizationManager).AddExternalSubtitleStreams(streams, videoPath, streams.Count, files);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -46,7 +46,6 @@ namespace MediaBrowser.Providers.MediaInfo
private readonly IApplicationPaths _appPaths; private readonly IApplicationPaths _appPaths;
private readonly IJsonSerializer _json; private readonly IJsonSerializer _json;
private readonly IEncodingManager _encodingManager; private readonly IEncodingManager _encodingManager;
private readonly IFileSystem _fileSystem;
private readonly IServerConfigurationManager _config; private readonly IServerConfigurationManager _config;
private readonly ISubtitleManager _subtitleManager; private readonly ISubtitleManager _subtitleManager;
private readonly IChapterManager _chapterManager; private readonly IChapterManager _chapterManager;
@ -134,7 +133,6 @@ namespace MediaBrowser.Providers.MediaInfo
IApplicationPaths appPaths, IApplicationPaths appPaths,
IJsonSerializer json, IJsonSerializer json,
IEncodingManager encodingManager, IEncodingManager encodingManager,
IFileSystem fileSystem,
IServerConfigurationManager config, IServerConfigurationManager config,
ISubtitleManager subtitleManager, ISubtitleManager subtitleManager,
IChapterManager chapterManager, IChapterManager chapterManager,
@ -149,7 +147,6 @@ namespace MediaBrowser.Providers.MediaInfo
_appPaths = appPaths; _appPaths = appPaths;
_json = json; _json = json;
_encodingManager = encodingManager; _encodingManager = encodingManager;
_fileSystem = fileSystem;
_config = config; _config = config;
_subtitleManager = subtitleManager; _subtitleManager = subtitleManager;
_chapterManager = chapterManager; _chapterManager = chapterManager;
@ -157,7 +154,7 @@ namespace MediaBrowser.Providers.MediaInfo
_channelManager = channelManager; _channelManager = channelManager;
_mediaSourceManager = mediaSourceManager; _mediaSourceManager = mediaSourceManager;
_subtitleResolver = new SubtitleResolver(BaseItem.LocalizationManager, fileSystem); _subtitleResolver = new SubtitleResolver(BaseItem.LocalizationManager);
} }
private readonly Task<ItemUpdateType> _cachedTask = Task.FromResult(ItemUpdateType.None); private readonly Task<ItemUpdateType> _cachedTask = Task.FromResult(ItemUpdateType.None);
@ -202,7 +199,6 @@ namespace MediaBrowser.Providers.MediaInfo
_blurayExaminer, _blurayExaminer,
_localization, _localization,
_encodingManager, _encodingManager,
_fileSystem,
_config, _config,
_subtitleManager, _subtitleManager,
_chapterManager, _chapterManager,

View File

@ -39,7 +39,6 @@ namespace MediaBrowser.Providers.MediaInfo
private readonly IBlurayExaminer _blurayExaminer; private readonly IBlurayExaminer _blurayExaminer;
private readonly ILocalizationManager _localization; private readonly ILocalizationManager _localization;
private readonly IEncodingManager _encodingManager; private readonly IEncodingManager _encodingManager;
private readonly IFileSystem _fileSystem;
private readonly IServerConfigurationManager _config; private readonly IServerConfigurationManager _config;
private readonly ISubtitleManager _subtitleManager; private readonly ISubtitleManager _subtitleManager;
private readonly IChapterManager _chapterManager; private readonly IChapterManager _chapterManager;
@ -56,7 +55,6 @@ namespace MediaBrowser.Providers.MediaInfo
IBlurayExaminer blurayExaminer, IBlurayExaminer blurayExaminer,
ILocalizationManager localization, ILocalizationManager localization,
IEncodingManager encodingManager, IEncodingManager encodingManager,
IFileSystem fileSystem,
IServerConfigurationManager config, IServerConfigurationManager config,
ISubtitleManager subtitleManager, ISubtitleManager subtitleManager,
IChapterManager chapterManager, IChapterManager chapterManager,
@ -68,7 +66,6 @@ namespace MediaBrowser.Providers.MediaInfo
_blurayExaminer = blurayExaminer; _blurayExaminer = blurayExaminer;
_localization = localization; _localization = localization;
_encodingManager = encodingManager; _encodingManager = encodingManager;
_fileSystem = fileSystem;
_config = config; _config = config;
_subtitleManager = subtitleManager; _subtitleManager = subtitleManager;
_chapterManager = chapterManager; _chapterManager = chapterManager;
@ -76,7 +73,8 @@ namespace MediaBrowser.Providers.MediaInfo
_mediaSourceManager = mediaSourceManager; _mediaSourceManager = mediaSourceManager;
} }
public async Task<ItemUpdateType> ProbeVideo<T>(T item, public async Task<ItemUpdateType> ProbeVideo<T>(
T item,
MetadataRefreshOptions options, MetadataRefreshOptions options,
CancellationToken cancellationToken) CancellationToken cancellationToken)
where T : Video where T : Video
@ -99,7 +97,6 @@ namespace MediaBrowser.Providers.MediaInfo
return ItemUpdateType.MetadataImport; return ItemUpdateType.MetadataImport;
} }
} }
else if (item.VideoType == VideoType.BluRay) else if (item.VideoType == VideoType.BluRay)
{ {
var inputPath = item.Path; var inputPath = item.Path;
@ -130,7 +127,8 @@ namespace MediaBrowser.Providers.MediaInfo
return ItemUpdateType.MetadataImport; return ItemUpdateType.MetadataImport;
} }
private Task<Model.MediaInfo.MediaInfo> GetMediaInfo(Video item, private Task<Model.MediaInfo.MediaInfo> GetMediaInfo(
Video item,
string[] streamFileNames, string[] streamFileNames,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
@ -145,22 +143,24 @@ namespace MediaBrowser.Providers.MediaInfo
protocol = _mediaSourceManager.GetPathProtocol(path); protocol = _mediaSourceManager.GetPathProtocol(path);
} }
return _mediaEncoder.GetMediaInfo(new MediaInfoRequest return _mediaEncoder.GetMediaInfo(
{ new MediaInfoRequest
PlayableStreamFileNames = streamFileNames,
ExtractChapters = true,
MediaType = DlnaProfileType.Video,
MediaSource = new MediaSourceInfo
{ {
Path = path, PlayableStreamFileNames = streamFileNames,
Protocol = protocol, ExtractChapters = true,
VideoType = item.VideoType MediaType = DlnaProfileType.Video,
} MediaSource = new MediaSourceInfo
{
}, cancellationToken); Path = path,
Protocol = protocol,
VideoType = item.VideoType
}
},
cancellationToken);
} }
protected async Task Fetch(Video video, protected async Task Fetch(
Video video,
CancellationToken cancellationToken, CancellationToken cancellationToken,
Model.MediaInfo.MediaInfo mediaInfo, Model.MediaInfo.MediaInfo mediaInfo,
BlurayDiscInfo blurayInfo, BlurayDiscInfo blurayInfo,
@ -491,12 +491,13 @@ namespace MediaBrowser.Providers.MediaInfo
/// <param name="options">The refreshOptions.</param> /// <param name="options">The refreshOptions.</param>
/// <param name="cancellationToken">The cancellation token.</param> /// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
private async Task AddExternalSubtitles(Video video, private async Task AddExternalSubtitles(
Video video,
List<MediaStream> currentStreams, List<MediaStream> currentStreams,
MetadataRefreshOptions options, MetadataRefreshOptions options,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var subtitleResolver = new SubtitleResolver(_localization, _fileSystem); var subtitleResolver = new SubtitleResolver(_localization);
var startIndex = currentStreams.Count == 0 ? 0 : (currentStreams.Select(i => i.Index).Max() + 1); var startIndex = currentStreams.Count == 0 ? 0 : (currentStreams.Select(i => i.Index).Max() + 1);
var externalSubtitleStreams = subtitleResolver.GetExternalSubtitleStreams(video, startIndex, options.DirectoryService, false); var externalSubtitleStreams = subtitleResolver.GetExternalSubtitleStreams(video, startIndex, options.DirectoryService, false);
@ -605,7 +606,7 @@ namespace MediaBrowser.Providers.MediaInfo
private string[] FetchFromDvdLib(Video item) private string[] FetchFromDvdLib(Video item)
{ {
var path = item.Path; var path = item.Path;
var dvd = new Dvd(path, _fileSystem); var dvd = new Dvd(path);
var primaryTitle = dvd.Titles.OrderByDescending(GetRuntime).FirstOrDefault(); var primaryTitle = dvd.Titles.OrderByDescending(GetRuntime).FirstOrDefault();

View File

@ -13,7 +13,6 @@ namespace MediaBrowser.Providers.MediaInfo
public class SubtitleResolver public class SubtitleResolver
{ {
private readonly ILocalizationManager _localization; private readonly ILocalizationManager _localization;
private readonly IFileSystem _fileSystem;
private static readonly HashSet<string> SubtitleExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) private static readonly HashSet<string> SubtitleExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{ {
@ -26,16 +25,16 @@ namespace MediaBrowser.Providers.MediaInfo
".vtt" ".vtt"
}; };
public SubtitleResolver(ILocalizationManager localization, IFileSystem fileSystem) public SubtitleResolver(ILocalizationManager localization)
{ {
_localization = localization; _localization = localization;
_fileSystem = fileSystem;
} }
public List<MediaStream> GetExternalSubtitleStreams(Video video, public List<MediaStream> GetExternalSubtitleStreams(
int startIndex, Video video,
IDirectoryService directoryService, int startIndex,
bool clearCache) IDirectoryService directoryService,
bool clearCache)
{ {
var streams = new List<MediaStream>(); var streams = new List<MediaStream>();