Showing 1 changed files with 126 additions and 8 deletions
+126 -8
mangaProxy.py
... ...
@@ -59,7 +59,7 @@ def completedManganeloTV(genre):
59 59
   return pageContent
60 60
 
61 61
 def getReadManganatoCOM(url):
62
-  debug("Downloading: "+url)
62
+  debug("getReadManganatoCOM: "+url)
63 63
   #if "manganelo.com" in url:
64 64
   #  url=url.replace("manganelo.com","manganelo.tv")
65 65
   #  say("Replace URL:"+url)
... ...
@@ -74,8 +74,6 @@ def getReadManganatoCOM(url):
74 74
   linkPrev = None
75 75
   listImages = []
76 76
 
77
-
78
-
79 77
   for line in content.split("\n"):
80 78
     if "<meta property=\"og:title\" content=\"" in line and lineTitle is None:
81 79
       lineTitle = line
... ...
@@ -173,13 +171,133 @@ def getReadManganatoCOM(url):
173 171
   pageContent += "</div><!-- /row -->\n"
174 172
   return pageContent
175 173
 
174
+def getMangakakalotCom(url):
175
+  debug("getMangakakalotCom :"+url)
176
+  r = requests.get(url, allow_redirects=True)
177
+  content = r.text
178
+  
179
+  isMangakakalot = 1
180
+  lineNextChapter = None
181
+  linePreviousChapter = None
182
+  lineTitle = None
183
+  linkNext = None
184
+  linkPrev = None
185
+  listImages = []
186
+  for line in content.split("\n"):
187
+    if "<meta property=\"og:title\" content=\"" in line and lineTitle is None:
188
+      lineTitle = line
189
+
190
+    elif isMangakakalot == 1 and "<div class='btn-navigation-chap'>" in line and lineNextChapter is None and linkNext is None:
191
+      for subLine in line.split("><"):
192
+        if "NEXT CHAPTER" in subLine:
193
+          linkNext=subLine.split("'")[1]
194
+          debug("linkNext: "+linkNext)
195
+    elif isMangakakalot == 1 and "<div class='btn-navigation-chap'>" in line and linePreviousChapter is None and linkPrev is None:
196
+      for subLine in line.split("><"):
197
+        if "PREV CHAPTER" in subLine:
198
+          linkPrev=subLine.split("'")[1]
199
+          debug("linkPrev: "+linkPrev)
200
+
201
+    elif "<img class=\"img-loading\" data-src=\"" in line:
202
+      if ".jpg" in line:
203
+        listImages.append(line.split("\"")[3])    
204
+
205
+  if 0 == len(listImages):
206
+    # Attempt to extract images once more, most likely all are on one line
207
+    for line in content.split("\n"):
208
+      if " page " in line:
209
+        for subLine in line.split("><"):
210
+          if "https://" in subLine:
211
+            if ".jpg" in subLine.split("\"")[1]:
212
+              listImages.append(subLine.split("\"")[1])
213
+
214
+  if None is not linePreviousChapter:
215
+    say("Prev :"+str(len(linePreviousChapter)))
216
+    #i.e First chapter is opened
217
+    if 200 < len(linePreviousChapter):
218
+      tempLine = linePreviousChapter 
219
+      linePreviousChapter = None
220
+      for line in tempLine.split("><"):
221
+        if "navi-change-chapter-btn-prev a-h" in line and linePreviousChapter is None:
222
+          linePreviousChapter = line
223
+      linkPrev=linePreviousChapter.split("\"")[5]
224
+    else:
225
+      linkPrev="https://manganelo.tv"+linePreviousChapter.split("\"")[5]
226
+
227
+  if None is not lineNextChapter:
228
+    #i.e Last chapter is opened
229
+    say("Next :"+str(len(lineNextChapter)))
230
+    if 200 < len(lineNextChapter):
231
+      tempLine = lineNextChapter 
232
+      lineNextChapter = None
233
+      for line in tempLine.split("><"):
234
+        if "navi-change-chapter-btn-next a-h" in line and lineNextChapter is None:
235
+          lineNextChapter = line
236
+      linkNext=lineNextChapter.split("\"")[5]
237
+    else:
238
+      linkNext="https://manganelo.tv"+lineNextChapter.split("\"")[5]
239
+        
240
+  mangaImagesNum = len(listImages)
241
+  mangaTitle=lineTitle.split("\"")[3].split(" - Manganelo")[0]
242
+  say("Manga :"+mangaTitle)
243
+  pageContent = ""
244
+  pageContent += "<div class=\"mangaChapNavig\">\n"
245
+  pageContent += "  <div class=\"mangaTitle\">"+mangaTitle+"</div>\n"
246
+  if linkPrev is not None:
247
+    pageContent += "  <div class=\"mangaChapNavigPrev\"><a href=\"?url="+linkPrev+"\"><div class=\"arrow-left\"></div><div class=\"arrow-left\"></div></a></div>\n"
248
+  if linkNext is not None:
249
+    pageContent += "  <div class=\"mangaChapNavigNext\"><a href=\"?url="+linkNext+"\"><div class=\"arrow-right\"></div><div class=\"arrow-right\"></div></a></div>\n"
250
+  pageContent += "  <div class=\"mangaChapNavigHome\"><a href=\".\"><div class=\"arrow-up\"></div></a></div>\n"
251
+  pageContent += "  <span id=\"mangaCurrPage\"></span><span id=\"mangaNumPages\"> / "+str(mangaImagesNum)+"</span>\n"
252
+  pageContent += "  <span id=\"mangaFSStatus\" style=\"display: none;\">0</span>\n"
253
+  pageContent += "  <span id=\"mangaFSToggle\" onclick=\"openFullscreen();\"><div class=\"fs-on\"></div></span>\n"
254
+  opacityValue=2;
255
+  if 7 <= datetime.datetime.now().hour and 20 >= datetime.datetime.now().hour:
256
+    opacityValue=10;
257
+  pageContent += "  <span id=\"mangaOpacityMinus\" onclick=\"onOpacityMinus()\">&#9788;</span>"
258
+  pageContent += "  <span id=\"mangaOpacityValue\">"+str(opacityValue)+"</span>"
259
+  pageContent += "  <span id=\"mangaOpacityPlus\" onclick=\"onOpacityPlus()\">&#9728;</span>\n"
260
+  pageContent += "  <span id=\"mangaReload\" onClick=\"window.location.reload();\"><div class=\"reload-circle\"></div></span>\n" 
261
+  pageContent += "</div>\n"
262
+  
263
+  pageContent += "<a name=\"article-top\"></a><div id=\"article-current\"></div>\n"
264
+  pageContent += "<div class=\"row\">\n\n"
265
+
266
+  cpt = 0
267
+  for pageImage in listImages:
268
+    #debug(pageImage)
269
+    pageContent += "<div class=\"article\" id=\"article-"+str(cpt)+"\" style=\"display: none;\">\n"
270
+    pageContent += "  <div class=\"column\" id=\"colLeft\" onclick=\"onArticle("+str(cpt-1)+")\">\n"
271
+    pageContent += "    <div class=\"arrow-left\"></div>\n"
272
+    pageContent += "  </div><!-- /column colLeft -->\n"
273
+        
274
+    pageContent += "  <div class=\"column\" id=\"colMiddle\">\n"
275
+    pageContent += "    <a name=\"article-"+str(cpt)+"\">\n"
276
+    pageContent += "    <img src=\"defer.png\" data-src=\""+pageImage+"\" class=\"center\">\n"
277
+    #pageContent += "    <li>"+str(cpt)+" : "+pageImage+"</li>\n"
278
+    pageContent += "  </div><!-- /column colMiddle -->\n\n"
279
+    
280
+    pageContent += "  <div class=\"column\" id=\"colRight\" onclick=\"onArticle("+str(cpt+1)+")\">\n"
281
+    pageContent += "    <div class=\"arrow-right\"></div>\n"
282
+    pageContent += "  </div><!-- /column colRight -->\n"
283
+    pageContent += "</div>\n"
284
+    pageContent += "\n"
285
+    cpt += 1
286
+
287
+  pageContent += "</div><!-- /row -->\n"
288
+  return pageContent
289
+
176 290
 def getManganeloTV(url):
177
-  debug("Downloading: "+url)
291
+  debug("getManganeloTV :"+url)
178 292
   #if "manganelo.com" in url:
179 293
   #  url=url.replace("manganelo.com","manganelo.tv")
180 294
   #  say("Replace URL:"+url)
181 295
   r = requests.get(url, allow_redirects=True)
182 296
   content = r.text
297
+  
298
+  isMangakakalot = 0
299
+  if "mangakakalot.com" in url:
300
+    isMangakakalot=1
183 301
 
184 302
   #print(r.text)
185 303
   lineNextChapter = None
... ...
@@ -362,9 +480,9 @@ class MyServer(BaseHTTPRequestHandler):
362 480
             data_page = ""
363 481
 
364 482
             #Forging response
365
-            if configuration.get_debug() != 0:
366
-                data_page += "<p>Request: "+self.path+"</p>\n"
367
-                data_page += "<xmp>"+json.dumps(urlArgs)+"</xmp>\n"
483
+            #if configuration.get_debug() != 0:
484
+            #    data_page += "<p>Request: "+self.path+"</p>\n"
485
+            #    data_page += "<xmp>"+json.dumps(urlArgs)+"</xmp>\n"
368 486
 
369 487
             if not url is None:
370 488
                 if "manganelo" in url:
... ...
@@ -372,7 +490,7 @@ class MyServer(BaseHTTPRequestHandler):
372 490
                 elif "readmanganato.com" in url:
373 491
                     data_page += getReadManganatoCOM(url)
374 492
                 elif "mangakakalot.com" in url:
375
-                    data_page += getManganeloTV(url)
493
+                    data_page += getMangakakalotCom(url)
376 494
                 else:
377 495
                     warn("Unsupported Hoster at "+url)
378 496
                     data_page += "<span id=\"lbl\">Unsupported hoster at "+url+"</span>"