Skip to content

Commit

Permalink
Fix for #89
Browse files Browse the repository at this point in the history
Fixes #89
  • Loading branch information
Xonshiz committed Jan 22, 2018
1 parent 42913e6 commit 08d5daf
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 24 deletions.
5 changes: 4 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,7 @@
- By default, script will not delete the file [2018.01.19]
- Fix for #79 [2018.01.19]
- Fix for #80 [2018.01.19]
- Fix for #90 [2018.01.20]
- Fix for #90 [2018.01.20]
- Support for Auto Download Included [2018.01.21] (@dsanchezseco)
- Error Log creation to be done in the desired download directory now. [2018.01.22]
- Fix for #89 [2018.01.22]
2 changes: 1 addition & 1 deletion comic_dl/__version__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__version__ = "2018.01.20"
__version__ = "2018.01.22"
8 changes: 5 additions & 3 deletions comic_dl/comic_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, argv):
parser.add_argument('-a', '--auto', action='store_true', help='Download new chapters automatically (needs config file!)')
parser.add_argument('-c', '--config', action='store_true', help='Generates config file for autodownload function')
parser.add_argument('-dd', '--download-directory', nargs=1,
help='Decides the download directory of the comics/manga.')
help='Decides the download directory of the comics/manga.', default=os.getcwd())
parser.add_argument('-rn', '--range', nargs=1,
help='Specifies the range of chapters to download.', default='All')
parser.add_argument('--convert', nargs=1,
Expand Down Expand Up @@ -80,9 +80,11 @@ def __init__(self, argv):
try:
os.remove("Error_Log.log")
except Exception as VerboseError:
print(VerboseError)
# print(VerboseError)
pass
logging.basicConfig(format='%(levelname)s: %(message)s', filename="Error_Log.log", level=logging.DEBUG)
logging.basicConfig(format='%(levelname)s: %(message)s',
filename=str(args.download_directory[0]) + str(os.sep) + "Error_Log.log",
level=logging.DEBUG)
logging.debug("Arguments Provided : %s" % args)
logging.debug("Operating System : %s - %s - %s" % (platform.system(),
platform.release(),
Expand Down
2 changes: 1 addition & 1 deletion comic_dl/sites/readComicsWebsite.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def full_series(self, comic_url, comic_name, sorting, download_directory, chapte
indexes = [x for x in range(starting, ending)]

all_links = [all_links[x] for x in indexes][::-1]
#if chapter range contains "__EnD__" write new value to config.json
# if chapter range contains "__EnD__" write new value to config.json
if chapter_range.split("-")[1] == "__EnD__":
globalFunctions.GlobalFunctions().saveNewRange(comic_url,len(all_links))
else:
Expand Down
39 changes: 22 additions & 17 deletions comic_dl/sites/readcomicOnlineto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import os
import logging
from bs4 import BeautifulSoup


class ReadComicOnlineTo(object):
Expand All @@ -18,11 +19,9 @@ def __init__(self, manga_url, download_directory, chapter_range, **kwargs):
self.image_quality = kwargs.get("image_quality")
self.comic_name = self.name_cleaner(manga_url)



url_split = str(manga_url).split("/")

if len(url_split) in [5]: # Sometimes, this value came out to be 6, instead of 5. Hmmmmmmmm weird.
if len(url_split) in [5]: # Sometimes, this value came out to be 6, instead of 5. Hmmmmmmmm weird.
# Removing "6" from here, because it caused #47
self.full_series(comic_url=manga_url.replace("&readType=1", ""), comic_name=self.comic_name,
sorting=self.sorting, download_directory=download_directory, chapter_range=chapter_range,
Expand All @@ -36,14 +35,13 @@ def __init__(self, manga_url, download_directory, chapter_range, **kwargs):
delete_files=delete_files)

def single_chapter(self, comic_url, comic_name, download_directory, conversion, delete_files):
# print("Received Comic Url : {0}".format(comic_url))
# print("Received Comic Url : {0}".format(comic_url))
chapter_number = str(comic_url).split("/")[5].split("?")[0].replace("-", " - ")

source, cookies = globalFunctions.GlobalFunctions().page_downloader(manga_url=comic_url)

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


file_directory = str(comic_name) + '/' + str(chapter_number) + "/"

# directory_path = os.path.realpath(file_directory)
Expand All @@ -60,7 +58,7 @@ def single_chapter(self, comic_url, comic_name, download_directory, conversion,
for link in image_list:
link = link.replace("\\", "")
# file_name = str(link).split("/")[-1].strip()
#file_name = "0" + str(image_list.index(link)) + ".jpg"
# file_name = "0" + str(image_list.index(link)) + ".jpg"

if len(str(image_list.index(link))) < len(str(image_len)):
number_of_zeroes = len(str(image_len)) - len(str(image_list.index(link)))
Expand All @@ -73,7 +71,7 @@ def single_chapter(self, comic_url, comic_name, download_directory, conversion,
file_name = str(image_list.index(link)) + ".jpg"

logging.debug("Image Link : %s" % link)
link = link.replace("=s1600", "=s0").replace("/s1600", "/s0") # Change low quality to best.
link = link.replace("=s1600", "=s0").replace("/s1600", "/s0") # Change low quality to best.

if str(self.image_quality).lower().strip() in ["low", "worst", "bad", "cancer", "mobile"]:
link = link.replace("=s0", "=s1600").replace("/s0", "/s1600")
Expand All @@ -92,16 +90,24 @@ def name_cleaner(self, url):
return manga_name

def full_series(self, comic_url, comic_name, sorting, download_directory, chapter_range, conversion, delete_files):
series_name_raw = str(comic_url).split("/")[3].strip()
source, cookies = globalFunctions.GlobalFunctions().page_downloader(manga_url=comic_url)

link_regex = "<a href=\"/" + str(series_name_raw) + "/(.*?)\""
all_links = []

listing_table = source.find_all("table", {"class": "listing"})
# print(listing_table)

for elements in listing_table:
x = elements.findAll('a')
for a in x:
all_links.append(str(a['href']).strip())

"""Readcomiconline.to shows the chapters in the Descending order. The 1st chapter is at the bottom, hence, at
the end of the list. So, we'll reverse the list, to perform the ranging functionality properly.
This is a fix for issues like #74.
"""
all_links = [rev_link for rev_link in reversed(list(re.findall(link_regex, str(source))))]
all_links.pop() # RCO changed their source and added one more link that matches the regex. I need to change this regex anyway, but, this is a quick fix.
all_links.reverse()

# print("All Links : {0}".format(all_links))

logging.debug("All Links : %s" % all_links)
Expand All @@ -120,24 +126,23 @@ def full_series(self, comic_url, comic_name, sorting, download_directory, chapte
indexes = [x for x in range(starting, ending)]

all_links = [all_links[x] for x in indexes][::-1]
#if chapter range contains "__EnD__" write new value to config.json
# if chapter range contains "__EnD__" write new value to config.json
if chapter_range.split("-")[1] == "__EnD__":
globalFunctions.GlobalFunctions().saveNewRange(comic_url,len(all_links))
globalFunctions.GlobalFunctions().saveNewRange(comic_url, len(all_links))
else:
all_links = all_links

if str(sorting).lower() in ['new', 'desc', 'descending', 'latest']:
for chap_link in all_links:
chap_link = "http://readcomiconline.to/Comic/" + chap_link
chap_link = "http://readcomiconline.to" + chap_link
self.single_chapter(comic_url=chap_link, comic_name=comic_name, download_directory=download_directory,
conversion=conversion, delete_files=delete_files)

elif str(sorting).lower() in ['old', 'asc', 'ascending', 'oldest', 'a']:
for chap_link in all_links[::-1]:
chap_link = "http://readcomiconline.to/Comic/" + chap_link
chap_link = "http://readcomiconline.to" + chap_link
self.single_chapter(comic_url=chap_link, comic_name=comic_name, download_directory=download_directory,
conversion=conversion, delete_files=delete_files)

print("Finished Downloading")
return 0

5 changes: 4 additions & 1 deletion docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,7 @@
- By default, script will not delete the file [2018.01.19]
- Fix for #79 [2018.01.19]
- Fix for #80 [2018.01.19]
- Fix for #90 [2018.01.20]
- Fix for #90 [2018.01.20]
- Support for Auto Download Included [2018.01.21] (@dsanchezseco)
- Error Log creation to be done in the desired download directory now. [2018.01.22]
- Fix for #89 [2018.01.22]

0 comments on commit 08d5daf

Please sign in to comment.