Example #1
0
 def test_get_size(self):
     self.assertEqual(helper.get_size(1000), '0.98 KB')
     self.assertEqual(helper.get_size(25600), '25.0 KB')
     self.assertEqual(helper.get_size(1024*1024*3), '3.0 MB')
     self.assertEqual(helper.get_size(1024**3*2.3), '2.3 GB')
     self.assertEqual(helper.get_size(1024**4*5.5), '5.5 TB')
     self.assertEqual(helper.get_size(1234, True), 'KB')
     self.assertEqual(helper.get_size(1024*1024*32, True), 'MB')
     self.assertEqual(helper.get_size(1024**3*77, True), 'GB')
     self.assertEqual(helper.get_size(1024**4*1.2, True), 'TB')
     self.assertEqual(helper.get_size(0), '0.00 KB')
Example #2
0
def start(filename, settings):
    Tracker.total_size, files, skipped_files = parse_nzb(filename, settings['skip_regex'])
    Tracker.downloaded = 0

    print 'Downloading:', filename
    print 'Size: %s \n' % helper.get_size(Tracker.total_size)
    res = download(files, settings)
    if res:
        # Got some broken files
        #download(skipped_files, settings)
        print 'got some broken files!'
Example #3
0
def show_progress():
    start = time()
    p = subprocess.Popen(['stty size'], shell=True, stdout=subprocess.PIPE)
    length, width = (int(i) for i in p.stdout.read().strip().split())
    progress_bar_length = int(width * 0.5)
    p.stdout.close()
    eta = 0
    speed = 0

    while Tracker.downloaded < Tracker.total_size:
        # Get terminal dimensions.
        p = subprocess.Popen(['stty size'], shell=True, stdout=subprocess.PIPE)
        length, width = (int(i) for i in p.stdout.read().strip().split())
        progress_bar_length = int(width * 0.5)
        p.stdout.close()

        speed = (Tracker.downloaded/1024.0)/(time() - start)
        percentage = (Tracker.downloaded / float(Tracker.total_size)) * 100.0
        # Progress bar output.
        progress = COMPLETE_CHAR * int(percentage * progress_bar_length/100.0)
        # Pad progress bar.
        progress = progress.ljust(progress_bar_length, ' ')

        if speed > 0:
            eta = (Tracker.total_size - Tracker.downloaded) / (speed * 1024)
        else:
            speed = 0
            
        helper.print_static(' %s%% [%s] %s KB/s  %s ETA' % (format(percentage, '3.1f'), progress, format(speed, '3.1f'), helper.htime(eta)), width)
        sleep(1)

    # For the completion progress bar and statistics.
    if Tracker.total_size:
        speed = format((Tracker.downloaded / 1024.0)/(time() - start), '3.1f')
        speed = speed + ' ' + helper.get_size(float(speed), suffix_only=True) + '/s'
    helper.print_static(' %s%% [%s] %s' % ('100', COMPLETE_CHAR * progress_bar_length, speed), width)

    # Print out completion download info.
    print '\n\n%s (%s)' % (datetime.now().strftime('%Y-%m-%d %H:%M:%S'), speed),
    print '[%s/%s] in %s\n' % (Tracker.downloaded, Tracker.total_size, helper.htime(time() - start))