-
-
Save Nominom/634f27db499c04ae08f3962ce6cd9a4d to your computer and use it in GitHub Desktop.
# Original script by drdaxxy | |
# https://gist.github.com/drdaxxy/1e43b3aee3e08a5898f61a45b96e4cb4 | |
import sys | |
import os | |
import requests | |
import errno | |
from PIL import Image | |
login = False # Set this to True if you want to login | |
username = "your email here" | |
password = "your password" | |
loginheaders = { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0', | |
'origin': 'https://pocket.shonenmagazine.com', | |
'x-requested-with': 'XMLHttpRequest' | |
} | |
loginurl = "https://pocket.shonenmagazine.com/user_account/login" | |
sess = requests.Session() | |
if login: | |
logindata = {"email_address": username, "password": password, "return_location_path" : "/"} | |
r = sess.post(loginurl, headers=loginheaders, data = logindata) | |
if r.ok: | |
print('LOGIN SUCCESS') | |
else: | |
print('LOGIN FAILED') | |
print(r.headers) | |
print(r.status_code) | |
print(r.reason) | |
print(r.text) | |
if len(sys.argv) != 3: | |
print("usage: shonenripperjson.py <url> <destination folder>") | |
sys.exit(1) | |
destination = sys.argv[2] | |
if not os.path.exists(destination): | |
try: | |
os.makedirs(destination) | |
except OSError as exc: | |
if exc.errno != errno.EEXIST: | |
raise | |
url = sys.argv[1] | |
if not url.endswith('.json'): | |
url = url + ".json" | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0'} | |
print("Getting from url: "+url) | |
r = sess.get(url=url, headers=headers) | |
data = r.json() | |
def dlImage(url, outFilename, drm): | |
r = sess.get(url, stream=True, headers=headers) | |
if not r.ok: | |
print(r) | |
return | |
content_type = r.headers.get('content-type') | |
if content_type == "image/jpeg": | |
outFilename = outFilename + ".jpg" | |
elif content_type == "image/png": | |
outFilename = outFilename + ".png" | |
else: | |
print("content type not recognized!") | |
print(r) | |
return | |
with open(outFilename, 'wb') as file: | |
for block in r.iter_content(1024): | |
if not block: | |
break | |
file.write(block) | |
if drm == True: | |
source = Image.open(outFilename) | |
dest = Image.new(source.mode, source.size) | |
def draw_subimage(sx, sy, sWidth, sHeight, dx, dy): | |
rect = source.crop((sx, sy, sx+sWidth, sy+sHeight)) | |
dest.paste(rect, (dx, dy, dx+sWidth, dy+sHeight)) | |
DIVIDE_NUM = 4 | |
MULTIPLE = 8 | |
cell_width = (source.width // (DIVIDE_NUM * MULTIPLE)) * MULTIPLE | |
cell_height = (source.height // (DIVIDE_NUM * MULTIPLE)) * MULTIPLE | |
for e in range(0, DIVIDE_NUM * DIVIDE_NUM): | |
t = e // DIVIDE_NUM * cell_height | |
n = e % DIVIDE_NUM * cell_width | |
r = e // DIVIDE_NUM | |
i_ = e % DIVIDE_NUM | |
u = i_ * DIVIDE_NUM + r | |
s = u % DIVIDE_NUM * cell_width | |
c = (u // DIVIDE_NUM) * cell_height | |
draw_subimage(n, t, cell_width, cell_height, s, c) | |
dest.save(outFilename) | |
if 'readableProduct' in data: | |
readableProduct = data['readableProduct'] | |
nextReadableProductUri = None | |
if 'nextReadableProductUri' in readableProduct: | |
nextReadableProductUri = readableProduct['nextReadableProductUri'] | |
if 'pageStructure' in readableProduct: | |
pageStructure = readableProduct['pageStructure'] | |
if pageStructure == None: | |
print('Could not download pages. Most likely this volume is not public.') | |
sys.exit(1) | |
choJuGiga = pageStructure['choJuGiga'] if 'choJuGiga' in pageStructure else '' | |
print('choJuGiga: ', choJuGiga) | |
drm = choJuGiga != "usagi" | |
pages = pageStructure['pages'] if 'pages' in pageStructure else [] | |
if len(pages) == 0: | |
print("No pages found") | |
sys.exit(1) | |
pageIndex = 0 | |
for page in pages: | |
if 'src' in page: | |
src = page['src'] | |
print(src) | |
pageIndex += 1 | |
outFile = os.path.join(destination, f"{pageIndex:04d}") | |
dlImage(src, outFile, drm) | |
else: | |
print('could not find pageStructure from json response') | |
sys.exit(1) | |
if nextReadableProductUri != None: | |
print("Next URI: ", nextReadableProductUri) | |
else: | |
print('could not find readableProduct from json response') |
I shot you an email :)
Hey!! I'm not sure why, but when I run the program according to the usage, it always returns the line "usage: shonenripperjson.py destination folder>", whether I'm logged in or not. It doesn't launch the program to get images from manga chapters.
Hey!! I'm not sure why, but when I run the program according to the usage, it always returns the line "usage: shonenripperjson.py destination folder>", whether I'm logged in or not. It doesn't launch the program to get images from manga chapters.
Did you run it with both the required parameters?
python shonenripperjson.py https://pocket.shonenmagazine.com/episode/3269754496353313267 destfolder/
Hey!! I'm not sure why, but when I run the program according to the usage, it always returns the line "usage: shonenripperjson.py destination folder>", whether I'm logged in or not. It doesn't launch the program to get images from manga chapters.
Did you run it with both the required parameters?
python shonenripperjson.py https://pocket.shonenmagazine.com/episode/3269754496353313267 destfolder/
Hey!! I'm not sure why, but when I run the program according to the usage, it always returns the line "usage: shonenripperjson.py destination folder>", whether I'm logged in or not. It doesn't launch the program to get images from manga chapters.
@dinhhung893
Did you run it with both the required parameters?
python shonenripperjson.py https://pocket.shonenmagazine.com/episode/3269754496353313267 destfolder/
Ah, you need to encase the file path in quotes since it contains a space. Otherwise python will think it's a third parameter.
python shonenripperjson.py https://pocket.shonenmagazine.com/episode/3269754496353313267 "C:\Users\dinhh\Downloads\New Folder"
Hey!! I'm not sure why, but when I run the program according to the usage, it always returns the line "usage: shonenripperjson.py destination folder>", whether I'm logged in or not. It doesn't launch the program to get images from manga chapters.
@dinhhung893
Did you run it with both the required parameters?
python shonenripperjson.py https://pocket.shonenmagazine.com/episode/3269754496353313267 destfolder/
Ah, you need to encase the file path in quotes since it contains a space. Otherwise python will think it's a third parameter.
python shonenripperjson.py https://pocket.shonenmagazine.com/episode/3269754496353313267 "C:\Users\dinhh\Downloads\New Folder"
Oh, thanks!! I'm still dumb about these thing. But now it works great 😁👍
hi the script is not working can you pls fix it?
hi the script is not working can you pls fix it?
@qiaant I tried it and it seems to be working. Can you provide a bit more information?
I'm sorry this is a stupid question from a beginner, but can I ask you how do I use it?
I'm sorry this is a stupid question from a beginner, but can I ask you how do I use it?
First you install the requirements with pip like the following (on windows):
pip3 install requests
pip3 install Pillow
Then find out the URL of the pocket chapter you want to download and copy it. Paste it after the python command to run the script, and add an output folder for the result:
python shonenripperjson.py https://pocket.shonenmagazine.com/episode/10834108156703718626 output/
If you need to login to download purchased chapters, modify your script and put your username and password where it says to do so, and set the login variable to True
login = True # Set this to True if you want to login
username = "your email here"
password = "your password"
Hi I notced when I used the script today that it sudenly put a black bar the same size onto every page in the right side. Covering art and making spreads look bad. Any idea what could cause this? Haven't had any problems using the script in the past.
Hi, @jonaselz
Not sure why this would happen. Does this happen with only some manga or some chapters of a manga, or does it happen to you with everything now?
Can you link to some chapter you're having problems with (preferably available for free), so I can take a look?
Hi @Nominom sorry for the late reply. It seems it only happens with some titles. For some reason
Found a few free ones that gives me me the black bar.
https://pocket.shonenmagazine.com/episode/10834108156634258465
https://pocket.shonenmagazine.com/episode/3270375685326280731
https://pocket.shonenmagazine.com/episode/4856001361109256286
https://pocket.shonenmagazine.com/episode/3269754496643321245
Oh, hey!! You can use my Pocket Shonen Magazine account to test the program, I already bought a manga chapter in it, if you want to test more you can buy another chapter from another manga. You can contact me via email: dinhhung893@gmail.com or you can reply to the message with the content of your email so I can send my account to you! I just want the program to work flawlessly when you publish the code on Github.