@ -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 A Bindex = aBitRate . IndexOf ( " /" ) ;
if ( A Bindex > 0 )
aBitRate = aBitRate . Remove ( A Bindex) ;
int a Bindex = aBitRate . IndexOf ( " /" , StringComparison . InvariantCultureIgnoreCase ) ;
if ( a Bindex > 0 )
aBitRate = aBitRate . Remove ( a Bindex) ;
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 A Cindex = audioChannelsStr . IndexOf ( " /" ) ;
if ( A Cindex > 0 )
audioChannelsStr = audioChannelsStr . Remove ( A Cindex) ;
int a Cindex = audioChannelsStr . IndexOf ( " /" , StringComparison . InvariantCultureIgnoreCase ) ;
if ( a Cindex > 0 )
audioChannelsStr = audioChannelsStr . Remove ( a Cindex) ;
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 A Pindex = audioProfile . IndexOf ( " /" ) ;
if ( A Pindex > 0 )
audioProfile = audioProfile . Remove ( A Pindex) ;
int a Pindex = audioProfile . IndexOf ( " /" , StringComparison . InvariantCultureIgnoreCase ) ;
if ( a Pindex > 0 )
audioProfile = audioProfile . Remove ( a Pindex) ;
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 ( DllNotFound Exception 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 ;
}
}
}