@@ -37,29 +37,43 @@ public JsonResult JacRedConf(string apikey)
3737 [ Route ( "/api/v2.0/indexers/{status}/results" ) ]
3838 public ActionResult Jackett ( string apikey , string query , string title , string title_original , int year , Dictionary < string , string > category , int is_serial = - 1 )
3939 {
40- bool rqnum = false ;
4140 var fastdb = getFastdb ( ) ;
4241 var torrents = new Dictionary < string , TorrentDetails > ( ) ;
42+ bool rqnum = ! HttpContext . Request . QueryString . Value . Contains ( "&is_serial=" ) && HttpContext . Request . Headers . UserAgent . ToString ( ) == "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36" ;
4343
4444 #region Запрос с NUM
45- var mNum = Regex . Match ( query ?? string . Empty , "^([^a-z-A-Z]+) ([^а-я-А-Я]+) ([0-9]{4})$" ) ;
46-
47- if ( string . IsNullOrWhiteSpace ( title ) && string . IsNullOrWhiteSpace ( title_original ) &&
48- mNum . Success )
45+ if ( rqnum && query != null )
4946 {
50- if ( Regex . IsMatch ( mNum . Groups [ 2 ] . Value , "[a-zA-Z0-9]{2}" ) )
47+ var mNum = Regex . Match ( query , "^([^a-z-A-Z]+) ([^а-я-А-Я]+) ([0-9]{4})$" ) ;
48+
49+ if ( mNum . Success )
5150 {
52- rqnum = true ;
53- var g = mNum . Groups ;
51+ if ( Regex . IsMatch ( mNum . Groups [ 2 ] . Value , "[a-zA-Z0-9]{2}" ) )
52+ {
53+ var g = mNum . Groups ;
54+ title = g [ 1 ] . Value ;
55+ title_original = g [ 2 ] . Value ;
56+ year = int . Parse ( g [ 3 ] . Value ) ;
57+ }
58+ }
59+ else
60+ {
61+ if ( Regex . IsMatch ( query , "^([^a-z-A-Z]+) ((19|20)[0-9]{2})$" ) )
62+ return Json ( new RootObject ( ) { Results = new List < Result > ( ) } ) ;
5463
55- title = g [ 1 ] . Value ;
56- title_original = g [ 2 ] . Value ;
57- year = int . Parse ( g [ 3 ] . Value ) ;
64+ mNum = Regex . Match ( query , "^([^a-z-A-Z]+) ([^а-я-А-Я]+)$" ) ;
65+
66+ if ( mNum . Success )
67+ {
68+ if ( Regex . IsMatch ( mNum . Groups [ 2 ] . Value , "[a-zA-Z0-9]{2}" ) )
69+ {
70+ var g = mNum . Groups ;
71+ title = g [ 1 ] . Value ;
72+ title_original = g [ 2 ] . Value ;
73+ }
74+ }
5875 }
5976 }
60-
61- if ( ! rqnum )
62- rqnum = ! HttpContext . Request . QueryString . Value . Contains ( "&is_serial=" ) && HttpContext . Request . Headers . UserAgent . ToString ( ) == "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36" ;
6377 #endregion
6478
6579 #region category
@@ -261,14 +275,14 @@ void updateKeys(string k)
261275 string _s = StringConvert . SearchName ( query ) ;
262276
263277 #region torrentsSearch
264- void torrentsSearch ( bool exact )
278+ void torrentsSearch ( bool exact , bool exactdb )
265279 {
266280 if ( _s == null )
267281 return ;
268282
269283 HashSet < string > keys = null ;
270284
271- if ( exact )
285+ if ( exactdb )
272286 {
273287 if ( fastdb . TryGetValue ( _s , out List < string > _keys ) && _keys . Count > 0 )
274288 {
@@ -294,8 +308,7 @@ void torrentsSearch(bool exact)
294308 break ;
295309 }
296310
297- if ( keys . Count > 0 )
298- memoryCache . Set ( mkey , keys , DateTime . Now . AddHours ( 1 ) ) ;
311+ memoryCache . Set ( mkey , keys , DateTime . Now . AddHours ( 1 ) ) ;
299312 }
300313 }
301314
@@ -351,12 +364,16 @@ void torrentsSearch(bool exact)
351364 #endregion
352365
353366 if ( is_serial == - 1 )
354- torrentsSearch ( exact : false ) ;
367+ {
368+ torrentsSearch ( exact : false , exactdb : true ) ;
369+ if ( torrents . Count == 0 )
370+ torrentsSearch ( exact : false , exactdb : false ) ;
371+ }
355372 else
356373 {
357- torrentsSearch ( exact : true ) ;
374+ torrentsSearch ( exact : true , exactdb : true ) ;
358375 if ( torrents . Count == 0 )
359- torrentsSearch ( exact : false ) ;
376+ torrentsSearch ( exact : false , exactdb : false ) ;
360377 }
361378 #endregion
362379 }
@@ -772,11 +789,13 @@ void AddTorrents(TorrentDetails t)
772789
773790
774791 #region getFastdb
775- Dictionary < string , List < string > > getFastdb ( )
792+ static Dictionary < string , List < string > > _fastdb = null ;
793+
794+ public static Dictionary < string , List < string > > getFastdb ( bool update = false )
776795 {
777- if ( ! memoryCache . TryGetValue ( "api:fastdb" , out Dictionary < string , List < string > > fastdb ) )
796+ if ( _fastdb == null || update )
778797 {
779- fastdb = new Dictionary < string , List < string > > ( ) ;
798+ var fastdb = new Dictionary < string , List < string > > ( ) ;
780799
781800 foreach ( var item in FileDB . masterDb )
782801 {
@@ -787,9 +806,6 @@ Dictionary<string, List<string>> getFastdb()
787806
788807 if ( fastdb . TryGetValue ( k , out List < string > keys ) )
789808 {
790- if ( keys == null )
791- keys = new List < string > ( ) ;
792-
793809 keys . Add ( item . Key ) ;
794810 }
795811 else
@@ -799,10 +815,10 @@ Dictionary<string, List<string>> getFastdb()
799815 }
800816 }
801817
802- memoryCache . Set ( "api:fastdb" , fastdb , DateTime . Now . AddMinutes ( 10 ) ) ;
818+ _fastdb = fastdb ;
803819 }
804820
805- return fastdb ;
821+ return _fastdb ;
806822 }
807823 #endregion
808824 }
0 commit comments