Esempio n. 1
0
    def test_get_filename_from(self):
        # Subject, expected filename.
        test_subjects = [
            ("""I AM A LAME SUBJECT "FILENAME.POOP" HA""", 'FILENAME.POOP'),
            ("""I AM A LAME SUBJECT "FILE.NAME.POOP" HA""", 'FILE.NAME.POOP'),
            ("""[123456]-[01/21] - "0_0.nfo" yEnc (1/1)""", '0_0.nfo'),
            ("""[123456]-[#chan@irc]-[Full]-[Title_of_the-Relase-GROuP]-[01/21] - this_is_the_filename.nfo yEnc (1/1)""", 'this_is_the_filename.nfo'),
            ("""[123456]-[#chan@irc]-[Full]-[Title_of_the-Relase-GROuP]-[01/21] - this is the filename.nfo yEnc (1/1)""", 'this is the filename.nfo'),
            ("""this_is_the_filename.nfo""", 'this_is_the_filename.nfo'),
            ("""this is the filename.nfo""", 'this is the filename.nfo'),
            ("""[1235]-[#chan@IrC]-[FULL]-[12345]-[21/79] - some.file.r01 (1/50)""", 'some.file.r01'),
            ("""[353]-[#chan@IrC]-[FULL]-[10202]-[21/79] - "some.file.r01" (1/50)""", 'some.file.r01'),
            ("""New subject name "Filename goes here (v5.0) (echo).rar" (1/3)""", 'Filename goes here (v5.0) (echo).rar'),
            ("""[65781]-[FULL]-[#a.b.test@EFNet]-[ Legit.File.MEDiA-GROUP ]-[25/29] - "a.real.file.vol01+02.par2"""", 'a.real.file.vol01+02.par2'),
            ("""[65781]-[FULL]-[#a.b.test@EFNet]-[ Legit.File.MEDiA-GROUP ]-[25/29] - a.real.file.vol01+02.par2 blah""", 'a.real.file.vol01+02.par2'), # Should test the second regex.
            ("""Just a file.jpg""", "Just a file.jpg"),
            ("""filename.jpg""", "filename.jpg"),
            ("""Blank""", '')
        ]

        for subject, expected_filename in test_subjects:
            potential = helper.get_filename_from(subject)
            try:
                self.assertTrue(expected_filename in potential)
            except AssertionError:
                print '* failed on subject', repr(subject)
                print '* got', repr(potential)
                print '* expected', repr(expected_filename)
                raise
Esempio n. 2
0
def download(files, settings):
    temp_dir = settings['temp_dir']
    download_path = settings['download_path']

    download = DownloadPool(settings)
    decode = Decode()
    pool = GreenPool(settings['connections'])
    progress_tracker = greenthread.spawn(show_progress)

    for file_ in files:
        # Check if file from subject exists.
        subject_filename = helper.get_filename_from(file_['file_subject'])

        if helper.file_exists(download_path, subject_filename):
            Tracker.total_size -= sum([i['segment_bytes'] for i in file_['segments']])
            print subject_filename, 'already exists'
            continue

        # Download.
        for segment_path in pool.imap(download.download, file_['segments']):
            # Decode.
            if segment_path:
                tpool.execute(decode.decode, segment_path, temp_dir, download_path)

    if decode.tracker:
        print 'have broken files...'
        #return False
        print decode.tracker
        broken_files = decode.tracker.keys()
        for fname in broken_files:
            #print 'decoding', fname
            decode.join_files(fname, temp_dir, download_path)

    #progress_tracker.kill()
    progress_tracker.wait()

    # All OK.
    return 0