def downloadCatalog(url,fileName,force): bDLFile=True fileName=format_filename(fileName) iCtlgRefresh=int(globalvar.ADDON.getSetting('ctlgRefresh')) *60 if not os.path.exists(globalvar.CACHE_DIR) : os.makedirs(globalvar.CACHE_DIR, mode=0777) filePath=os.path.join(globalvar.CACHE_DIR,fileName) if os.path.exists(filePath): mtime = os.stat(filePath).st_mtime bDLFile=(time.time()-mtime>iCtlgRefresh) print fileName,time.time()-mtime else: bDLFile=True if bDLFile: urllib.urlretrieve(url,filePath) log.logDLFile(url) return filePath
def download_catalog( url, file_name, force_dl=False, request_type='get', post_dic={}, random_ua=False, specific_headers={}): file_name = format_filename(file_name) iCtlgRefresh = int(globalvar.ADDON.getSetting('ctlgRefresh')) * 60 if not os.path.exists(globalvar.CACHE_DIR): os.makedirs(globalvar.CACHE_DIR, mode=0777) file_path = os.path.join(globalvar.CACHE_DIR, file_name) if os.path.exists(file_path): mtime = os.stat(file_path).st_mtime dl_file = (time.time() - mtime > iCtlgRefresh) else: dl_file = True if dl_file or force_dl: if random_ua: ua = user_agents[randint(0, len(user_agents) - 1)] else: ua = default_ua if specific_headers: headers = specific_headers if 'User-Agent' not in headers: headers['User-Agent'] = ua else: headers = {'User-Agent': ua} if request_type == 'get': r = requests.get(url, headers=headers) elif request_type == 'post': r = requests.get(url, headers=headers, data=post_dic) with open(file_path, 'wb') as f: f.write(r.content) log.logDLFile(url) return file_path
def downloadCatalog(url, fileName, force, dicPost): bDLFile = True fileName = format_filename(fileName) iCtlgRefresh = int(globalvar.ADDON.getSetting('ctlgRefresh')) * 60 if not os.path.exists(globalvar.CACHE_DIR): os.makedirs(globalvar.CACHE_DIR, mode=0777) filePath = os.path.join(globalvar.CACHE_DIR, fileName) if os.path.exists(filePath): mtime = os.stat(filePath).st_mtime bDLFile = (time.time() - mtime > iCtlgRefresh) else: bDLFile = True if bDLFile: if dicPost: data = urllib.urlencode(dicPost) print data urllib.urlretrieve(url, filePath, None, data) else: urllib.urlretrieve(url, filePath) log.logDLFile(url) return filePath