@@ -66,46 +66,19 @@ protected override SearchResult Process(object obj, SearchResult r)
6666 {
6767 Error = ( sender , args ) =>
6868 {
69-
7069 if ( object . Equals ( args . ErrorContext . Member , nameof ( TraceMoeDoc . episode ) ) /*&&
7170 args.ErrorContext.OriginalObject.GetType() == typeof(TraceMoeRootObject)*/ ) {
7271 args . ErrorContext . Handled = true ;
73-
7472 }
7573
7674 Debug . WriteLine ( $ "{ args . ErrorContext } ") ;
7775 }
7876 } ;
7977
80- /*var tm2t = request.GetJsonAsync();
81- tm2t.Wait();
82- var tm2 = tm2t.Result;
83-
84- dynamic result = tm2.result;
85- Debug.WriteLine($"{result}");
86- tm = new() { result = new(), error = tm2.error, frameCount = tm2.frameCount };
87-
88- for (int i = 0; i < result.Count; i++) {
89- Debug.WriteLine($"{result[i]}");
90-
91- var d = result[i];
92-
93- var doc = new TraceMoeDoc()
94- {
95- episode = d.episode,
96- from = d.from,
97- to = d.to,
98- filename = d.filename, anilist = d.anilist
99- };
100-
101- tm.result.Add(doc);
102- }*/
103-
104-
10578 tm = JsonConvert . DeserializeObject < TraceMoeRootObject > ( json , settings ) ;
10679 }
10780 catch ( Exception e ) {
108- Debug . WriteLine ( $ ">>>> { e . Message } ") ;
81+ Debug . WriteLine ( $ "{ Name } : { nameof ( Process ) } : { e . Message } ") ;
10982
11083 goto ret ;
11184 }
@@ -149,28 +122,18 @@ protected override SearchResult Process(object obj, SearchResult r)
149122 return r ;
150123 }
151124
152- private IEnumerable < ImageResult > ConvertResults ( TraceMoeRootObject obj , SearchResult r )
125+ private IEnumerable < ImageResult > ConvertResults ( TraceMoeRootObject obj , SearchResult sr )
153126 {
154- var docs = obj . result ;
155- var results = new ImageResult [ docs . Count ] ;
127+ var results = obj . result ;
128+ var imageResults = new ImageResult [ results . Count ] ;
156129
157- for ( int i = 0 ; i < results . Length ; i ++ ) {
158- var doc = docs [ i ] ;
130+ for ( int i = 0 ; i < imageResults . Length ; i ++ ) {
131+ var doc = results [ i ] ;
159132 float sim = MathF . Round ( ( float ) ( doc . similarity * 100.0f ) , 2 ) ;
160133
161- var episode = doc . episode ;
162-
163- string epStr = episode . ToString ( ) ;
134+ string epStr = GetEpisodeString ( doc ) ;
164135
165- if ( episode is string ) {
166- epStr = episode as string ;
167- }
168- else if ( episode is IEnumerable enumerable ) {
169- var ls = enumerable . CopyToList ( ) . Select ( x => Int64 . Parse ( x . ToString ( ) ?? String . Empty ) ) ;
170- epStr = ls . QuickJoin ( ) ;
171- }
172-
173- var result = new ImageResult ( r )
136+ var result = new ImageResult ( sr )
174137 {
175138 Similarity = sim ,
176139 Description = $ "Episode #{ epStr } @ { TimeSpan . FromSeconds ( doc . from ) } "
@@ -192,10 +155,26 @@ private IEnumerable<ImageResult> ConvertResults(TraceMoeRootObject obj, SearchRe
192155 $ "< { FILTER_THRESHOLD / 100 : P} )") ;
193156 }
194157
195- results [ i ] = result ;
158+ imageResults [ i ] = result ;
196159 }
197160
198- return results ;
161+ return imageResults ;
162+
163+ static string GetEpisodeString ( TraceMoeDoc doc )
164+ {
165+ object episode = doc . episode ;
166+
167+ string epStr = episode is string s ? s : episode . ToString ( ) ;
168+
169+ if ( episode is IEnumerable e ) {
170+ var epList = e . CopyToList ( )
171+ . Select ( x => Int64 . Parse ( x . ToString ( ) ?? String . Empty ) ) ;
172+
173+ epStr = epList . QuickJoin ( ) ;
174+ }
175+
176+ return epStr ;
177+ }
199178 }
200179
201180 /// <summary>
@@ -223,8 +202,7 @@ private class TraceMoeDoc
223202 public string filename { get ; set ; }
224203
225204
226- /// <remarks>Episode field may contain multiple possible results delimited by <c>|</c></remarks>
227- // [JsonIgnore]
205+ /// <remarks>Episode may be a JSON array (edge case) or a normal integer</remarks>
228206 public object episode { get ; set ; }
229207
230208 public double similarity { get ; set ; }
0 commit comments