def updates(): favoured = favourite.all() updates = {} with Loader("Initialize") as loader: for f_manga in favoured: loader.message = f'Parsing {f_manga.title}' # a bit of sanity check if f_manga.title not in manga.databases.keys(): continue d_database = manga.databases[f_manga.title].get_chapter_list() _, d_online = f_manga.parse() # compare if len(d_database) == len(d_online): continue d_urls = [chapter.url for chapter in d_database] for o_chapter in d_online: if o_chapter.url not in d_urls: if f_manga not in updates.keys(): updates[f_manga] = [] updates[f_manga].append(o_chapter) loader.message = 'Update check' if not updates.keys(): print(title('No updates.')) return UpdatesMenu(updates).prompt()
def prompt(self): # choose a manga manga_title = self._menu.prompt() if manga_title == 'Exit': return # construct new checbox menu for this checkbox_choices = [{ 'name': chapter.title } for chapter in self.informative[manga_title]] selected_names = prompt( dict(type='checkbox', name='updates', message=manga_title, choices=checkbox_choices))['updates'] # nothing selected if not selected_names: return selected = list( filter(lambda chapter: chapter.title in selected_names, self.informative[manga_title])) manga = list( filter( lambda key: self.updates[key] == self.informative[manga_title], self.updates.keys()))[0] with Loader("Parse Info"): manga, all_chapters = manga.parse() from modules.database.models.manga.download import selective_download selective_download(manga, all_chapters, selected, update=True)
def direct(): answer = vinput('Enter the url: ') with Loader("Parse Info"): parsed_manga, chapters = models.Manga('', answer).parse() return parsed_manga, chapters
def select_and_download(manga, chapters=None): if not chapters: with Loader("Parse Info"): manga, chapters = manga.parse() exists = manga.title in saved_manga.databases.keys() if exists: with Loader("Update database"): # check database and update chapters saved_manga.databases[manga.title].update_chapter_list(chapters) # get new chapters from updated database chapters = saved_manga.databases[manga.title].get_chapter_list() # get settings s = get_settings() question = { 'type': 'checkbox', 'name': 'chapters', 'message': 'Select chapters to download', 'choices': [ dict(name=chapter.title, disabled='Downloaded' if s.disable_downloaded and chapter.downloaded else False) for chapter in chapters ], } answers = prompt(question) if not answers['chapters']: return selected = [] for chapter in chapters: if chapter.title in answers['chapters']: selected.append(chapter) selective_download(manga, chapters, selected, update=not exists)
def reset(): cont = confirm('This will REMOVE all your data and close app, would you still like to continue?', default=False) if cont: with Loader("Erase data"): # unlink all databases so they are not being used anymore base.close() meta.close() for key, database in manga.databases.items(): database.close() # unlink the files and exit shutil.rmtree(base_directory) sys.exit(1)
def chapters_check(manga_list): unsuccessful_retrievals = [] with Loader('Chapter check') as loader: # for all manga get list of downloaded chapters for obj in manga_list: manga = Manga.fromdict(obj) loader.message = f'Checking {manga.title}' manga, chapter_list = manga.parse() try: mangabase.databases[manga.title].update_chapter_list(chapter_list) except KeyError: unsuccessful_retrievals.append(manga) continue try: chapter_directories = list(manga.path().iterdir()) except FileNotFoundError: # file is in database but not in filesystem, so entry is being removed loader.print(f'[{visualize(False)}] {manga.title} NotFound: Removed from database') base.remove(Query().url == manga.url) # for each chapter in file system for cpath in chapter_directories: chapter = Chapter(cpath.parts[-1], '') filtered = list(filter(lambda val: val.title == chapter.title, chapter_list)) if len(filtered) <= 0: continue # title based update mangabase.databases[manga.title].chapters.update({'downloaded': True}, Query().url == filtered[0].url) loader.message = 'Chapter check' if len(unsuccessful_retrievals) > 0: loader.fail(f'information retrieval of {len(unsuccessful_retrievals)} unsuccessful') return unsuccessful_retrievals
def mangas_check(): unsuccessful_retrievals = [] with Loader('Getting started') as loader: for manga in Manga.directory.iterdir(): manga = Manga(manga.parts[-1], '') url = '' loader.message = f'try to get {manga.title} url from database' result = base.search(Query().title == manga.title) if len(result) > 0 and result[0]['url'] != '': url = result[0]['url'] else: loader.message = f'try to get {manga.title} url from online' try: codec = MKCodec() codec.search(codec.search_prefix + manga.title) if len(codec.search_result) > 0: url = codec.search_result[0]['href'] except Exception as e: loader.print(e) url = '' manga.url = url if url != '': # update database add_manga(manga.title, url, manga.path()) mangabase.databases[manga.title].set_info(manga) else: unsuccessful_retrievals.append(manga) loader.message = 'Manga check' if len(unsuccessful_retrievals) > 0: loader.fail(f'information retrieval of {len(unsuccessful_retrievals)} unsuccessful') return unsuccessful_retrievals
def selective_download(manga, chapters, to_download, update=False): """ url (string): manga path from mangakakalot.com starting_chapter (int): download start (inclusive) ending_chapter (int): download end (exclusive) chapter_list (list): optional returns None """ # fetch settings settings = get_settings() manga_path = manga.path() # Create directories Manga.mkdir_base() if settings.is_compositing(): composition.dir.create_directories(manga) # update base database modules.database.mangas.add_manga(manga.title, manga.url, manga_path) manga_base = modules.database.mangas.manga.databases[manga.title] # update manga info manga_base.set_info(manga) if update: with Loader("Update database"): # update chapter list manga_base.update_chapter_list(chapters) # add mangas to waiting list resume.new(manga, to_download) # download each chapter loop for chapter in to_download: chapter_directory = manga_path / Path(chapter.title) # parse info print() with Loader(chapter.title): # create chapter dir chapter_directory.mkdir(parents=True, exist_ok=True) page_list = chapter.pages() # download pages for page in page_list: save_image(page, chapter_directory) # save image # on chapter download complete # update chapters left to download, set downloaded to true resume.update(chapter.url) manga_base.chapters.update({'downloaded': True}, Query().url == chapter.url) # convert to pdf if settings.pdf: with Loader( f'Convert {chapter_directory.parts[-1]} to pdf') as loader: try: dir_to_pdf(chapter_directory, manga_path / composition.directories.pdf) except OSError as e: loader.fail(e) # convert to jpg if settings.jpg: with Loader( f'Convert {chapter_directory.parts[-1]} to jpg') as loader: try: dir_to_jpg(chapter_directory, manga_path / composition.directories.jpg) except OSError as e: loader.fail(e) # on download task complete Completer('Downloads complete').init().complete() # download task complete notification Notification( title='Download task complete', description=f'{manga.title} | {len(to_download)} chapters downloaded' ).send() print()
if menuoption['dialog'] == 0: try: dialog = MangaDialog(search()) dialog.prompt() except Exception: traceback.print_exc() elif menuoption['dialog'] == 1: try: manga, chapters = direct() dialog = MangaDialog(manga) dialog.prompt() except Exception: traceback.print_exc() elif menuoption['dialog'] == 2: # generate manga tree with Loader('Generating tree'): manga_manager.generate_tree() # generate html pages using the tree with Loader('Generating html files.'): html_manager.generate_web(manga_manager.tree) if html_manager.open(): break elif menuoption['dialog'] == 4: compose_menu() elif menuoption['dialog'] == 5: database.actions.menu() elif menuoption['dialog'] == 6: settings.change() elif menuoption['dialog'] == 7: