Advertisement
iStrzalka

Untitled

Sep 2nd, 2018
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.19 KB | None | 0 0
  1. import requests
  2. import os
  3. from re import finditer
  4.  
  5. headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) But it's actually python cuz i'm bored"}
  6.  
  7. def html_get(url):
  8.     r = requests.get(url, headers=headers)
  9.     return r.text
  10.  
  11. manga_name = input("Manga (Folder) name : ")
  12. if not os.path.exists(manga_name):
  13.     os.makedirs(manga_name)
  14. os.chdir(manga_name)
  15.  
  16. url_link = input("Link to the manga [mangakakalot.com / manganelo.com source] : ")
  17. chapter_link = url_link[::-1].replace('/agnam/', '/retpahc/', 1)[::-1]
  18. html = html_get(url_link)
  19. index = html.find('div class="row">')
  20. html = html[index:]
  21. #print(chapter_link)
  22.  
  23. found_iter = finditer(chapter_link, html)
  24.  
  25. chapter_links = []
  26. for iteration in found_iter:
  27.     index = iteration.start() + len(chapter_link)
  28.     url = chapter_link
  29.     while html[index] != '"':
  30.         url += html[index]
  31.         index += 1
  32.     #print(url)
  33.     chapter_links.append(url)
  34. chapter_links = list(reversed(chapter_links))
  35.  
  36. print("Preparations complete")
  37. print("Chapters like 2.5 count as one just so you know")
  38. print("But the folders' chapter number will be fitting to the chapter")
  39. f_ch = int(input("From Chapter [{} is Last] : ".format(len(chapter_links))))
  40. t_ch = int(input("Till Chapter : "))
  41.  
  42. for i in range(f_ch, t_ch + 1):
  43.     ch_link = chapter_links[i - 1]
  44.     html = html_get(ch_link)
  45.    
  46.     index = html.find('1.jpg') - 1
  47.     sub_url = ""
  48.     while html[index] != '"':
  49.         sub_url += html[index]
  50.         index -= 1
  51.     sub_url = sub_url[::-1]
  52.  
  53.     Chapter_name = chapter_links[i-1][len(chapter_link) + 1:].replace("_", " ").title()
  54.  
  55.     if not os.path.exists("{}".format(Chapter_name)):
  56.         os.makedirs("{}".format(Chapter_name))
  57.     os.chdir("{}".format(Chapter_name))
  58.    
  59.     nr = 1
  60.     s = 2
  61.     while True:
  62.         r = requests.get("{}{}.jpg".format(sub_url, nr), headers=headers)
  63.         if r.status_code == 404:
  64.             break
  65.         with open("{}{}.jpg".format("0" * s, nr), "wb") as img_obj:
  66.            img_obj.write(r.content)
  67.         print("Done with {} Page {}".format(Chapter_name, nr))
  68.         nr += 1
  69.         if nr == 10 or nr == 100:
  70.             s -= 1
  71.     os.chdir("..")
  72.  
  73. input("Done\a")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement