@@ -35,22 +35,14 @@ protected override Url GetRawUrl(SearchQuery query)
3535 // return (BaseUrl.AppendPathSegments("image").AppendPathSegment(Base64Hash));
3636 }
3737
38- protected override ValueTask < SearchResultItem > ParseResultItem ( INode n , SearchResult r )
39- {
40- // ReSharper disable PossibleNullReferenceException
41-
42- var p = ChanPost . Parse ( n ) ;
43- return p . ToItem ( r ) ;
44-
45- // ReSharper restore PossibleNullReferenceException
46- }
38+
4739
4840 protected static string GetHash ( SearchQuery q )
4941 {
5042 //var digestBase64URL = digestBase64.replace('==', '').replace(/\//g, '_').replace(/\+/g, '-');
5143 using Stream stream = q . Source . Image . ToStream ( ) ;
52- var data = MD5 . HashData ( stream ) ;
53- var b64 = Convert . ToBase64String ( data ) . Replace ( "==" , "" ) ;
44+ var data = MD5 . HashData ( stream ) ;
45+ var b64 = Convert . ToBase64String ( data ) . Replace ( "==" , "" ) ;
5446 b64 = Regex . Replace ( b64 , @"\//" , "_" ) ;
5547 b64 = Regex . Replace ( b64 , @"\+" , "-" ) ;
5648
@@ -72,25 +64,35 @@ public override void Dispose()
7264
7365}
7466
75- public record ChanPost : ISearchResultItemConverter < ChanPost >
67+ public record ChanPost : SearchResultItem , INodeResultParse < ChanPost >
7668{
7769
78- public string Author ;
79- public string Board ;
80- public Url File ;
81- public string Filename ;
82- public int Height ;
83-
84- public long Id ;
85- public string Size ;
86- public string Text ;
87- public string Time1 ;
88- public DateTime Time2 ;
89- public string Title ;
90- public string Tripcode ;
91- public int Width ;
92-
93- public static ChanPost Parse ( INode n )
70+ public string Board { get ; private set ; }
71+
72+ public Url File { get ; private set ; }
73+
74+ public string Filename { get ; private set ; }
75+
76+ public long Id { get ; private set ; }
77+
78+ public string Size { get ; private set ; }
79+
80+ public string Text { get ; private set ; }
81+
82+ // public string Time1 { get; private set; }
83+
84+ // public DateTime Time2 { get; private set; }
85+
86+ public string Tripcode { get ; private set ; }
87+
88+
89+
90+
91+ private ChanPost ( SearchResult r ) : base ( r ) { }
92+
93+ #region Implementation of IResultParse<in INode,ChanPost>
94+
95+ public static ValueTask < ChanPost > ParseResultItem ( INode n , SearchResult r )
9496 {
9597 var e = n as HtmlElement ;
9698
@@ -107,42 +109,28 @@ public static ChanPost Parse(INode n)
107109
108110 var wh = pfm [ 1 ] . Split ( 'x' ) ;
109111
110- var p = new ChanPost
112+ var file = Flurl . Url . Parse ( pff . GetAttribute ( "href" ) ) ;
113+
114+ var p = new ChanPost ( r )
111115 {
112116 Id = Int64 . Parse ( e . GetAttribute ( "id" ) ) ,
113117 Board = e . GetAttribute ( "data-board" ) ,
114118 Filename = pff . TextContent ,
115- File = pff . GetAttribute ( "href" ) ,
119+ File = file ,
116120 Width = Int32 . Parse ( wh [ 0 ] ) ,
117121 Height = Int32 . Parse ( wh [ 1 ] ) ,
118122 Size = pfm [ 0 ] ,
119123 Title = pt ,
120- Author = pa ,
124+ Artist = pa ,
125+ Site = file . Host ,
121126 Tripcode = ptc ,
122- Time1 = time ,
123- Time2 = time2 ,
127+ Time = time2 ,
124128 Text = text
125129 } ;
126130
127- return p ;
131+ return ValueTask . FromResult ( p ) ;
128132 }
129133
130- public ValueTask < SearchResultItem > ToItem ( SearchResult sr )
131- {
132-
133- var sri = new SearchResultItem ( sr )
134- {
135- Url = File ,
136- Width = Width ,
137- Height = Height ,
138- Artist = Author ,
139- Description = Title ,
140- Time = Time2 ,
141- Site = File . Host ,
142- Metadata = this
143- } ;
144-
145- return ValueTask . FromResult ( sri ) ;
146- }
134+ #endregion
147135
148136}
0 commit comments