• R/O
  • SSH
  • HTTPS

autocodeforsql: Commit


Commit MetaInfo

Revision434 (tree)
Zeit2022-06-19 15:03:22
Autorhilinwei

Log Message

Ändern Zusammenfassung

Diff

--- AutoEpub3/Logic/DEP1/cDep1_002.vb (nonexistent)
+++ AutoEpub3/Logic/DEP1/cDep1_002.vb (revision 434)
@@ -0,0 +1,249 @@
1+Imports System.IO
2+Imports HtmlAgilityPack
3+
4+Public Class cDep1_002
5+
6+ Dim bookPath As String
7+
8+ Public mEpub As New List(Of modelChapter)
9+
10+ Dim listSkip As List(Of String) = {"版权", "目录", "书名页", "版权页", "作家榜经典文库", "勇者物语"}.ToList
11+ Dim listMobiRight As List(Of String) = {"signature"}.ToList()
12+ Dim emCurreDep As emEpub6.emDep
13+ Dim iSpanIndex As Integer = 0
14+
15+
16+ Sub New(_bookPath As String)
17+ bookPath = _bookPath
18+ End Sub
19+
20+
21+ Public Sub CreadEpub()
22+
23+ Dim sText As String = String.Empty
24+ Dim listLine As New List(Of String)
25+
26+ Dim ncxFilePath As String = Path.Combine(bookPath, "toc.ncx")
27+
28+ Dim fs As System.IO.FileStream = New System.IO.FileStream(ncxFilePath, System.IO.FileMode.Open)
29+ Dim serializer As System.Xml.Serialization.XmlSerializer = New System.Xml.Serialization.XmlSerializer(GetType(ncx))
30+ Dim model As ncx = CType(serializer.Deserialize(fs), ncx)
31+ fs.Dispose()
32+ fs = Nothing
33+
34+ emCurreDep = emEpub6.emDep.Dep1
35+
36+ Dim iCharp As Integer = 0
37+
38+ For iCtr As Integer = 0 To 6
39+
40+
41+ Dim sPath As String = "C:\Users\DTC_PC07\Downloads\BLY\OEBPS\text0000" & iCtr & ".html"
42+ Dim sTemp As String = sFileEditRead(sPath)
43+
44+
45+ Dim listTemp As List(Of String) = sTemp.Split({"<b>第"}, StringSplitOptions.None).ToList()
46+
47+ For iSub As Integer = 1 To listTemp.Count - 1
48+
49+ Dim mChapter As New modelChapter
50+ iCharp += 1
51+ mChapter.Title = "第" & lbiCSharp.Tools.ToUpper((iCharp).ToString) & "章"
52+
53+
54+ Dim listText As List(Of String) = GetListText(listTemp(iSub))
55+ mChapter.listText = listText
56+
57+ mEpub.Add(mChapter)
58+
59+ Next
60+
61+
62+
63+ 'Dim mChapter As New modelChapter
64+ 'mChapter.Title = "第" & lbiCSharp.Tools.ToUpper((iCtr + 1).ToString) & "章"
65+
66+ 'If listSkip.Any(Function(x) mChapter.Title.IndexOf(x) > -1) Then
67+ ' Continue For
68+ 'End If
69+
70+ 'Dim sPath As String = Path.Combine(bookPath, unitOne.content.src).Split("#").ToList(0)
71+
72+ 'Dim listText As List(Of String) = GetListText(sTemp)
73+ 'mChapter.listText = listText
74+
75+ 'Dim sHtml As String = String.Empty
76+
77+ 'If listSkip.Any(Function(x) mChapter.Title.IndexOf(x) > -1) Then
78+ ' Continue For
79+ 'End If
80+
81+
82+
83+ 'mEpub.Add(mChapter)
84+
85+ Next
86+
87+ 'mEpub.RemoveAt(0)
88+
89+ End Sub
90+
91+ Private Function GetListText(ByVal sHtml) As List(Of String)
92+
93+ GetListText = New List(Of String)
94+ Dim apHtml As HtmlAgilityPack.HtmlDocument = New HtmlAgilityPack.HtmlDocument()
95+ apHtml.LoadHtml(sHtml)
96+ Dim listHtmlNode = apHtml.DocumentNode.Descendants.Where(Function(x) x.Name = "p" OrElse x.Name = "h2")
97+ For Each uHtmlNode As HtmlAgilityPack.HtmlNode In listHtmlNode
98+
99+ If uHtmlNode.Name = "p" Then
100+ Dim sTarget As String = uHtmlNode.InnerHtml
101+ If listMobiRight.Any(Function(x) uHtmlNode.OuterHtml.Contains(x)) Then
102+ sTarget = sTarget + emEpub6.spDl_Right
103+ End If
104+ GetListText.Add(sTarget)
105+ End If
106+
107+ If uHtmlNode.Name = "h2" Then
108+ Dim sTarget As String = uHtmlNode.InnerHtml
109+ sTarget = sTarget + emEpub6.spText_SubTitle
110+ GetListText.Add(sTarget)
111+ End If
112+
113+
114+ If uHtmlNode.Name = "img" Then
115+
116+ Dim imgScr As String = uHtmlNode.Attributes("src").Value
117+ Dim sNewImg As String = cTools.sGaiji(imgScr, emCurreDep)
118+ If uHtmlNode.OuterHtml.IndexOf("image-100") > -1 Then
119+ sNewImg = cTools.sMapImg(imgScr, emCurreDep)
120+ End If
121+ GetListText.Add(sNewImg)
122+ End If
123+
124+
125+ Next
126+
127+ End Function
128+
129+ Private Function sFileEditRead(ByVal sPath As String) As String
130+ sFileEditRead = cTools.sFileReader(sPath, cEpub6.encUTF8)
131+ EditHref00(sFileEditRead)
132+ DelHtml(sFileEditRead)
133+ ResetImgUrl(sFileEditRead)
134+
135+
136+ End Function
137+
138+ Private Function GetListHref(ByRef sHtml As String) As List(Of HtmlNode)
139+
140+ GetListHref = New List(Of HtmlNode)
141+
142+ Dim hapHtmlEdit As HtmlAgilityPack.HtmlDocument = New HtmlAgilityPack.HtmlDocument()
143+ hapHtmlEdit.LoadHtml(sHtml)
144+ Dim linqHap = hapHtmlEdit.DocumentNode.SelectNodes(("//a"))
145+
146+ If linqHap IsNot Nothing Then
147+
148+ For Each uHap As HtmlNode In linqHap
149+
150+
151+ If uHap.Attributes("href") IsNot Nothing Then
152+
153+ GetListHref.Add(uHap)
154+
155+ End If
156+
157+
158+ Next
159+
160+ End If
161+
162+
163+ End Function
164+
165+
166+
167+ Private Sub DelHtml(ByRef sHtml As String)
168+
169+ 'Dim sTemp As String = sHtml
170+
171+ 'Dim hapHtmlEdit As HtmlAgilityPack.HtmlDocument = New HtmlAgilityPack.HtmlDocument()
172+ 'hapHtmlEdit.LoadHtml(sHtml)
173+ 'Dim linqHap = hapHtmlEdit.DocumentNode.Descendants("p").Where(Function(x) x.Attributes("class").Value.Contains("note-title")
174+ ' )
175+
176+ 'If linqHap IsNot Nothing Then
177+ ' For Each uHap As HtmlNode In linqHap
178+ ' sTemp = sTemp.Replace(uHap.OuterHtml, "")
179+ ' Next
180+ 'End If
181+ 'sHtml = sTemp
182+
183+ End Sub
184+
185+
186+ Private Sub EditHref00(ByRef sHtml As String)
187+
188+ Dim hapHtmlEdit As HtmlAgilityPack.HtmlDocument = New HtmlAgilityPack.HtmlDocument()
189+ hapHtmlEdit.LoadHtml(sHtml)
190+ Dim linqHap = hapHtmlEdit.DocumentNode.SelectNodes(("//a"))
191+
192+ If linqHap IsNot Nothing Then
193+
194+ For Each uHap As HtmlNode In linqHap
195+
196+
197+ If uHap.Attributes("href") IsNot Nothing Then
198+ Dim sScr As String = uHap.Attributes("href").Value
199+
200+ If sScr.Split("#").Count = 2 Then
201+
202+ Dim sKey As String = sScr.Split("#")(1)
203+ sHtml = sHtml.Replace(sScr, "#" & sKey)
204+
205+ iSpanIndex += 1
206+
207+ sHtml = sHtml.Replace(sKey, sKey & "_" & iSpanIndex.ToString().PadLeft(5, "0"))
208+
209+
210+
211+ Else
212+ Dim sError As String = ""
213+ End If
214+
215+ End If
216+
217+
218+ Next
219+
220+ End If
221+
222+
223+ End Sub
224+
225+ Private Sub ResetImgUrl(ByRef sChapter As String)
226+
227+ Dim hapHtml As HtmlDocument = New HtmlDocument()
228+ hapHtml.LoadHtml(sChapter)
229+ sChapter = hapHtml.DocumentNode.OuterHtml
230+ hapHtml.LoadHtml(sChapter)
231+
232+
233+
234+ Dim listTarget = hapHtml.DocumentNode.SelectNodes(("//img"))
235+ If listTarget IsNot Nothing Then
236+ For Each uTarget As HtmlNode In listTarget
237+ Dim imgScr As String = uTarget.Attributes("src").Value
238+ Dim sNewImg As String = cTools.sGaiji(imgScr, emCurreDep)
239+ If uTarget.OuterHtml.IndexOf("image-100") > -1 Then
240+ sNewImg = cTools.sMapImg(sNewImg, emCurreDep)
241+ End If
242+ sChapter = sChapter.Replace(uTarget.OuterHtml, sNewImg)
243+ Next
244+ End If
245+
246+ End Sub
247+
248+
249+End Class
Show on old repository browser