def WriteKeymap(start, end): filename = os.path.join('special://profile/keymaps', 'zOTT_hotkey.xml') theFile = sfile.file(filename, 'w') cmd = '\t\t\t<%s>XBMC.RunScript(special://home/addons/script.tvguidedixie/hotkey.py)</%s>\n' % ( start, end) theFile.write('<keymap>\n') theFile.write('\t<global>\n') theFile.write('\t\t<keyboard>\n') theFile.write(cmd) theFile.write('\t\t</keyboard>\n') theFile.write('\n') theFile.write('\t\t<remote>\n') theFile.write(cmd) theFile.write('\t\t</remote>\n') theFile.write('\t</global>\n') theFile.write('</keymap>\n') theFile.close() return True
def setParam(param, value, file): config = [] try: param = param.upper() + '=' config = sfile.readlines(file) except: pass value = str(value) copy = [] for line in config: line = line.strip() if (len(line) > 0) and (not line.startswith(param)): copy.append(line) if len(value) > 0: copy.append(param + value) f = sfile.file(file, 'w') for line in copy: f.write(line) f.write('\n') f.close()
def writeFavourites(file, faves): f = sfile.file(file, 'w') f.write('<favourites>') for fave in faves: try: name = utils.escape(fave[0]) thumb = utils.escape(fave[1]) cmd = utils.escape(fave[2]) thumb = convertToHome(thumb) name = 'name="%s" ' % name thumb = 'thumb="%s">' % thumb f.write('\n\t<favourite ') f.write(name) f.write(thumb) f.write(cmd) f.write('</favourite>') except: pass f.write('\n</favourites>') f.close() import xbmcgui try: count = int(xbmcgui.Window(10000).getProperty('Super_Favourites_Count')) except: count = 0 xbmcgui.Window(10000).setProperty('Super_Favourites_Count', str(count+1))
def WriteKeymap(start, end): dest = os.path.join('special://profile/keymaps', KEYMAP_HOT) cmd = '<keymap><Global><keyboard><%s>XBMC.RunScript(special://home/addons/plugin.program.super.favourites/hot.py)</%s></keyboard></Global></keymap>' % (start, end) f = sfile.file(dest, 'w') f.write(cmd) f.close() xbmc.sleep(1000) tries = 4 while not sfile.exists(dest) and tries > 0: tries -= 1 f = sfile.file(dest, 'w') f.write(t) f.close() xbmc.sleep(1000) return True
def WriteKeymap(start, end): dest = os.path.join('special://profile/keymaps', KEYMAP_HOT) cmd = '<keymap><Global><keyboard><%s>XBMC.RunScript(special://home/addons/script.trtv/osd.py)</%s></keyboard></Global></keymap>' % (start, end) f = sfile.file(dest, 'w') f.write(cmd) f.close() xbmc.sleep(1000) tries = 4 while not sfile.exists(dest) and tries > 0: tries -= 1 f = sfile.file(dest, 'w') f.write(cmd) f.close() xbmc.sleep(1000) return True
def addToCache(url, data): checkCacheDir() cacheKey = createKey(url) cachePath = os.path.join(CacheDir, cacheKey) f = sfile.file(cachePath, 'w') f.write(data) f.close() purgeCache()
def WriteKeymap(start, end): dest = os.path.join("special://profile/keymaps", KEYMAP_HOT) cmd = ( "<keymap><Global><keyboard><%s>XBMC.RunScript(special://home/addons/plugin.program.super.favourites/hot.py)</%s></keyboard></Global></keymap>" % (start, end) ) f = sfile.file(dest, "w") f.write(cmd) f.close() xbmc.sleep(1000) tries = 4 while not sfile.exists(dest) and tries > 0: tries -= 1 f = sfile.file(dest, "w") f.write(t) f.close() xbmc.sleep(1000) return True
def WriteKeymap(start, end): filename = KEYMAP_HOT cmd = 'XBMC.RunScript(special://home/addons/plugin.program.favoritos.wizardk17/hot.py)' dest = os.path.join('special://profile/keymaps', filename) cmd = '<keymap><Global><keyboard><%s>%s</%s></keyboard></Global></keymap>' % (start, cmd, end) f = sfile.file(dest, 'w') f.write(cmd) f.close() xbmc.sleep(1000) tries = 4 while not sfile.exists(dest) and tries > 0: tries -= 1 f = sfile.file(dest, 'w') f.write(cmd) f.close() xbmc.sleep(1000) return True
def writeToFile(self, filename): cloneID = -1 localID = self.id if self.isClone: filename, cloneID = self.cloneFilename(filename) localID += cloneID try: f = sfile.file(filename, 'w') except: return False try: f.write(localID.encode('utf8') + '\n') except: f.write(localID + '\n') f.write(self.title.encode('utf8') + '\n') if self.logo: f.write(self.logo.encode('utf8') + '\n') else: f.write('\n') if self.streamUrl: f.write(self.streamUrl.encode('utf8') + '\n') else: f.write('\n') if self.visible: f.write('1\n') else: f.write('0\n') f.write(str(self.weight) + '\n') f.write(self.categories.encode('utf8') + '\n') if self.userDef: f.write('1\n') else: f.write('0\n') if self.desc: f.write(self.desc.encode('utf8') + '\n') else: f.write('\n') if self.isClone: f.write('1\n') else: f.write('0\n') f.close() return True
def patchAmazonImage(mode, image, url, infoLabels): folder = url.rsplit(DELIMETER, 1)[0] files = s3.getAllFiles(folder, recurse=False) root = folder + removeExtension(url.replace(folder, '')) root = urllib.quote_plus(root).replace('%25LB%25', '%') for ext in IMG_EXT: img = root + ext for file in files: file = urllib.quote_plus(file.encode('utf-8')) if img == file: img = s3.convertToCloud(s3.getURL(img)) gif = s3.convertToCloud(s3.getURL(root + '.gif')) infoLabels['Gif'] = img #Kodi incorrectly handles remote gifs therefore download and store locally gifFolder = os.path.join(PROFILE, 'c') filename = os.path.join(gifFolder, getMD5(url.split('?', 1)[0])) + '.gif' if sfile.exists(filename): if sfile.size(filename) > 0: infoLabels['Gif'] = filename else: if DownloadIfExists(gif, filename): infoLabels['Gif'] = filename else: sfile.file(filename, 'w') #create empty file so we don't check again return img if mode == AMAZON_FOLDER: return DEFAULTFOLDER if mode == AMAZON_FILE: return DEFAULTMOVIE
def verifySuperSearch(): src = os.path.join(ROOT, 'Search') dst = os.path.join(ROOT, 'S') sfile.rename(src, dst) dst = os.path.join(ROOT, 'S') src = os.path.join(HOME, 'resources', 'Search', FILENAME) try: sfile.makedirs(dst) except: pass dst = os.path.join(dst, FILENAME) if not sfile.exists(dst): sfile.copy(src, dst) try: #patch any changes xml = sfile.read(dst) xml = xml.replace('1channel/?mode=7000', '1channel/?mode=Search') xml = xml.replace('plugin.video.genesis/?action=actors_movies', 'plugin.video.genesis/?action=people_movies') xml = xml.replace('plugin.video.genesis/?action=actors_shows', 'plugin.video.genesis/?action=people_shows') f = sfile.file(dst, 'w') f.write(xml) f.close() except: pass import favourite new = favourite.getFavourites(src, validate=False) line1 = GETTEXT(30123) line2 = GETTEXT(30124) for item in new: fave, index, nFaves = favourite.findFave(dst, item[2]) if index < 0: line = line1 % item[0] if DialogYesNo(line1=line, line2=line2): favourite.addFave(dst, item)
def verifySuperSearch(): old = os.path.join(ROOT, 'Search') dst = os.path.join(ROOT, 'S') sfile.rename(old, dst) try: sfile.makedirs(dst) except: pass src = os.path.join(HOME, 'resources', 'search', FILENAME) dst = os.path.join(dst, FILENAME) if not sfile.exists(dst): sfile.copy(src, dst) try: #patch any changes xml = sfile.read(dst) xml = xml.replace('is/?action=movies_search&', 'is/?action=movieSearch&') xml = xml.replace('is/?action=people_movies&', 'is/?action=moviePerson&') xml = xml.replace('is/?action=shows_search&', 'is/?action=tvSearch&') xml = xml.replace('is/?action=people_shows&', 'is/?action=tvPerson&') f = sfile.file(dst, 'w') f.write(xml) f.close() except: pass import favourite new = favourite.getFavourites(src, validate=False) #line1 = GETTEXT(30123) #line2 = GETTEXT(30124) for item in new: fave, index, nFaves = favourite.findFave(dst, item[2]) if index < 0: #line = line1 % item[0] #if DialogYesNo(line1=line, line2=line2): favourite.addFave(dst, item)
def verifySuperSearch(): src = os.path.join(ROOT, "Search") dst = os.path.join(ROOT, "S") sfile.rename(src, dst) dst = os.path.join(ROOT, "S") src = os.path.join(HOME, "resources", "Search", FILENAME) try: sfile.makedirs(dst) except: pass dst = os.path.join(dst, FILENAME) if not sfile.exists(dst): sfile.copy(src, dst) try: # patch any changes xml = sfile.read(dst) xml = xml.replace("1channel/?mode=7000", "1channel/?mode=Search") xml = xml.replace("plugin.video.genesis/?action=actors_movies", "plugin.video.genesis/?action=people_movies") xml = xml.replace("plugin.video.genesis/?action=actors_shows", "plugin.video.genesis/?action=people_shows") f = sfile.file(dst, "w") f.write(xml) f.close() except: pass import favourite new = favourite.getFavourites(src, validate=False) line1 = GETTEXT(30123) line2 = GETTEXT(30124) for item in new: fave, index, nFaves = favourite.findFave(dst, item[2]) if index < 0: line = line1 % item[0] if DialogYesNo(line1=line, line2=line2): favourite.addFave(dst, item)
def writeToFile(self, filename): cloneID = -1 localID = self.id if self.isClone: filename, cloneID = self.cloneFilename(filename) localID += cloneID try: f = sfile.file(filename, 'w') except: return False self.safeWriteToFile(f, localID) self.safeWriteToFile(f, self.title) self.safeWriteToFile( f, self.logo.replace('__PLUS1', '').replace('_PLUS1', '')) self.safeWriteToFile(f, self.streamUrl) if self.visible: f.write('1\n') else: f.write('0\n') f.write(str(self.weight) + '\n') self.safeWriteToFile(f, self.categories) if self.userDef: f.write('1\n') else: f.write('0\n') self.safeWriteToFile(f, self.desc) if self.isClone: f.write('1\n') else: f.write('0\n') f.close() return True
def writeToFile(self, filename): cloneID = -1 localID = self.id if self.isClone: filename, cloneID = self.cloneFilename(filename) localID += cloneID try: f = sfile.file(filename, "w") except: return False self.safeWriteToFile(f, localID) self.safeWriteToFile(f, self.title) self.safeWriteToFile(f, self.logo.replace("__PLUS1", "").replace("_PLUS1", "")) self.safeWriteToFile(f, self.streamUrl) if self.visible: f.write("1\n") else: f.write("0\n") f.write(str(self.weight) + "\n") self.safeWriteToFile(f, self.categories) if self.userDef: f.write("1\n") else: f.write("0\n") self.safeWriteToFile(f, self.desc) if self.isClone: f.write("1\n") else: f.write("0\n") f.close() return True
def writeFavourites(file, faves): kodiFile = os.path.join('special://profile', utils.FILENAME) isKodi = xbmc.translatePath(file) == xbmc.translatePath(kodiFile) f = sfile.file(file, 'w') f.write('<favourites>') for fave in faves: try: name = utils.escape(fave[0]) thumb = utils.escape(fave[1]) cmd = utils.escape(fave[2]) cmd = removeHome(cmd) if isKodi and cmd.lower().startswith('playmedia'): cmd = removeSFOptions(cmd) thumb = utils.convertToHome(thumb) name = 'name="%s" ' % name thumb = 'thumb="%s">' % thumb f.write('\n\t<favourite ') f.write(name) f.write(thumb) f.write(cmd) f.write('</favourite>') except: pass f.write('\n</favourites>') f.close() import xbmcgui try: count = int( xbmcgui.Window(10000).getProperty('Super_Favourites_Count')) except: count = 0 xbmcgui.Window(10000).setProperty('Super_Favourites_Count', str(count + 1))
def writeFavourites(file, faves): kodiFile = os.path.join("special://profile", utils.FILENAME) isKodi = xbmc.translatePath(file) == xbmc.translatePath(kodiFile) f = sfile.file(file, "w") f.write("<favourites>") for fave in faves: try: name = utils.escape(fave[0]) thumb = utils.escape(fave[1]) cmd = utils.escape(fave[2]) if isKodi and cmd.lower().startswith("playmedia"): cmd = removeSFOptions(cmd) thumb = utils.convertToHome(thumb) name = 'name="%s" ' % name thumb = 'thumb="%s">' % thumb f.write("\n\t<favourite ") f.write(name) f.write(thumb) f.write(cmd) f.write("</favourite>") except: pass f.write("\n</favourites>") f.close() import xbmcgui try: count = int(xbmcgui.Window(10000).getProperty("Super_Favourites_Count")) except: count = 0 xbmcgui.Window(10000).setProperty("Super_Favourites_Count", str(count + 1))
def writeToFile(self, filename): cloneID = -1 localID = self.id if self.isClone: filename, cloneID = self.cloneFilename(filename) localID += cloneID try: f = sfile.file(filename, 'w') except: return False self.safeWriteToFile(f, localID) self.safeWriteToFile(f, self.title) self.safeWriteToFile(f, self.logo) self.safeWriteToFile(f, self.streamUrl) if self.visible: f.write('1\n') else: f.write('0\n') f.write(str(self.weight) + '\n') self.safeWriteToFile(f, self.categories) if self.userDef: f.write('1\n') else: f.write('0\n') self.safeWriteToFile(f, self.desc) if self.isClone: f.write('1\n') else: f.write('0\n') f.close() return True
def WriteFSKeymap(start, end): filename = os.path.join('special://profile/keymaps', 'zOTT_toggle.xml') theFile = sfile.file(filename, 'w') cmd = '\t\t\t<%s>fullscreen</%s>\n' % (start, end) theFile.write('<keymap>\n') theFile.write('\t<global>\n') theFile.write('\t\t<keyboard>\n') theFile.write(cmd) theFile.write('\t\t</keyboard>\n') theFile.write('\n') theFile.write('\t\t<remote>\n') theFile.write(cmd) theFile.write('\t\t</remote>\n') theFile.write('\t</global>\n') theFile.write('</keymap>\n') theFile.close() return True
def doDownload(url, dest, title, referrer='', dp=None, silent=False): resp = getResponse(url, 0, referrer) if not resp: if not silent: utils.DialogOK(title, utils.GETTEXT(30081)) return try: content = int(resp.headers['Content-Length']) except: content = 0 try: resumable = 'bytes' in resp.headers['Accept-Ranges'].lower() except: resumable = False if resumable: utils.Log('Download is resumable') if content < 1: if not silent: utils.DialogOK(title, utils.GETTEXT(30081)) return import s3 dest = dest.replace(s3.DELIMETER, os.sep) folder = dest.rsplit(os.sep, 1)[0] sfile.makedirs(folder) size = CHUNK_SIZE * CHUNK_SIZE if size > content: size = content total = 0 notify = 0 errors = 0 count = 0 resume = 0 sleep = 0 f = sfile.file(dest, type='wb') sfile.file(dest+'.part', type='wb') chunk = None chunks = [] while True: abortRequested = xbmcgui.Window(10000).getProperty('LB_XBMC_ABORTED') == 'true' if abortRequested or (dp and dp.iscanceled()): f.close() utils.tidyUp(dest) return downloaded = total for c in chunks: downloaded += len(c) percent = min(100 * downloaded / content, 100) if percent >= notify: notify += 10 if dp: dp.update(int(percent), utils.GETTEXT(30079) % title, utils.GETTEXT(30080)) chunk = None error = False try: chunk = resp.read(size) if not chunk: if percent < 99: error = True else: while len(chunks) > 0: c = chunks.pop(0) f.write(c) del c f.close() utils.Log('%s download complete' % (dest)) sfile.remove(dest+'.part') return except Exception, e: utils.Log(str(e)) error = True sleep = 10 errno = 0 if hasattr(e, 'errno'): errno = e.errno if errno == 10035: # 'A non-blocking socket operation could not be completed immediately' pass if errno == 10054: #'An existing connection was forcibly closed by the remote host' errors = 10 #force resume sleep = 30 if errno == 11001: # 'getaddrinfo failed' errors = 10 #force resume sleep = 30 if chunk: errors = 0 chunks.append(chunk) if len(chunks) > CHUNK_CACHE: c = chunks.pop(0) f.write(c) total += len(c) del c if error: errors += 1 count += 1 utils.Log('%d Error(s) whilst downloading %s' % (count, dest)) xbmc.sleep(sleep*1000) if (resumable and errors > 0) or errors >= 10: if (not resumable and resume >= 10) or resume >= 100: #Give up! utils.Log('%s download canceled - too many error whilst downloading' % dest) if not silent: utils.DialogOK(dest, '' , utils.GETTEXT(30081)) return resume += 1 errors = 0 if resumable: chunks = [] #create new response utils.Log('Download resumed (%d) %s' % (resume, dest)) resp = getResponse(url, total, referrer) else: #use existing response pass
def doDownload(url, dest, title, referer='', agent='', cookie='', quiet=False): #unquote parameters url = urllib.unquote_plus(url).split('|')[0] dest = urllib.unquote_plus(dest) title = urllib.unquote_plus(title) referer = urllib.unquote_plus(referer) agent = urllib.unquote_plus(agent) cookie = urllib.unquote_plus(cookie) file = dest.rsplit(os.sep, 1)[-1] resp = getResponse(url, 0, referer, agent, cookie) if not resp: xbmcgui.Dialog().ok(title, dest, 'Download failed', 'No response from server') return try: content = int(resp.headers['Content-Length']) except: content = 0 try: resumable = 'bytes' in resp.headers['Accept-Ranges'].lower() except: resumable = False utils.log('Download Header') utils.log(resp.headers) if resumable: utils.log('Download is resumable') if content < 1: xbmcgui.Dialog().ok(title, file, 'Unknown filesize', 'Unable to download') return size = 1024 * 1024 mb = content / (1024 * 1024) if content < size: size = content total = 0 notify = 0 errors = 0 count = 0 resume = 0 sleep = 0 if (not quiet) and xbmcgui.Dialog().yesno(title + ' - Confirm Download', file, 'Complete file is %dMB' % mb, 'Continue with download?', 'Confirm', 'Cancel') == 1: return f = sfile.file(dest, type='wb') chunk = None chunks = [] while True: downloaded = total for c in chunks: downloaded += len(c) percent = min(100 * downloaded / content, 100) if percent >= notify: if not quiet: xbmc.executebuiltin( "XBMC.Notification(%s,%s,%i)" % ( title.replace(',', '') + ' - Download Progress - ' + str(percent)+'%', dest, 10000)) utils.log('Download percent : %s %s %dMB downloaded : %sMB File Size : %sMB' % (str(percent)+'%', dest, mb, downloaded / 1000000, content / 1000000)) notify += 10 chunk = None error = False try: chunk = resp.read(size) if not chunk: if percent < 99: error = True else: while len(chunks) > 0: c = chunks.pop(0) f.write(c) del c f.close() utils.log('%s download complete' % (dest)) if not quiet: done(title, dest, True) return except Exception, e: utils.log(str(e)) error = True sleep = 10 errno = 0 if hasattr(e, 'errno'): errno = e.errno if errno == 10035: # 'A non-blocking socket operation could not be completed immediately' pass if errno == 10054: #'An existing connection was forcibly closed by the remote host' errors = 10 #force resume sleep = 30 if errno == 11001: # 'getaddrinfo failed' errors = 10 #force resume sleep = 30 if chunk: errors = 0 chunks.append(chunk) if len(chunks) > 5: c = chunks.pop(0) f.write(c) total += len(c) del c if error: errors += 1 count += 1 utils.log('%d Error(s) whilst downloading %s' % (count, dest)) xbmc.sleep(sleep*1000) if (resumable and errors > 0) or errors >= 10: if (not resumable and resume >= 50) or resume >= 500: #Give up! utils.log('%s download canceled - too many error whilst downloading' % (dest)) if not quiet: done(title, dest, False) return resume += 1 errors = 0 if resumable: chunks = [] #create new response utils.log('Download resumed (%d) %s' % (resume, dest)) resp = getResponse(url, total, referer, agent, cookie) else: #use existing response pass
def doDownload(url, dest, title, referer='', agent='', cookie='', quiet=False): #unquote parameters url = urllib.unquote_plus(url).split('|')[0] dest = urllib.unquote_plus(dest) title = urllib.unquote_plus(title) referer = urllib.unquote_plus(referer) agent = urllib.unquote_plus(agent) cookie = urllib.unquote_plus(cookie) file = dest.rsplit(os.sep, 1)[-1] resp, error = getResponse(url, 0, referer, agent, cookie) if not resp: xbmcgui.Dialog().ok(title, dest, 'Download failed', error) return try: content = int(resp.headers['Content-Length']) except: content = 0 try: resumable = 'bytes' in resp.headers['Accept-Ranges'].lower() except: resumable = False utils.log('Download Header') utils.log(resp.headers) if resumable: utils.log('Download is resumable') if content < 1: xbmcgui.Dialog().ok(title, file, 'Unknown filesize', 'Unable to download') return size = 1024 * 1024 mb = content / (1024 * 1024) if content < size: size = content total = 0 notify = 0 errors = 0 count = 0 resume = 0 sleep = 0 if (not quiet) and xbmcgui.Dialog().yesno( title + ' - Confirm Download', file, 'Complete file is %dMB' % mb, 'Continue with download?', 'Confirm', 'Cancel') == 1: return f = sfile.file(dest, type='wb') chunk = None chunks = [] while True: downloaded = total for c in chunks: downloaded += len(c) percent = min(100 * downloaded / content, 100) if percent >= notify: if not quiet: xbmc.executebuiltin( "XBMC.Notification(%s,%s,%i)" % (title.replace(',', '') + ' - Download Progress - ' + str(percent) + '%', dest, 10000)) utils.log( 'Download percent : %s %s %dMB downloaded : %sMB File Size : %sMB' % (str(percent) + '%', dest, mb, downloaded / 1000000, content / 1000000)) notify += 10 chunk = None error = False try: chunk = resp.read(size) if not chunk: if percent < 99: error = True else: while len(chunks) > 0: c = chunks.pop(0) f.write(c) del c f.close() utils.log('%s download complete' % (dest)) if not quiet: done(title, dest, True) return except Exception, e: utils.log(str(e)) error = True sleep = 10 errno = 0 if hasattr(e, 'errno'): errno = e.errno if errno == 10035: # 'A non-blocking socket operation could not be completed immediately' pass if errno == 10054: #'An existing connection was forcibly closed by the remote host' errors = 10 #force resume sleep = 30 if errno == 11001: # 'getaddrinfo failed' errors = 10 #force resume sleep = 30 if chunk: errors = 0 chunks.append(chunk) if len(chunks) > 5: c = chunks.pop(0) f.write(c) total += len(c) del c if error: errors += 1 count += 1 utils.log('%d Error(s) whilst downloading %s' % (count, dest)) xbmc.sleep(sleep * 1000) if (resumable and errors > 0) or errors >= 10: if (not resumable and resume >= 50) or resume >= 500: #Give up! utils.log( '%s download canceled - too many error whilst downloading' % (dest)) if not quiet: done(title, dest, False) return resume += 1 errors = 0 if resumable: chunks = [] #create new response utils.log('Download resumed (%d) %s' % (resume, dest)) resp, error = getResponse(url, total, referer, agent, cookie) else: #use existing response pass
def doDownload(url, dest, title, referrer='', showProgress=False): resp = getResponse(url, 0, referrer) if not resp: xbmcgui.Dialog().ok(title, dest, 'Download failed', 'No response from server') return try: content = int(resp.headers['Content-Length']) except: content = 0 try: resumable = 'bytes' in resp.headers['Accept-Ranges'].lower() except: resumable = False if resumable: utils.log('Download is resumable') if content < 1: xbmcgui.Dialog().ok(title, dest, 'Download failed', 'Unknown filesize') return size = 1024 * 1024 mb = content / (1024 * 1024) if content < size: size = content total = 0 notify = 0 errors = 0 count = 0 resume = 0 sleep = 0 f = sfile.file(dest, type='wb') chunk = None chunks = [] while True: downloaded = total for c in chunks: downloaded += len(c) percent = min(100 * downloaded / content, 100) if percent >= notify: if showProgress: xbmc.executebuiltin( "XBMC.Notification(%s,%s,%d)" % ( title + ' - Download Progress - ' + notify +'%', dest, 10000)) notify += 10 chunk = None error = False try: chunk = resp.read(size) if not chunk: if percent < 99: error = True else: while len(chunks) > 0: c = chunks.pop(0) f.write(c) del c f.close() utils.log('%s download complete' % (dest)) return except Exception, e: utils.log(str(e)) error = True sleep = 10 errno = 0 if hasattr(e, 'errno'): errno = e.errno if errno == 10035: # 'A non-blocking socket operation could not be completed immediately' pass if errno == 10054: #'An existing connection was forcibly closed by the remote host' errors = 10 #force resume sleep = 30 if errno == 11001: # 'getaddrinfo failed' errors = 10 #force resume sleep = 30 if chunk: errors = 0 chunks.append(chunk) if len(chunks) > 5: c = chunks.pop(0) f.write(c) total += len(c) del c if error: errors += 1 count += 1 utils.log('%d Error(s) whilst downloading %s' % (count, dest)) xbmc.sleep(sleep*1000) if (resumable and errors > 0) or errors >= 10: if (not resumable and resume >= 10) or resume >= 100: #Give up! utils.log('%s download canceled - too many error whilst downloading' % dest) xbmcgui.Dialog().ok(title, dest, '' , 'Download failed') return resume += 1 errors = 0 if resumable: chunks = [] #create new response utils.log('Download resumed (%d) %s' % (resume, dest)) resp = getResponse(url, total, referrer) else: #use existing response pass