def get_filename(original_url_parsed, response): ans = get_download_filename_from_response(response) or posixpath.basename(original_url_parsed.path) or 'unknown' ct = response.info().get('Content-Type', '') if ct: ct = cgi.parse_header(ct)[0].lower() if ct: mt = guess_type(ans) if mt != ct: exts = mimetypes.guess_all_extensions(ct) if exts: ans += exts[0] return ans
def get_download_filename(response): filename = get_download_filename_from_response(response) filename, ext = os.path.splitext(filename) filename = filename[:60] + ext filename = ascii_filename(filename) return filename