Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #171 Windows: Manga Names with invalid characters prevent creatio… #172

Merged
merged 2 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions comic_dl/globalFunctions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re

import cfscrape
import requests
Expand All @@ -14,7 +15,6 @@
import img2pdf
import math


class GlobalFunctions(object):
def page_downloader(self, manga_url, scrapper_delay=5, **kwargs):
headers = kwargs.get("headers")
Expand Down Expand Up @@ -176,7 +176,7 @@ def conversion(self, directory_path, conversion, delete_files, comic_name, chapt
print(DirectoryDeleteError)
pass
print("Deleted the files...")

def addOne(self, comicUrl):
# @dsanchezseco
# edit config.json to update nextChapter value
Expand All @@ -197,3 +197,10 @@ def prepend_zeroes(self, current_chapter_value, total_images):
"""
max_digits = int(math.log10(int(total_images))) + 1
return str(current_chapter_value).zfill(max_digits)

@staticmethod
def create_file_directory(chapter_number, comic_name):
comic = re.sub('[^\w\-_. \[\]]', '-', comic_name)
chapter = re.sub('[^\w\-_. \[\]]', '-', chapter_number)
file_directory = comic + os.sep + chapter + os.sep
return file_directory
3 changes: 1 addition & 2 deletions comic_dl/manga_eden/mangaChapterDownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def __init__(self, page_id, download_directory, **kwargs):
else:
pass

file_directory = str(self.manga_name) + '/' + str(self.chapter_number) + "/"

file_directory = globalFunctions.GlobalFunctions().create_file_directory(self.chapter_number, self.manga_name)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))

if not os.path.exists(directory_path):
Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/acQQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def single_chapter(self, comic_url, comic_name, download_directory, conversion,
img_list.append(img_url['url'])
logging.debug("img_list : %s" % img_list)

file_directory = str(comic_name) + '/' + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)

# directory_path = os.path.realpath(file_directory)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))
Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/batoto.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ def single_chapter(self, comic_url, download_directory, conversion, delete_files
if not comic_name or not chapter_number or not file_directory:
comic_name = self.name_cleaner(re.search(r'https://bato.to/comic/_/comics/(.*?)">', str(page_source)).group(1))
chapter_number = re.sub('[^0-9]+', '', str(re.search(r'Ch\.(.*?)\:', str(page_source)).group(1)))
file_directory = str(comic_name) + os.sep + str(chapter_number) + os.sep
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
directory_path = os.path.realpath(str(download_directory) + os.sep + str(file_directory))

if not os.path.exists(directory_path):
Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/comicNaver.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def single_chapter(self, comic_url, comic_name, download_directory, conversion,
image_list = list(re.findall(img_regex, str(source)))
logging.debug("Image List : %s" % image_list)

file_directory = str(comic_name) + '/' + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
# directory_path = os.path.realpath(file_directory)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))
print("Directory Path : %s" % str(directory_path))
Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/comicextra.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def single_chapter(self, comic_url, download_directory, conversion, delete_files
total_pages = len(img_list)
# print(total_pages)

file_directory = str(comic_name) + '/' + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))

if not os.path.exists(directory_path):
Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/foolSlide.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def single_chapter(self, chapter_url, comic_name, download_directory, conversion
img_links = self.image_links(source)
logging.debug("Img Links : %s" % img_links)

file_directory = str(comic_name) + '/' + "Chapter " + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
# directory_path = os.path.realpath(file_directory)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))

Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/kissmanga.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def single_chapter(self, comic_url, comic_name, download_directory):
# print(source)
image_list = re.findall(r"lstImages\.push\(wrapKA\(\"(.*?)\"\)\);", str(source))
#
file_directory = str(comic_name) + '/' + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
directory_path = os.path.realpath(file_directory)

if not os.path.exists(file_directory):
Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/mangaFox.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def single_chapter(self, comic_url, comic_name, download_directory, conversion,
current_page_number = int(str(re.search(r'current_page=(.*?)\;', str(source)).group(1)).strip())
last_page_number = int(str(re.search(r'total_pages=(.*?)\;', str(source)).group(1)).strip())

file_directory = str(comic_name) + '/' + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
# directory_path = os.path.realpath(file_directory)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))

Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/mangaHere.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def single_chapter(self, comic_url, comic_name, download_directory, conversion,
source, cookies_main = globalFunctions.GlobalFunctions().page_downloader(manga_url=comic_url)
last_page_number = str(re.search(r'total_pages\ \=\ (.*?) \;', str(source)).group(1)).strip()

file_directory = str(comic_name) + '/' + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
# directory_path = os.path.realpath(file_directory)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))

Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/mangaReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def single_chapter(self, comic_url, comic_name, download_directory, conversion,
total_pages = int(str(re.search(r'</select> of (.*?)</div>', str(source)).group(1)).strip())
# print("Total Pages : {0}".format(total_pages))

file_directory = str(comic_name) + '/' + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))

if not os.path.exists(directory_path):
Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/mangaRock.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ def single_chapter(self, chapter_id, comic_name, chapter_number, download_direct
source, cookies = globalFunctions.GlobalFunctions().page_downloader(manga_url=image_api_link)
json_parse = json.loads(str(source))

file_directory = str(comic_name) + os.sep + str(chapter_number) + os.sep
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)

directory_path = os.path.realpath(str(download_directory) + os.sep + str(file_directory))

Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/omgBeauPeep.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def single_chapter(self, comic_url, comic_name, download_directory, conversion,

last_page_number = int(re.search(r"</select> of (\d+) <a", str(source)).group(1))

file_directory = str(comic_name) + '/' + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
# directory_path = os.path.realpath(file_directory)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))

Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/rawSenManga.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def single_chapter(self, comic_url, comic_name, download_directory, conversion,

last_page_number = int(str(re.search(r"</select> of (\d+) <a", str(source)).group(1)).strip())

file_directory = str(comic_name) + '/' + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
# directory_path = os.path.realpath(file_directory)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))

Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/readComicBooksOnline.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def single_chapter(self, comic_url, comic_name, download_directory, conversion,
first_image_link = image_download_link
img_list.append(image_download_link)

file_directory = str(comic_name) + '/' + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))

if not os.path.exists(directory_path):
Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/readComicsIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def single_chapter(self, comic_url, comic_name, download_directory, conversion,
for a in x:
img_list.append(str(a['src']).strip())

file_directory = str(comic_name) + '/' + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))

if not os.path.exists(directory_path):
Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/readComicsWebsite.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def single_chapter(self, comic_url, comic_name, download_directory, conversion,
for image_number in range(1, last_chapter + 1):
img_list.append("http://www.readcomics.website/uploads/manga/{0}/chapters/{1}/{2}.jpg".format(name_of_manga, chapter_number, str(image_number).zfill(2)))

file_directory = str(comic_name) + '/' + chapter_number + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))

if not os.path.exists(directory_path):
Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/readcomicOnlineto.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def single_chapter(self, comic_url, comic_name, download_directory, conversion,

image_list = re.findall(r"lstImages.push\(\"(.*?)\"\);", str(source))

file_directory = str(comic_name) + '/' + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
# directory_path = os.path.realpath(file_directory)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))

Expand Down
3 changes: 1 addition & 2 deletions comic_dl/sites/stripUtopia.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def single_chapter(self, source, comic_url, comic_name, download_directory, conv
img_list = re.findall(r'href="(.*?)"', str(short_content))
chapter_number = str(str(comic_url).split("/")[-1]).replace(".html", "")

file_directory = str(comic_name) + '/' + str(chapter_number) + "/"
file_directory = file_directory.replace(":", "-")
file_directory = globalFunctions.GlobalFunctions().create_file_directory(chapter_number, comic_name)
directory_path = os.path.realpath(str(download_directory) + "/" + str(file_directory))

globalFunctions.GlobalFunctions().info_printer(comic_name, chapter_number, total_chapters=len(img_list))
Expand Down