@@ -15,30 +15,43 @@ public static string[] GetOrderedSegmentIds(this NzbFile file)
1515
1616 public static string GetSubjectFileName ( this NzbFile file )
1717 {
18- return FirstNonEmpty (
18+ return GetFirstValidNonEmptyFilename (
1919 ( ) => TryParseFilename1 ( file ) ,
20- ( ) => TryParseFilename2 ( file )
20+ ( ) => TryParseFilename2 ( file ) ,
21+ ( ) => TryParseFilename3 ( file )
2122 ) ;
2223 }
2324
2425 private static string TryParseFilename1 ( this NzbFile file )
2526 {
27+ // example: `[1/8] - "file.mkv" yEnc 12345 (1/54321)`
2628 var match = Regex . Match ( file . Subject , "\\ \" (.*)\\ \" " ) ;
2729 if ( match . Success ) return match . Groups [ 1 ] . Value ;
2830 return "" ;
2931 }
3032
3133 private static string TryParseFilename2 ( this NzbFile file )
3234 {
35+ // example: `Some release [file.mkv] [release]`
3336 var matches = Regex . Matches ( file . Subject , @"\[([^\[\]]*)\]" ) ;
3437 return matches
3538 . Select ( x => x . Groups [ 1 ] . Value )
3639 . Where ( x => Path . GetExtension ( x ) . StartsWith ( "." ) )
3740 . FirstOrDefault ( x => Path . GetExtension ( x ) . Length < 6 ) ?? "" ;
3841 }
3942
40- private static string FirstNonEmpty ( params Func < string > [ ] funcs )
43+ private static string TryParseFilename3 ( this NzbFile file )
4144 {
42- return funcs . Select ( x => x . Invoke ( ) ) . FirstOrDefault ( x => x != "" ) ?? "" ;
45+ // example: `file.mkv (1/0)`
46+ var match = Regex . Match ( file . Subject , @"^(.*?\.\w{2,6})\s+\(.*\)$" ) ;
47+ return match . Success ? match . Groups [ 1 ] . Value : "" ;
48+ }
49+
50+ private static string GetFirstValidNonEmptyFilename ( params Func < string > [ ] funcs )
51+ {
52+ return funcs
53+ . Select ( x => x . Invoke ( ) )
54+ . Where ( x => x == Path . GetFileName ( x ) )
55+ . FirstOrDefault ( x => x != "" ) ?? "" ;
4356 }
4457}
0 commit comments