Author Topic: Manga Downloader  (Read 2182 times)

0 Members and 1 Guest are viewing this topic.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4557
  • Rating: +716/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Manga Downloader
« on: January 19, 2013, 12:41:09 am »
Recently I made a manga downloader tool for my spouse who often likes to get on CityManga. The problem is that you need internet for that. Since I made a comic downloader for Questionable Content and XKCD, I decided to make a CityManga downloader. Unfortunately, ze does not program, so  had to make it easy to use, unlike my other programs.

It is programmed in Python, so you will need that on your computer, but all you need to do is run the program, type the name of the manga and press enter. For example, ze was finishing up Angel Hunt, the url used "angel_hunt" so that is what you would type. The program will make a folder with the name, then proceed to download each page of each chapter. Each page will be labeled with chapter#_page#, too.

I am sure the program can be optimised a bunch. I know very little Python, so I brute forced a lot of the code .__.
Here is the code, download, and screenshot:
Code: [Select]
import urllib
import urllib2
import os
manganame=raw_input("Manga Name:")
if not os.path.exists(manganame): os.mkdir(manganame)
os.chdir(manganame)
url="http://citymanga.com/"+manganame
f = urllib2.urlopen(url)
a="0"
while a[:20]!=" <b>Chapters:</b> ":
    a=f.readline()
c=20
b=d=0
while b<10 and b>=0:
    d=d*10+b
    b=ord(a[c])-48
    c=c+1
while d:
    f = urllib2.urlopen(url+"/chapter-"+str(d))
    a="0"
    while a[27:39]!="pageselector":
        a=f.readline()
    b=len(f.readline())-30
    if b>330:
        a=(b+20)/35
    if b<331:
        a=b/33
    chapter=str(d)
    path='http://citymanga.com/files/images/'+manganame+"/"+chapter+"/"
    path2=chapter+'_'
    while a:
        b=str(a)+'.jpg'
        print path2+b
        g = open(path2+b,'wb')
        g.write(urllib.urlopen(path+b).read())
        g.close()
        a=a-1
    d=d-1
usock.close()
f.close()
raw_input()