@@ -77,47 +77,57 @@ public List<Episode> DownloadList(Novel novel)
7777 var document = new HtmlDocument ( ) ;
7878 document . LoadHtml ( downloadedString ) ;
7979
80+ if ( string . IsNullOrWhiteSpace ( novel . Name ) )
81+ {
82+ novel . Name = document . DocumentNode . Descendants ( "title" ) . FirstOrDefault ( ) . InnerText ;
83+ }
84+
8085 if ( string . IsNullOrWhiteSpace ( novel . Desc ) )
8186 {
82- novel . Desc = document . DocumentNode . Descendants ( "title" ) . FirstOrDefault ( ) . InnerText ;
87+ novel . Desc = document . GetElementbyId ( "novel_ex" ) . InnerText ;
8388 }
8489
8590 var episodes = new List < Episode > ( ) ;
8691 for ( int i = 0 ; i < MatchCollection . Count ; i ++ )
8792 {
88- var Episode = new Episode
93+ var episode = new Episode
8994 {
9095 Number = i + 1 ,
9196 URLNumber = ( i + 1 ) . ToString ( ) ,
9297 Title = MatchCollection [ i ] . Value . Split ( '>' ) [ 1 ] . Split ( '<' ) [ 0 ]
9398 } ;
9499
95- episodes . Add ( Episode ) ;
100+ episodes . Add ( episode ) ;
96101 }
97102
98103 return episodes ;
99104 }
100105 }
101106 else if ( novel . Type == NovelType . Kakuyomu )
102107 {
103- using ( var Client = new WebClient ( ) )
108+ using ( var client = new WebClient ( ) )
104109 {
105- Client . Headers . Add ( "User-Agent: Other" ) ;
106- Client . UseDefaultCredentials = true ;
110+ client . Headers . Add ( "User-Agent: Other" ) ;
111+ client . UseDefaultCredentials = true ;
107112
108113 string URL = KakuyomuURL + novel . Code ;
109114
110- var bytes = Client . DownloadData ( URL ) ;
115+ var bytes = client . DownloadData ( URL ) ;
111116 var downloadedString = Encoding . UTF8 . GetString ( bytes ) ;
112117 var Regex1 = new Regex ( "\" widget-toc-episode-titleLabel js-vertical-composition-item\" >" ) ;
113118 var Regex2 = new Regex ( "/episodes/" ) ;
114119
115120 var document = new HtmlDocument ( ) ;
116121 document . LoadHtml ( downloadedString ) ;
117122
123+ if ( string . IsNullOrWhiteSpace ( novel . Name ) )
124+ {
125+ novel . Name = document . GetElementbyId ( "workTitle" ) . InnerText ;
126+ }
127+
118128 if ( string . IsNullOrWhiteSpace ( novel . Desc ) )
119129 {
120- novel . Desc = document . GetElementbyId ( "workTitle " ) . InnerText ;
130+ novel . Desc = document . GetElementbyId ( "introduction " ) . InnerText ;
121131 }
122132
123133 var Matches1 = Regex1 . Matches ( downloadedString ) ;
@@ -195,17 +205,17 @@ public List<Episode> DownloadList(Novel novel)
195205 return null ;
196206 }
197207
198- public void DownloadNovel ( Novel novel , int startIndex , int endIndex , bool merging )
208+ public void DownloadNovel ( Novel novel , int startIndex , int endIndex , bool merging , bool loadOnly = false )
199209 {
200210 Downloading = true ;
201211
202212 try
203213 {
204214 if ( novel . Type == NovelType . Normal || novel . Type == NovelType . R18 )
205215 {
206- if ( ! Directory . Exists ( novel . Desc ) )
216+ if ( ! Directory . Exists ( novel . Name ) )
207217 {
208- Directory . CreateDirectory ( novel . Desc ) ;
218+ Directory . CreateDirectory ( novel . Name ) ;
209219 }
210220
211221 var regex1 = new Regex ( "<p class=\" novel_subtitle\" >(.*)</p>" , RegexOptions . Compiled ) ;
@@ -214,7 +224,7 @@ public void DownloadNovel(Novel novel, int startIndex, int endIndex, bool mergin
214224 var regex4 = new Regex ( "\" La[0-9]*\" >(.*)</p>" , RegexOptions . Multiline ) ;
215225
216226 var dict = new Dictionary < int , string > ( ) ;
217- int Count = 0 ;
227+ int count = 0 ;
218228
219229 for ( int i = startIndex ; i <= endIndex ; i ++ )
220230 {
@@ -266,33 +276,40 @@ public void DownloadNovel(Novel novel, int startIndex, int endIndex, bool mergin
266276 builder . Append ( document . GetElementbyId ( "novel_color" ) . InnerText ) ;
267277
268278 var result = builder . ToString ( ) ;
279+ result = result . Replace ( " " , "" ) ;
280+ result = result . Replace ( "<ruby>" , "" ) ;
281+ result = result . Replace ( "</ruby>" , "" ) ;
282+ result = result . Replace ( "<rp>" , "" ) ;
283+ result = result . Replace ( "</rp>" , "" ) ;
284+ result = result . Replace ( "<rb>" , "" ) ;
285+ result = result . Replace ( "</rb>" , "" ) ;
286+ result = result . Replace ( "<rt>" , "" ) ;
287+ result = result . Replace ( "</rt>" , "" ) ;
288+ result = result . Replace ( "<br />" , Environment . NewLine + Environment . NewLine ) ;
289+ result = result . Replace ( """ , "\" " ) ;
290+ result = result . Replace ( "<" , "<" ) ;
291+ result = result . Replace ( ">" , ">" ) ;
292+ result = result . Replace ( """ , "\" " ) ;
293+ result = result . Replace ( "<" , "<" ) ;
294+ result = result . Replace ( ">" , ">" ) ;
295+
269296 dict . Add ( i , result ) ;
270297
271- if ( ! merging )
298+ if ( loadOnly )
299+ {
300+ novel . Episodes [ i ] . Text = result ;
301+ }
302+ else if ( ! merging )
272303 {
273- result = result . Replace ( " " , "" ) ;
274- result = result . Replace ( "<ruby>" , "" ) ;
275- result = result . Replace ( "</ruby>" , "" ) ;
276- result = result . Replace ( "<rp>" , "" ) ;
277- result = result . Replace ( "</rp>" , "" ) ;
278- result = result . Replace ( "<rb>" , "" ) ;
279- result = result . Replace ( "</rb>" , "" ) ;
280- result = result . Replace ( "<rt>" , "" ) ;
281- result = result . Replace ( "</rt>" , "" ) ;
282- result = result . Replace ( "<br />" , Environment . NewLine + Environment . NewLine ) ;
283- result = result . Replace ( """ , "\" " ) ;
284- result = result . Replace ( "<" , "<" ) ;
285- result = result . Replace ( ">" , ">" ) ;
286- result = result . Replace ( """ , "\" " ) ;
287- result = result . Replace ( "<" , "<" ) ;
288- result = result . Replace ( ">" , ">" ) ;
289-
290- File . WriteAllText ( string . Format ( "{0}\\ {1:D4}.txt" , novel . Desc , i + 1 ) , result , Encoding . UTF8 ) ;
304+ File . WriteAllText ( string . Format ( "{0}\\ {1:D4}.txt" , novel . Name , i + 1 ) , result , Encoding . UTF8 ) ;
291305 }
292306
293- ProgressChanged ? . Invoke ( novel , ++ Count ) ;
307+ if ( ! loadOnly )
308+ {
309+ ProgressChanged ? . Invoke ( novel , ++ count ) ;
310+ }
294311
295- if ( merging && Count - 1 == endIndex - startIndex )
312+ if ( ! loadOnly && merging && count - 1 == endIndex - startIndex )
296313 {
297314 builder . Clear ( ) ;
298315
@@ -302,40 +319,24 @@ public void DownloadNovel(Novel novel, int startIndex, int endIndex, bool mergin
302319 }
303320
304321 result = builder . ToString ( ) ;
305- result = result . Replace ( " " , "" ) ;
306- result = result . Replace ( "<ruby>" , "" ) ;
307- result = result . Replace ( "</ruby>" , "" ) ;
308- result = result . Replace ( "<rp>" , "" ) ;
309- result = result . Replace ( "</rp>" , "" ) ;
310- result = result . Replace ( "<rb>" , "" ) ;
311- result = result . Replace ( "</rb>" , "" ) ;
312- result = result . Replace ( "<rt>" , "" ) ;
313- result = result . Replace ( "</rt>" , "" ) ;
314- result = result . Replace ( "<br />" , Environment . NewLine + Environment . NewLine ) ;
315- result = result . Replace ( """ , "\" " ) ;
316- result = result . Replace ( "<" , "<" ) ;
317- result = result . Replace ( ">" , ">" ) ;
318- result = result . Replace ( """ , "\" " ) ;
319- result = result . Replace ( "<" , "<" ) ;
320- result = result . Replace ( ">" , ">" ) ;
321-
322- File . WriteAllText ( string . Format ( "{0}\\ {1:D4}~{2:D4}.txt" , novel . Desc , startIndex + 1 , endIndex + 1 ) , result , Encoding . UTF8 ) ;
322+
323+ File . WriteAllText ( string . Format ( "{0}\\ {1:D4}~{2:D4}.txt" , novel . Name , startIndex + 1 , endIndex + 1 ) , result , Encoding . UTF8 ) ;
323324 }
324325 }
325326 }
326327 else
327328 {
328- if ( ! Directory . Exists ( novel . Desc ) )
329+ if ( ! Directory . Exists ( novel . Name ) )
329330 {
330- Directory . CreateDirectory ( novel . Desc ) ;
331+ Directory . CreateDirectory ( novel . Name ) ;
331332 }
332333
333334 var Regex1 = new Regex ( "<p class=\" chapterTitle level1 js-vertical-composition-item\" ><span>" , RegexOptions . Multiline ) ;
334335 var Regex2 = new Regex ( "<p class=\" widget-episodeTitle js-vertical-composition-item\" >" , RegexOptions . Multiline ) ;
335336 var Regex3 = new Regex ( "<p id=\" p\\ d+\" " , RegexOptions . Multiline ) ;
336337
337338 var dict = new Dictionary < string , string > ( ) ;
338- int Count = 0 ;
339+ int count = 0 ;
339340
340341 for ( int i = startIndex ; i <= endIndex ; i ++ )
341342 {
@@ -355,35 +356,41 @@ public void DownloadNovel(Novel novel, int startIndex, int endIndex, bool mergin
355356 builder . Append ( document . GetElementbyId ( "contentMain-inner" ) . InnerText ) ;
356357
357358 var result = builder . ToString ( ) ;
359+ result = result . Replace ( " " , "" ) ;
360+ result = result . Replace ( "<em class=\" emphasisDots\" >" , "" ) ;
361+ result = result . Replace ( "</em>" , "" ) ;
362+ result = result . Replace ( "<span>" , "" ) ;
363+ result = result . Replace ( "</span>" , "" ) ;
364+ result = result . Replace ( "<ruby>" , "" ) ;
365+ result = result . Replace ( "</ruby>" , "" ) ;
366+ result = result . Replace ( "<rp>" , "" ) ;
367+ result = result . Replace ( "</rp>" , "" ) ;
368+ result = result . Replace ( "<rb>" , "" ) ;
369+ result = result . Replace ( "</rb>" , "" ) ;
370+ result = result . Replace ( "<rt>" , "" ) ;
371+ result = result . Replace ( "</rt>" , "" ) ;
372+ result = result . Replace ( "<br />" , "\r \n " ) ;
358373
359374 if ( ! dict . ContainsKey ( novel . Episodes [ i ] . URLNumber ) )
360375 {
361376 dict . Add ( novel . Episodes [ i ] . URLNumber , result ) ;
362377
363- if ( ! merging )
378+ if ( loadOnly )
379+ {
380+ novel . Episodes [ i ] . Text = result ;
381+ }
382+ else if ( ! merging )
364383 {
365- result = result . Replace ( " " , "" ) ;
366- result = result . Replace ( "<em class=\" emphasisDots\" >" , "" ) ;
367- result = result . Replace ( "</em>" , "" ) ;
368- result = result . Replace ( "<span>" , "" ) ;
369- result = result . Replace ( "</span>" , "" ) ;
370- result = result . Replace ( "<ruby>" , "" ) ;
371- result = result . Replace ( "</ruby>" , "" ) ;
372- result = result . Replace ( "<rp>" , "" ) ;
373- result = result . Replace ( "</rp>" , "" ) ;
374- result = result . Replace ( "<rb>" , "" ) ;
375- result = result . Replace ( "</rb>" , "" ) ;
376- result = result . Replace ( "<rt>" , "" ) ;
377- result = result . Replace ( "</rt>" , "" ) ;
378- result = result . Replace ( "<br />" , "\r \n " ) ;
379-
380- File . WriteAllText ( string . Format ( "{0}\\ {1:D4}.txt" , novel . Desc , i + 1 ) , result , Encoding . UTF8 ) ;
384+ File . WriteAllText ( string . Format ( "{0}\\ {1:D4}.txt" , novel . Name , i + 1 ) , result , Encoding . UTF8 ) ;
381385 }
382386 }
383387
384- ProgressChanged ? . Invoke ( novel , ++ Count ) ;
388+ if ( ! loadOnly )
389+ {
390+ ProgressChanged ? . Invoke ( novel , ++ count ) ;
391+ }
385392
386- if ( merging && Count - 1 == endIndex - startIndex )
393+ if ( ! loadOnly && merging && count - 1 == endIndex - startIndex )
387394 {
388395 builder . Clear ( ) ;
389396
@@ -394,22 +401,7 @@ public void DownloadNovel(Novel novel, int startIndex, int endIndex, bool mergin
394401
395402 result = builder . ToString ( ) ;
396403
397- result = result . Replace ( " " , "" ) ;
398- result = result . Replace ( "<em class=\" emphasisDots\" >" , "" ) ;
399- result = result . Replace ( "</em>" , "" ) ;
400- result = result . Replace ( "<span>" , "" ) ;
401- result = result . Replace ( "</span>" , "" ) ;
402- result = result . Replace ( "<ruby>" , "" ) ;
403- result = result . Replace ( "</ruby>" , "" ) ;
404- result = result . Replace ( "<rp>" , "" ) ;
405- result = result . Replace ( "</rp>" , "" ) ;
406- result = result . Replace ( "<rb>" , "" ) ;
407- result = result . Replace ( "</rb>" , "" ) ;
408- result = result . Replace ( "<rt>" , "" ) ;
409- result = result . Replace ( "</rt>" , "" ) ;
410- result = result . Replace ( "<br />" , "\r \n " ) ;
411-
412- File . WriteAllText ( string . Format ( "{0}\\ {1:D4}~{2:D4}.txt" , novel . Desc , startIndex + 1 , endIndex + 1 ) , result , Encoding . UTF8 ) ;
404+ File . WriteAllText ( string . Format ( "{0}\\ {1:D4}~{2:D4}.txt" , novel . Name , startIndex + 1 , endIndex + 1 ) , result , Encoding . UTF8 ) ;
413405 }
414406 }
415407 }
0 commit comments