|
|
|
@ -30,10 +30,11 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
|
|
|
|
|
if (!_diskProvider.FileExists(filename))
|
|
|
|
|
throw new FileNotFoundException("Media file does not exist: " + filename);
|
|
|
|
|
|
|
|
|
|
var mediaInfo = new MediaInfoLib.MediaInfo();
|
|
|
|
|
MediaInfoLib.MediaInfo mediaInfo = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
mediaInfo = new MediaInfoLib.MediaInfo();
|
|
|
|
|
_logger.Trace("Getting media info from {0}", filename);
|
|
|
|
|
|
|
|
|
|
mediaInfo.Option("ParseSpeed", "0.2");
|
|
|
|
@ -56,26 +57,26 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
|
|
|
|
|
Int32.TryParse(mediaInfo.Get(StreamKind.Video, 0, "BitRate"), out videoBitRate);
|
|
|
|
|
|
|
|
|
|
string aBitRate = mediaInfo.Get(StreamKind.Audio, 0, "BitRate");
|
|
|
|
|
int ABindex = aBitRate.IndexOf(" /");
|
|
|
|
|
if (ABindex > 0)
|
|
|
|
|
aBitRate = aBitRate.Remove(ABindex);
|
|
|
|
|
int aBindex = aBitRate.IndexOf(" /", StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
|
if (aBindex > 0)
|
|
|
|
|
aBitRate = aBitRate.Remove(aBindex);
|
|
|
|
|
|
|
|
|
|
Int32.TryParse(aBitRate, out audioBitRate);
|
|
|
|
|
Int32.TryParse(mediaInfo.Get(StreamKind.Video, 0, "PlayTime"), out runTime);
|
|
|
|
|
Int32.TryParse(mediaInfo.Get(StreamKind.Audio, 0, "StreamCount"), out streamCount);
|
|
|
|
|
|
|
|
|
|
string audioChannelsStr = mediaInfo.Get(StreamKind.Audio, 0, "Channel(s)");
|
|
|
|
|
int ACindex = audioChannelsStr.IndexOf(" /");
|
|
|
|
|
if (ACindex > 0)
|
|
|
|
|
audioChannelsStr = audioChannelsStr.Remove(ACindex);
|
|
|
|
|
int aCindex = audioChannelsStr.IndexOf(" /", StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
|
if (aCindex > 0)
|
|
|
|
|
audioChannelsStr = audioChannelsStr.Remove(aCindex);
|
|
|
|
|
|
|
|
|
|
string audioLanguages = mediaInfo.Get(StreamKind.General, 0, "Audio_Language_List");
|
|
|
|
|
decimal videoFrameRate = Decimal.Parse(mediaInfo.Get(StreamKind.Video, 0, "FrameRate"));
|
|
|
|
|
string audioProfile = mediaInfo.Get(StreamKind.Audio, 0, "Format_Profile");
|
|
|
|
|
|
|
|
|
|
int APindex = audioProfile.IndexOf(" /");
|
|
|
|
|
if (APindex > 0)
|
|
|
|
|
audioProfile = audioProfile.Remove(APindex);
|
|
|
|
|
int aPindex = audioProfile.IndexOf(" /", StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
|
if (aPindex > 0)
|
|
|
|
|
audioProfile = audioProfile.Remove(aPindex);
|
|
|
|
|
|
|
|
|
|
Int32.TryParse(audioChannelsStr, out audioChannels);
|
|
|
|
|
var mediaInfoModel = new MediaInfoModel
|
|
|
|
@ -84,9 +85,10 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
|
|
|
|
|
VideoBitrate = videoBitRate,
|
|
|
|
|
Height = height,
|
|
|
|
|
Width = width,
|
|
|
|
|
|
|
|
|
|
AudioFormat = mediaInfo.Get(StreamKind.Audio, 0, "Format"),
|
|
|
|
|
AudioBitrate = audioBitRate,
|
|
|
|
|
RunTime = (runTime / 1000), //InSeconds
|
|
|
|
|
RunTime = TimeSpan.FromMilliseconds(runTime),
|
|
|
|
|
AudioStreamCount = streamCount,
|
|
|
|
|
AudioChannels = audioChannels,
|
|
|
|
|
AudioProfile = audioProfile.Trim(),
|
|
|
|
@ -100,34 +102,10 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
|
|
|
|
|
return mediaInfoModel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
catch (DllNotFoundException ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Unable to parse media info from file: " + filename, ex);
|
|
|
|
|
mediaInfo.Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TimeSpan GetRunTime(string filename)
|
|
|
|
|
{
|
|
|
|
|
MediaInfoLib.MediaInfo mediaInfo = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
mediaInfo = new MediaInfoLib.MediaInfo();
|
|
|
|
|
_logger.Trace("Getting media info from {0}", filename);
|
|
|
|
|
|
|
|
|
|
mediaInfo.Option("ParseSpeed", "0.2");
|
|
|
|
|
int open = mediaInfo.Open(filename);
|
|
|
|
|
|
|
|
|
|
if (open != 0)
|
|
|
|
|
{
|
|
|
|
|
int runTime;
|
|
|
|
|
Int32.TryParse(mediaInfo.Get(StreamKind.Video, 0, "PlayTime"), out runTime);
|
|
|
|
|
|
|
|
|
|
mediaInfo.Close();
|
|
|
|
|
return TimeSpan.FromMilliseconds(runTime);
|
|
|
|
|
}
|
|
|
|
|
_logger.ErrorException("mediainfo is required but was not found", ex);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
@ -141,7 +119,19 @@ namespace NzbDrone.Core.MediaFiles.MediaInfo
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new TimeSpan();
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TimeSpan GetRunTime(string filename)
|
|
|
|
|
{
|
|
|
|
|
var info = GetMediaInfo(filename);
|
|
|
|
|
|
|
|
|
|
if (info == null)
|
|
|
|
|
{
|
|
|
|
|
return new TimeSpan();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info.RunTime;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|