def display_page(page, rowspaces, cols, left_shifts, path): with cd(path): for (index, space) in enumerate(rowspaces): for col in cols: Image(page[index][col]).thumbnail(310).show(align='left', x=left_shifts[col], y=space)
def download_core(large_dir, url, filename, try_make_dir=True): """Downloads one url, intended for single images only""" if try_make_dir: os.makedirs(large_dir, exist_ok=True) if not Path(filename).is_file(): print(' Downloading illustration...', flush=True, end='\r') with pure.cd(large_dir): downloadr(url, filename, None)
def show_artist_illusts(path, renderer='lscat', **kwargs): """ Use specified renderer to display all images in the given path Default is "lscat"; can be "lscat old" or "lsix" (needs to install lsix first) """ if renderer != 'lscat': lscat_path = os.getcwd() with pure.cd(path): if renderer == 'lscat': lscat.Gallery(path, **kwargs).render() elif renderer == 'lscat old': os.system(f'{Path(lscat_path).parent}/legacy/lscat') elif renderer == 'lsix': os.system(f'{Path(lscat_path).parent}/legacy/lsix')
def _download_pbar(self, preview_path): pbar = tqdm(total=len(self.data.all_urls()), smoothing=0) download.async_download_core(preview_path, self.data.all_urls(), rename_images=True, file_names=self.data.all_names( self._page_num), pbar=pbar) pbar.close() # Move artist profile pics to their correct dir to_move = sorted(os.listdir(preview_path))[:self.data.splitpoint()] with pure.cd(self.download_path): [ os.rename(f'{self.download_path}/previews/{pic}', f'{self.download_path}/{pic}') for pic in to_move ]
def async_download_core(download_path, urls, rename_images=False, file_names=None, pbar=None): """ Rename files with given new name if needed. Submit each url to the ThreadPoolExecutor, so download and rename are concurrent """ oldnames = list(map(pure.split_backslash_last, urls)) if rename_images: newnames = map(pure.prefix_filename, oldnames, file_names, range(len(urls))) newnames = list(newnames) else: newnames = oldnames filtered = itertools.filterfalse(os.path.isfile, newnames) oldnames = itertools.filterfalse(os.path.isfile, oldnames) helper = downloadr(pbar=pbar) os.makedirs(download_path, exist_ok=True) with pure.cd(download_path): with ThreadPoolExecutor(max_workers=len(urls)) as executor: executor.map(helper, urls, oldnames, filtered)
def filter_jpg(path): with cd(path): return sorted(filter(is_image, os.listdir('.')))
def test_cd(): current_dir = os.getcwd() with pure.cd(current_dir): testdir = os.getcwd() assert testdir == os.getcwd()