Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import os
- from re import finditer
- headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) But it's actually python cuz i'm bored"}
- def html_get(url):
- r = requests.get(url, headers=headers)
- return r.text
- manga_name = input("Manga (Folder) name : ")
- if not os.path.exists(manga_name):
- os.makedirs(manga_name)
- os.chdir(manga_name)
- url_link = input("Link to the manga [mangakakalot.com / manganelo.com source] : ")
- chapter_link = url_link[::-1].replace('/agnam/', '/retpahc/', 1)[::-1]
- html = html_get(url_link)
- index = html.find('div class="row">')
- html = html[index:]
- #print(chapter_link)
- found_iter = finditer(chapter_link, html)
- chapter_links = []
- for iteration in found_iter:
- index = iteration.start() + len(chapter_link)
- url = chapter_link
- while html[index] != '"':
- url += html[index]
- index += 1
- #print(url)
- chapter_links.append(url)
- chapter_links = list(reversed(chapter_links))
- print("Preparations complete")
- print("Chapters like 2.5 count as one just so you know")
- print("But the folders' chapter number will be fitting to the chapter")
- f_ch = int(input("From Chapter [{} is Last] : ".format(len(chapter_links))))
- t_ch = int(input("Till Chapter : "))
- for i in range(f_ch, t_ch + 1):
- ch_link = chapter_links[i - 1]
- html = html_get(ch_link)
- index = html.find('1.jpg') - 1
- sub_url = ""
- while html[index] != '"':
- sub_url += html[index]
- index -= 1
- sub_url = sub_url[::-1]
- Chapter_name = chapter_links[i-1][len(chapter_link) + 1:].replace("_", " ").title()
- if not os.path.exists("{}".format(Chapter_name)):
- os.makedirs("{}".format(Chapter_name))
- os.chdir("{}".format(Chapter_name))
- nr = 1
- s = 2
- while True:
- r = requests.get("{}{}.jpg".format(sub_url, nr), headers=headers)
- if r.status_code == 404:
- break
- with open("{}{}.jpg".format("0" * s, nr), "wb") as img_obj:
- img_obj.write(r.content)
- print("Done with {} Page {}".format(Chapter_name, nr))
- nr += 1
- if nr == 10 or nr == 100:
- s -= 1
- os.chdir("..")
- input("Done\a")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement