def _check_download(self, monitor, link, size, file_size, file_path): ''' Verify the downloaded file's size by means of two criteria: The content-length header sent from the hoster must match exactly. The config parameter min_size defines what is considered to be a faulty file, i.e. the link checker didn't detect the file to be invalid, but it is small enough to just be the hoster's error page. ''' if size < self._min_size: msg = 'File smaller than required ({}): {!s}' self._fail(monitor, link, msg.format(sizeof_fmt(size), monitor.release)) elif size != file_size and file_size != -1: msg = 'Filesize mismatch in download of {!s}:' self._fail(monitor, link, msg.format(monitor.release)) msg = 'Got {}, expected {}.' self.log.error(msg.format(size, file_size)) try: file_path.unlink() except IOError: msg = 'Couldn\'t delete broken download of {}.' self.log.warn(msg.format(monitor.release)) else: self._releases.update_by_id(monitor.id, download_path=str(file_path), download_date_stamp=now_unix()) self._releases.mark_episode_downloaded(monitor) return True
def parse(torr): td = Map(torr) name = '{} {}'.format(title_long, td.get('quality') | '') size = td.get('size_bytes') | 0 size_str = sizeof_fmt(str(size)) seeds = td.get('seeds') | 0 hsh = td.get('hash') | 'no_hash' magnet_link = yify_magnet(title, hsh) return SearchResult(name, size, size_str, seeds, magnet_link)
def _init_params(self): self.text = [ 'Total: {}'.format(sizeof_fmt(self.total_size)), 'Toggle [a]ll or individual files, toggle [f]lat display,' ' [r]emove or [d]ownload selected files.' ] self._type = FilePickerList self._simple = ['f', 'd', 'r'] self._enter = 'q'
def _init_params(self): self.text = [ 'Total: {}'.format(sizeof_fmt(self.total_size)), 'Download [a]ll ([z]ipped), select a directory or' ' [p]arent, toggle [s]election mode or [f]lat display' ' or [q]uit.' ] self._type = SpecifiedChoice self._simple = ['s', 'p', 'q', 'a', 'f', 'z'] self._enter = 's'
def _init_choice(self): urls = [d.url for d in self._downloaders] sizes = [d.file_size_str for d in self._downloaders] _format = '{u: <{ua}} | {s: >{sa}}' max_url = maxlen(*urls) max_size = maxlen(*sizes) lines = [ _format.format(u=u, s=s, ua=max_url, sa=max_size) for u, s in zip(urls, sizes) ] total_size = sum([d.file_size for d in self._downloaders]) text = [ 'Total: {}'.format(sizeof_fmt(total_size)), 'Download [a]ll, [m]ultiple, [n]one, a single file or [q]uit?' ] self._choice = SpecifiedChoice(lines, simple=['a', 'n', 'm', 'q'], enter='a', text_post=text, values=self._downloaders)
def _size_strings(self): return [sizeof_fmt(s) for s in self._sizes]
def size_string(self): return '{}: {} => {}'.format(self.filename, sizeof_fmt(self.size), sizeof_fmt(self.target_size))
def _print_progress(self): text = self._format(self._percent, sizeof_fmt(self._progress), self._size_string, self._rate_string) self._terminal.pop() self._terminal.push(text) self._terminal.flush()
def file_size_str(self): return sizeof_fmt(self.file_size)
def _rate_string(self): return sizeof_fmt(self._rate, prec=2) if self._have_size else '??'
def _size_string(self): return sizeof_fmt(self._file_size) if self._have_size else '??'
def __init__(self, dir, wanted, avail): from tek.tools import sizeof_fmt text = 'Not enough space in directory "{}" ({} needed, {} available)' text = text.format(dir, sizeof_fmt(wanted), sizeof_fmt(avail)) super(NotEnoughDiskSpace, self).__init__(text)
def sizeof_fmt(self): sizeof_fmt(1450000, prec=3, bi=False).should.equal('1.450 MB') sizeof_fmt(1450000, bi=True).should.equal('1.4 MB')
def size_str(self): return sizeof_fmt(self.size)