@ -5,6 +5,7 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Localization ;
using MediaBrowser.Controller.Localization ;
using MediaBrowser.Controller.MediaInfo ;
using MediaBrowser.Controller.MediaInfo ;
using MediaBrowser.Controller.Persistence ;
using MediaBrowser.Controller.Persistence ;
using MediaBrowser.Controller.Providers ;
using MediaBrowser.Model.Entities ;
using MediaBrowser.Model.Entities ;
using MediaBrowser.Model.IO ;
using MediaBrowser.Model.IO ;
using MediaBrowser.Model.Logging ;
using MediaBrowser.Model.Logging ;
@ -45,7 +46,7 @@ namespace MediaBrowser.Providers.MediaInfo
_json = json ;
_json = json ;
}
}
public async Task < ItemUpdateType > ProbeVideo < T > ( T item , CancellationToken cancellationToken )
public async Task < ItemUpdateType > ProbeVideo < T > ( T item , IDirectoryService directoryService , CancellationToken cancellationToken )
where T : Video
where T : Video
{
{
var isoMount = await MountIsoIfNeeded ( item , cancellationToken ) . ConfigureAwait ( false ) ;
var isoMount = await MountIsoIfNeeded ( item , cancellationToken ) . ConfigureAwait ( false ) ;
@ -72,7 +73,7 @@ namespace MediaBrowser.Providers.MediaInfo
cancellationToken . ThrowIfCancellationRequested ( ) ;
cancellationToken . ThrowIfCancellationRequested ( ) ;
await Fetch ( item , cancellationToken , result , isoMount ). ConfigureAwait ( false ) ;
await Fetch ( item , cancellationToken , result , isoMount , directoryService ). ConfigureAwait ( false ) ;
}
}
finally
finally
@ -125,7 +126,7 @@ namespace MediaBrowser.Providers.MediaInfo
return result ;
return result ;
}
}
protected async Task Fetch ( Video video , CancellationToken cancellationToken , InternalMediaInfoResult data , IIsoMount isoMount )
protected async Task Fetch ( Video video , CancellationToken cancellationToken , InternalMediaInfoResult data , IIsoMount isoMount , IDirectoryService directoryService )
{
{
if ( data . format ! = null )
if ( data . format ! = null )
{
{
@ -148,7 +149,7 @@ namespace MediaBrowser.Providers.MediaInfo
FetchBdInfo ( video , chapters , mediaStreams , inputPath , cancellationToken ) ;
FetchBdInfo ( video , chapters , mediaStreams , inputPath , cancellationToken ) ;
}
}
AddExternalSubtitles ( video , mediaStreams );
AddExternalSubtitles ( video , mediaStreams , directoryService );
FetchWtvInfo ( video , data ) ;
FetchWtvInfo ( video , data ) ;
@ -342,76 +343,104 @@ namespace MediaBrowser.Providers.MediaInfo
}
}
}
}
public IEnumerable < FileInfo > GetSubtitleFiles ( Video video , IDirectoryService directoryService )
{
var containingPath = video . ContainingFolderPath ;
if ( string . IsNullOrEmpty ( containingPath ) )
{
throw new ArgumentException ( string . Format ( "Cannot search for items that don't have a path: {0} {1}" , video . Name , video . Id ) ) ;
}
var files = directoryService . GetFiles ( containingPath ) ;
var videoFileNameWithoutExtension = Path . GetFileNameWithoutExtension ( video . Path ) ;
return files . Where ( i = >
{
if ( ! i . Attributes . HasFlag ( FileAttributes . Directory ) & &
SubtitleExtensions . Contains ( i . Extension , StringComparer . OrdinalIgnoreCase ) )
{
var fullName = i . FullName ;
var fileNameWithoutExtension = Path . GetFileNameWithoutExtension ( fullName ) ;
if ( string . Equals ( videoFileNameWithoutExtension , fileNameWithoutExtension , StringComparison . OrdinalIgnoreCase ) )
{
return true ;
}
if ( fileNameWithoutExtension . StartsWith ( videoFileNameWithoutExtension + "." , StringComparison . OrdinalIgnoreCase ) )
{
return true ;
}
}
return false ;
} ) ;
}
/// <summary>
/// <summary>
/// Adds the external subtitles.
/// Adds the external subtitles.
/// </summary>
/// </summary>
/// <param name="video">The video.</param>
/// <param name="video">The video.</param>
/// <param name="currentStreams">The current streams.</param>
/// <param name="currentStreams">The current streams.</param>
private void AddExternalSubtitles ( Video video , List < MediaStream > currentStreams )
private void AddExternalSubtitles ( Video video , List < MediaStream > currentStreams , IDirectoryService directoryService )
{
{
//var useParent = !video.ResolveArgs.IsDirectory;
var files = GetSubtitleFiles ( video , directoryService ) ;
//if (useParent && video.Parent == null)
var startIndex = currentStreams . Count ;
//{
var streams = new List < MediaStream > ( ) ;
// return;
//}
var videoFileNameWithoutExtension = Path . GetFileNameWithoutExtension ( video . Path ) ;
//var fileSystemChildren = useParent
foreach ( var file in files )
// ? video.Parent.ResolveArgs.FileSystemChildren
{
// : video.ResolveArgs.FileSystemChildren;
var fullName = file . FullName ;
//var startIndex = currentStreams.Count;
var fileNameWithoutExtension = Path . GetFileNameWithoutExtension ( fullName ) ;
//var streams = new List<MediaStream>();
// If the subtitle file matches the video file name
//var videoFileNameWithoutExtension = Path.GetFileNameWithoutExtension(video.Path);
if ( string . Equals ( videoFileNameWithoutExtension , fileNameWithoutExtension , StringComparison . OrdinalIgnoreCase ) )
{
//foreach (var file in fileSystemChildren
streams . Add ( new MediaStream
// .Where(f => !f.Attributes.HasFlag(FileAttributes.Directory) && SubtitleExtensions.Contains(Path.GetExtension(f.FullName), StringComparer.OrdinalIgnoreCase)))
{
//{
Index = startIndex + + ,
// var fullName = file.FullName;
Type = MediaStreamType . Subtitle ,
IsExternal = true ,
// var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullName);
Path = fullName ,
Codec = Path . GetExtension ( fullName ) . ToLower ( ) . TrimStart ( '.' )
// // If the subtitle file matches the video file name
} ) ;
// if (string.Equals(videoFileNameWithoutExtension, fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
}
// {
else if ( fileNameWithoutExtension . StartsWith ( videoFileNameWithoutExtension + "." , StringComparison . OrdinalIgnoreCase ) )
// streams.Add(new MediaStream
{
// {
// Support xbmc naming conventions - 300.spanish.srt
// Index = startIndex++,
var language = fileNameWithoutExtension . Split ( '.' ) . LastOrDefault ( ) ;
// Type = MediaStreamType.Subtitle,
// IsExternal = true,
// Try to translate to three character code
// Path = fullName,
// Be flexible and check against both the full and three character versions
// Codec = Path.GetExtension(fullName).ToLower().TrimStart('.')
var culture = _localization . GetCultures ( )
// });
. FirstOrDefault ( i = > string . Equals ( i . DisplayName , language , StringComparison . OrdinalIgnoreCase ) | | string . Equals ( i . Name , language , StringComparison . OrdinalIgnoreCase ) | | string . Equals ( i . ThreeLetterISOLanguageName , language , StringComparison . OrdinalIgnoreCase ) | | string . Equals ( i . TwoLetterISOLanguageName , language , StringComparison . OrdinalIgnoreCase ) ) ;
// }
// else if (fileNameWithoutExtension.StartsWith(videoFileNameWithoutExtension + ".", StringComparison.OrdinalIgnoreCase))
if ( culture ! = null )
// {
{
// // Support xbmc naming conventions - 300.spanish.srt
language = culture . ThreeLetterISOLanguageName ;
// var language = fileNameWithoutExtension.Split('.').LastOrDefault();
}
// // Try to translate to three character code
streams . Add ( new MediaStream
// // Be flexible and check against both the full and three character versions
{
// var culture = _localization.GetCultures()
Index = startIndex + + ,
// .FirstOrDefault(i => string.Equals(i.DisplayName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Name, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.ThreeLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.TwoLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase));
Type = MediaStreamType . Subtitle ,
IsExternal = true ,
// if (culture != null)
Path = fullName ,
// {
Codec = Path . GetExtension ( fullName ) . ToLower ( ) . TrimStart ( '.' ) ,
// language = culture.ThreeLetterISOLanguageName;
Language = language
// }
} ) ;
}
// streams.Add(new MediaStream
}
// {
// Index = startIndex++,
video . SubtitleFiles = streams . Select ( i = > i . Path ) . OrderBy ( i = > i ) . ToList ( ) ;
// Type = MediaStreamType.Subtitle,
// IsExternal = true,
currentStreams . AddRange ( streams ) ;
// Path = fullName,
// Codec = Path.GetExtension(fullName).ToLower().TrimStart('.'),
// Language = language
// });
// }
//}
//currentStreams.AddRange(streams);
}
}
/// <summary>
/// <summary>