def get_number_of_files(url_res): num_of_files = url_res.read(1) if num_of_files: return byte2int(num_of_files, 8) else: logger.info("no files") return 0
def query_subtitles(hash_string, file_path): req = urllib2.Request(QUERY_URL, headers=request_headers) res = urllib2.urlopen(req, data=generate_post_data(file_path, hash_string)) if res.getcode() == 200: stat_code_str = res.read(1) if not stat_code_check_pass(stat_code_str): return 'none', 'none' stat_code_int = byte2int(stat_code_str, 8) logger.info("stat_code is:" + str(stat_code_int)) return process_url_result(res, stat_code_int, file_path)
def read_file_ext(url_res): url_res.read(4), 32 ext_len = byte2int(url_res.read(4), 32) ext = url_res.read(ext_len) ext_string = ext.decode('utf-8', 'ignore') return ext_string
def read_header(res): byte2int(res.read(4), 32) desc_len = byte2int(res.read(4), 32) if desc_len > 0: res.read(desc_len) byte2int(res.read(4), 32)
def get_sub_file_buffer(url_res): file_len = byte2int(url_res.read(4), 32) return url_res.read(file_len)
def stat_code_check_pass(stat_code): if len(stat_code) != 0: stat_code = byte2int(stat_code, 8) if stat_code >= 0: return True return False