def test_buff_guess(self): """ test name_resolver with only buffer """ filename = name_resolver.guess_file_name(buff=self.buff) self.assertTrue(isinstance(filename, str)) self.assertTrue(filename != "") print('\n', self.url, 'buff', filename)
def test_only_headers_guess(self): """ test name_resolver with only headers """ filename = name_resolver.guess_file_name(headers=self.req.headers) self.assertTrue(isinstance(filename, str)) self.assertTrue(filename != "") print('\n', self.url, 'headers', filename)
def test_only_url_guess(self): """ test name_resolver with only url. """ filename = name_resolver.guess_file_name(url=self.url) self.assertTrue(isinstance(filename, str)) self.assertTrue(filename != "") print('\n', self.url, 'url', filename)
def test_worst_guess(self): """ test name_resolver with nothing """ filename = name_resolver.guess_file_name() self.assertTrue(isinstance(filename, str)) self.assertTrue(filename != "") print('\n', self.url, 'best', filename)
def test_buff_headers_guess(self): """ test name_resolver with buffer, headers """ filename = name_resolver.guess_file_name(headers=self.req.headers, buff=self.buff) self.assertTrue(isinstance(filename, str)) self.assertTrue(filename != "") print('\n', self.url, 'url, headers', filename)
def test_best_guess(self): """ test name_resolver with everything """ filename = name_resolver.guess_file_name(self.req.url, self.req.headers, self.buff) self.assertTrue(isinstance(filename, str)) self.assertTrue(filename != "") print('\n', self.url, 'best', filename)
""" This file is only for experiments """ from time import sleep from awget.engine import HttpEngine from awget.name_resolver import guess_file_name URL = "http://www.rapconverter.com/SampleDownload/Sample1280.mp4" USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Firefox/68.0' #USER_AGENT = 'Wget/1.13.4 (linux-gnu)' LOCATION = "." dlr = HttpEngine(URL, LOCATION, USER_AGENT) req = dlr.prepare() dlr.download(False) while dlr.is_active(): if dlr.length is not None: print(round(dlr.done / dlr.length * 100, 2), end='\r') sleep(0.0167) dlr.save(guess_file_name(URL, req.headers, req.buff_for_mime)) dlr.clean()