Skip to content

Instantly share code, notes, and snippets.

@marcymon97
Created April 10, 2021 15:37
Show Gist options
  • Select an option

  • Save marcymon97/9b9388844f4a0a1b88f8860cbecaf8c6 to your computer and use it in GitHub Desktop.

Select an option

Save marcymon97/9b9388844f4a0a1b88f8860cbecaf8c6 to your computer and use it in GitHub Desktop.
Simple python script to download portuguese One Piece manga chapters from onepieceex.net. Remember to support the translators!
# Description: Simple python script to download portuguese One Piece manga chapters from onepieceex.net
# Usage: Just execute the script with python and tell the chapter number as the first and only parameter.
# The chapter will then be downloaded and saved as .cbz on the same folder as the script.
# Author: Márcio Medeiros
# Version 1.0
import sys
import os
import shutil
import requests
import re
import json
import zipfile
def zipdir(path, ziph):
for root, dirs, files in os.walk(path):
for file in files:
ziph.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), os.path.join(path, '..')))
def clear():
if os.name == 'nt':
_ = os.system('cls')
else:
_ = os.system('clear')
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
clear()
print(bcolors.HEADER)
print("=-=-One Piece Ex Manga downloader-=-=")
print(bcolors.ENDC)
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'}
url = "http://onepieceex.net/"
complementUrl = url + "mangas/leitor/"
if len(sys.argv)<=1:
print("chapter not informed")
sys.exit()
chapter = sys.argv[1]
regex = "(paginasLista = .+?(\";))"
print(complementUrl + chapter)
response = requests.get(complementUrl + chapter, headers=headers)
paginasLista = re.findall(regex, response.text)
if len(paginasLista) <= 0:
print("Chapter not found")
else:
lista = paginasLista[0][0]
cleanLista = re.findall("(\".+\")",lista)
if len(cleanLista) <= 0:
print("Coudn't find page list")
else:
l = cleanLista[0]
x = json.loads(l)
y = json.loads(x)
paginasLista = []
for obj in y:
paginasLista.append(url+y[obj])
# print(paginasLista)
try:
shutil.rmtree(chapter)
except OSError:
print ("Deletion of the directory %s failed" % chapter)
else:
print ("Successfully deleted the directory %s" % chapter)
try:
os.makedirs(chapter)
except OSError:
print ("Creation of the directory %s failed" % chapter)
else:
print ("Successfully created the directory %s" % chapter)
headers = {
'authority': 'onepieceex.net',
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.9,pt-BR;q=0.8,pt;q=0.7',
'cache-control': 'no-cache',
'dnt': "1",
'pragma': 'no-cache',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'
}
for page in paginasLista:
filename = page.rsplit('/',1)[1]
print("downloading "+filename)
response = requests.get(page, headers=headers)
if response.status_code != 200:
print("Error downloading file: "+filename)
print("headers: "+response.headers)
exit()
open(chapter +'/'+ filename, 'wb').write(response.content)
print("Finished Downloading")
print("zipping")
zipf = zipfile.ZipFile(chapter+'.cbz', 'w', zipfile.ZIP_DEFLATED)
zipdir(chapter+'/', zipf)
zipf.close()
try:
shutil.rmtree(chapter)
except OSError:
print ("Deletion of the directory %s failed" % chapter)
else:
print ("Successfully deleted the directory %s" % chapter)
print(bcolors.OKGREEN+"Finished!"+bcolors.ENDC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment