def downloader(self, url, counter, parser): # Check if we have the Download folder helper.createFolder(self.downloadfolder) imagepath = self.downloadfolder + "/" + str( "{0:0=3d}".format(counter)) + ".png" tempdl = self.downloadfolder + "/" + str( "{0:0=3d}".format(counter)) + ".tmp" # Download the image! f = open(tempdl, 'wb') f.write(requests.get(parser(url)).content) f.close() # If everything is alright, write image to final name os.rename(tempdl, imagepath) # Cleanse image, remove footer # # I have borrowed this code from the kmanga project. # https://github.com/aplanas/kmanga/blob/master/mobi/mobi.py#L416 # Thanks a lot to Alberto Planas for coming up with it! # if self.origin == "mangafox.me" or self.origin == "mangafox.la" or self.origin == "fanfox.net": logging.debug("Cleaning Mangafox Footer") img = Image.open(imagepath) _img = ImageOps.invert(img.convert(mode='L')) _img = _img.point(lambda x: x and 255) _img = _img.filter(ImageFilter.MinFilter(size=3)) _img = _img.filter(ImageFilter.GaussianBlur(radius=5)) _img = _img.point(lambda x: (x >= 48) and x) cleaned = img.crop(_img.getbbox()) if _img.getbbox() else img cleaned.save(imagepath)
def __init__(self): # Python 3 is required! if sys.version_info[0] < 3: sys.stdout.write("Sorry, requires Python 3.x, not Python 2.x\n") sys.exit(1) # Get args right at the start self.args = None if not self.args: self.read_arguments() # Load config right at the start self.config = None if not self.config: self.config = Config.load_config() logging.debug("Loaded Config:") logging.debug(self.config) # Check if Database exists, else create if not os.path.isfile(self.config["Database"]): helper.createFolder(self.config["SaveLocation"]) helper.createDB() # Check weather there are some database migrations mversion = helper.getMigrationVersion() + ".py" if self.config["DisableMigrations"] == "True": logging.debug("Migrations disabled! Current version: %s ", mversion) else: if mversion in os.listdir(os.getcwd() + "/migrations"): logging.debug("No migrations required! Current version: %s ", mversion) else: migrator.migrate()
def downloader(args): """ the downloader function """ # Make the query chapters = helper.getChapters() if args.start: logging.debug("The loop will only consider Chapters younger than 24h!") # Start Download loop! for chapter in chapters.iterator(): # Initialize Downloader class & load basic params current_chapter = Downloader() current_chapter.data_collector(chapter) # Check if the old DL location is being used and fix it! oldlocation = str(current_chapter.saveloc + current_chapter.mangatitle) newlocation = str(current_chapter.saveloc + current_chapter.manganame) if os.path.isdir(oldlocation): logging.info("Moving %s from old DL location to new one...", current_chapter.mangatitle) helper.createFolder(newlocation) move(oldlocation, newlocation) # Check if chapter needs to be downloaded if helper.verifyDownload(chapter): logging.debug("Manga %s downloaded already!", current_chapter.mangatitle) else: # Check if Download loop & Download task is selected if not args.start: current_chapter.data_processor() else: # Only start run if chapter is younger than 24h if helper.checkTime(current_chapter.chapterdate): current_chapter.data_processor() else: logging.debug("%s is older than 24h, will not be processed by daemon.", current_chapter.mangatitle)
def directDownloader(chapterids=[]): logging.debug("Following Chapters are directly converted:") logging.debug(chapterids) chapters = helper.getChaptersFromID(chapterids) # Load Users users = helper.getUsers() # Debug Users: logging.debug("Userlist:") logging.debug(users) if not chapters: logging.error("No Chapters found with said ID!") else: # Start conversion loop! for chapter in chapters: # Initialize Downloader class & load basic params current_chapter = Downloader() current_chapter.data_collector(chapter) # Check if the old DL location is being used and fix it! oldlocation = str(current_chapter.saveloc + current_chapter.mangatitle) newlocation = str(current_chapter.saveloc + current_chapter.manganame) if os.path.isdir(oldlocation): logging.info("Moving %s from old DL location to new one..." % current_chapter.mangatitle) helper.createFolder(newlocation) move(oldlocation, newlocation) # Check if chapter needs to be downloaded if helper.verifyDownload(chapter): logging.info("Manga %s downloaded already!" % current_chapter.mangatitle) else: current_chapter.data_processor()
def __init__(self): # Python 3 is required! if sys.version_info[0] < 3: sys.stdout.write("Sorry, requires Python 3.x, not Python 2.x\n") sys.exit(1) # Get args right at the start self.args = None if not self.args: self.read_arguments() # Load config right at the start self.config = None if not self.config: self.config = Config.load_config() logging.debug("Loaded Config:") logging.debug(self.config) # Check if Database exists, else create if not os.path.isfile(self.config["Database"]): helper.createFolder(self.config["SaveLocation"]) helper.createDB()