@@ -14,7 +14,8 @@ public static class SyncCron
1414 {
1515 static long lastsync = - 1 , starsync = - 1 ;
1616
17- async public static Task Run ( )
17+ #region Torrents
18+ async public static Task Torrents ( )
1819 {
1920 await Task . Delay ( 20_000 ) ;
2021
@@ -55,19 +56,16 @@ async public static Task Run()
5556 else if ( root . collections . Count > 0 )
5657 {
5758 reset = true ;
58- var torrents = new List < TorrentBaseDetails > ( ) ;
59+ var torrents = new List < TorrentBaseDetails > ( root . countread ) ;
5960
6061 foreach ( var collection in root . collections )
6162 {
6263 foreach ( var torrent in collection . Value . torrents )
6364 {
64- if ( torrent . Value . types == null )
65+ if ( AppInit . conf . synctrackers != null && torrent . Value . trackerName != null && ! AppInit . conf . synctrackers . Contains ( torrent . Value . trackerName ) )
6566 continue ;
6667
67- if ( AppInit . conf . synctrackers != null && ! AppInit . conf . synctrackers . Contains ( torrent . Value . trackerName ) )
68- continue ;
69-
70- if ( ! AppInit . conf . syncsport && torrent . Value . types . Contains ( "sport" ) )
68+ if ( ! AppInit . conf . syncsport && torrent . Value . types != null && torrent . Value . types . Contains ( "sport" ) )
7169 continue ;
7270
7371 torrents . Add ( torrent . Value ) ;
@@ -118,14 +116,16 @@ async public static Task Run()
118116
119117 FileDB . SaveChangesToFile ( ) ;
120118 File . WriteAllText ( "lastsync.txt" , lastsync . ToString ( ) ) ;
119+
120+ Console . WriteLine ( "sync: end" ) ;
121121 }
122122 else
123123 {
124124 await Task . Delay ( TimeSpan . FromMinutes ( 1 ) ) ;
125125 continue ;
126126 }
127127 }
128- catch
128+ catch ( Exception ex )
129129 {
130130 try
131131 {
@@ -136,12 +136,62 @@ async public static Task Run()
136136 }
137137 }
138138 catch { }
139+
140+ Console . WriteLine ( "sync: error / " + ex . Message ) ;
139141 }
140142
141- Console . WriteLine ( "sync: end" ) ;
142143 await Task . Delay ( 1000 * Random . Shared . Next ( 60 , 300 ) ) ;
143144 await Task . Delay ( 1000 * 60 * ( 20 > AppInit . conf . timeSync ? 20 : AppInit . conf . timeSync ) ) ;
144145 }
145146 }
147+ #endregion
148+
149+ #region Spidr
150+ async public static Task Spidr ( )
151+ {
152+ while ( true )
153+ {
154+ await Task . Delay ( 1000 * Random . Shared . Next ( 60 , 300 ) ) ;
155+ await Task . Delay ( 1000 * 60 * 120 ) ;
156+
157+ try
158+ {
159+ if ( ! string . IsNullOrWhiteSpace ( AppInit . conf . syncapi ) && AppInit . conf . syncspidr )
160+ {
161+ long lastsync_spidr = - 1 ;
162+
163+ var conf = await HttpClient . Get < JObject > ( $ "{ AppInit . conf . syncapi } /sync/conf") ;
164+ if ( conf != null && conf . ContainsKey ( "spidr" ) && conf . Value < bool > ( "spidr" ) )
165+ {
166+ Console . WriteLine ( $ "\n \n sync_spidr: start / { DateTime . Now } ") ;
167+
168+ next : var root = await HttpClient . Get < Models . Sync . v2 . RootObject > ( $ "{ AppInit . conf . syncapi } /sync/fdb/torrents?time={ lastsync_spidr } &spidr=true", timeoutSeconds : 300 , MaxResponseContentBufferSize : 100_000_000 ) ;
169+
170+ Console . WriteLine ( $ "sync_spidr: time={ lastsync_spidr } ") ;
171+
172+ if ( root ? . collections != null && root . collections . Count > 0 )
173+ {
174+ foreach ( var collection in root . collections )
175+ FileDB . AddOrUpdate ( collection . Value . torrents . Values ) ;
176+
177+ lastsync_spidr = root . collections . Last ( ) . Value . fileTime ;
178+
179+ if ( root . nextread )
180+ goto next ;
181+ }
182+
183+ Console . WriteLine ( "sync_spidr: end" ) ;
184+ }
185+ }
186+ else
187+ {
188+ await Task . Delay ( TimeSpan . FromMinutes ( 1 ) ) ;
189+ continue ;
190+ }
191+ }
192+ catch ( Exception ex ) { Console . WriteLine ( "sync_spidr: error / " + ex . Message ) ; }
193+ }
194+ }
195+ #endregion
146196 }
147197}
0 commit comments