Esempio n. 1
0
    def _go_next_image(self):
        """
        Downloads next image if not downloaded, open it, download the next image
        in the background
        """
        # IDEAL: image prompt should not be blocked while downloading
        # But I think delaying the prompt is better than waiting for an image
        # to download when you load it

        # First time from gallery; download next image
        if self.data.img_post_page_num == 1:
            download.async_download_spinner(self.data.large_dir,
                                            [self.data.current_url()])

        utils.display_image_vp(self.data.filepath())

        # Downloads the next image
        try:
            next_img_url = self.data.next_img_url()
        except IndexError:  # Last page
            pass
        else:  # No error
            self.data.downloaded_images.append(
                pure.split_backslash_last(next_img_url))
            download.async_download_spinner(self.data.large_dir,
                                            [next_img_url])

        print(
            f'Page {self.data.img_post_page_num+1}/{self.data.number_of_pages}'
        )
Esempio n. 2
0
def view_post_mode(image_id):
    """
    Fetch all the illust info, download it in the correct directory, then display it.
    If it is a multi-image post, download the next image
    Else or otherwise, open image prompt
    """
    print('Fetching illust details...')
    try:
        post_json = api.myapi.protected_illust_detail(image_id)['illust']
    except KeyError:
        print('Work has been deleted or the ID does not exist!')
        sys.exit(1)

    idata = data.ImageJson(post_json, image_id)

    download.download_core(idata.large_dir, idata.url, idata.filename)
    utils.display_image_vp(f'{idata.large_dir}{idata.filename}')

    # Download the next page for multi-image posts
    if idata.number_of_pages != 1:
        download.async_download_spinner(idata.large_dir, idata.page_urls[:2])
        downloaded_images = list(
            map(pure.split_backslash_last, idata.page_urls[:2]))

    image = ui.Image(image_id, idata, 1, True)
    prompt.image_prompt(image)
Esempio n. 3
0
    def _jump(self):
        """Downloads next image if not downloaded, display it, prefetch next"""
        # FIXME: thread might download to the user's current dir.
        # Pass in path to api.download as planned
        threading.Thread(target=self._prefetch_next_image).start()
        if not (self.download_path / self.image_filename).is_dir():
            download.async_download_spinner(self.download_path,
                                            [self.current_url])

        os.system('clear')

        lscat.icat(self.filepath)

        print(f'Page {self.page_num+1}/{self.number_of_pages}')
        self.start_preview()
Esempio n. 4
0
    def _jump(self) -> 'IO':
        """Downloads next image if not downloaded, display it, prefetch next"""
        # FIXME: thread might download to the user's current dir.
        # Pass in path to api.download as planned
        threading.Thread(target=self._prefetch_next_image).start()
        if not (self.download_path / self.image_filename).is_dir():
            download.async_download_spinner(self.download_path,
                                            [self.current_url])

        os.system('clear')
        lscat.api.hide(self.image)
        lscat.api.hide_all(self.preview_images)

        self.image = lscat.api.show_center(self.filepath)

        printer.print_bottom(
            f'Page {self.page_num+1}/{self.number_of_pages}',
            use_ueberzug=self.use_ueberzug,
        )
        self.start_preview()
Esempio n. 5
0
 def _prefetch_next_image(self):
     with funcy.suppress(IndexError):
         next_img_url = self.next_img_url
     if next_img_url:
         download.async_download_spinner(self.download_path, [next_img_url])