def download(self):
        # TODO: Clean this up
        self.pre_process()
        logger.info(self.path)

        # TODO: Use pathlib. Break into functions
        util.make_dir(self.path.rsplit('/', 1)[0])
        self.check_if_exists()

        self.start_time = time.time()
        self.downloaded = 0
        self._download()
        self.post_process()
Esempio n. 2
0
    def download(self, url, path, options=None):
        # TODO: Clean this up
        self.pre_process()
        self.url = url
        logger.info(path)

        # TODO: Use pathlib. Break into functions
        self.path = path
        util.make_dir(path.rsplit('/', 1)[0])

        if options is not None:
            self.options = {**options, **self.options}

        self.check_if_exists()

        self.start_time = time.time()
        self.downloaded = 0
        self._download()

        self.post_process()
    def __init__(self, source, path, force, range_size=None):
        logging.info(path)

        self.url = source.stream_url
        self.referer = source.referer
        self.path = path
        self.range_size = range_size

        util.make_dir(path.rsplit('/', 1)[0])

        self.chunksize = 16384

        r = requests.get(self.url, stream=True)

        self.total_size = int(r.headers['Content-length'])
        if os.path.exists(path):
            if abs(os.stat(path).st_size - self.total_size) < 10 and not force:
                logging.warning('File already downloaded. Skipping download.')
                return
            else:
                os.remove(path)
Esempio n. 4
0
    def download(self, force=False, path=None, format='{anime_title}_{ep_no}'):
        logging.info('Downloading {}'.format(self.pretty_title))
        if format:
            file_name = util.format_filename(format, self) + '.mp4'

        if path is None:
            path = './' + file_name
        if path.endswith('.mp4'):
            path = path
        else:
            path = os.path.join(path, file_name)

        logging.info(path)

        r = requests.get(self.source().stream_url, stream=True)

        util.make_dir(path.rsplit('/', 1)[0])

        total_size = int(r.headers['Content-length'])
        downloaded, chunksize = 0, 16384
        start_time = time.time()

        if os.path.exists(path):
            if os.stat(path).st_size == total_size and not force:
                logging.warning('File already downloaded. Skipping download.')
                return
            else:
                os.remove(path)

        if r.status_code == 200:
            with open(path, 'wb') as f:
                for chunk in r.iter_content(chunk_size=chunksize):
                    if chunk:
                        f.write(chunk)
                        downloaded += chunksize
                        write_status((downloaded), (total_size), start_time)