def _search_title(page): titles = [] data = util.substr(page,'<div class=\"info','</div>') p = _match(re.search('<[hH]1>([^<]+)',data)) if not p: return __empty_info['title'] p = re.sub('[\t\r\n]+',' ',p).strip() p = unicode(p,'utf-8',errors='ignore') titles.append(util.replace_diacritic(p)) for m in re.finditer('<li>.+?<h3>(?P<name>[^<]+)',data,re.DOTALL|re.IGNORECASE): p = re.sub('[\t\r\n]+',' ',m.group('name')).strip() p = unicode(p,'utf-8',errors='ignore') titles.append(util.replace_diacritic(p)) return titles
def download(addon, filename, url, local, notifyFinishDialog=True, headers={}): try: util.info('Downloading %s to %s' % (url, local)) except: util.info('Downloading ' + url) local = xbmc.makeLegalFilename(local) try: filename = util.replace_diacritic(util.decode_html(filename)) except: filename = 'Video soubor' icon = os.path.join(addon.getAddonInfo('path'), 'icon.png') notifyEnabled = addon.getSetting('download-notify') == 'true' notifyEvery = addon.getSetting('download-notify-every') notifyPercent = 1 if int(notifyEvery) == 0: notifyPercent = 10 if int(notifyEvery) == 1: notifyPercent = 5 def encode(string): return u' '.join(string).encode('utf-8') def notify(title, message, time=3000): try: xbmcgui.Dialog().notification(encode(title), encode(message), time=time, icon=icon, sound=False) except: traceback.print_exc() error('unable to show notification') def callback(percent, speed, est, filename): if percent == 0 and speed == 0: notify(xbmc.getLocalizedString(13413), filename) return if notifyEnabled: if percent > 0 and percent % notifyPercent == 0: esTime = '%ss' % est if est > 60: esTime = '%sm' % int(est / 60) message = xbmc.getLocalizedString( 24042) % percent + ' - %s KB/s %s' % (speed, esTime) notify(message, filename) downloader = Downloader(callback) result = downloader.download(url, local, filename, headers) try: if result == True: if xbmc.Player().isPlaying(): notify(xbmc.getLocalizedString(20177), filename) else: if notifyFinishDialog: xbmcgui.Dialog().ok(xbmc.getLocalizedString(20177), filename) else: notify(xbmc.getLocalizedString(20177), filename) else: notify(xbmc.getLocalizedString(257), filename) xbmcgui.Dialog().ok(filename, xbmc.getLocalizedString(257) + ' : ' + result) except: traceback.print_exc()
def download(addon,filename,url,local,notifyFinishDialog=True,headers={}): util.info('Downloading %s to %s' % (url,local)) local = xbmc.makeLegalFilename(local) try: filename = util.replace_diacritic(util.decode_html(filename)) except: filename = 'Video soubor' icon = os.path.join(addon.getAddonInfo('path'),'icon.png') notify = addon.getSetting('download-notify') == 'true' notifyEvery = addon.getSetting('download-notify-every') notifyPercent = 1 if int(notifyEvery) == 0: notifyPercent = 10 if int(notifyEvery) == 1: notifyPercent = 5 def callback(percent,speed,est,filename): if percent == 0 and speed == 0: try: xbmc.executebuiltin('XBMC.Notification(%s,%s,3000,%s)' % (xbmc.getLocalizedString(13413).encode('utf-8'),filename,icon)) except: error('Unable to show notification') return if notify: if percent > 0 and percent % notifyPercent == 0: esTime = '%ss' % est if est>60: esTime = '%sm' % int(est/60) message = xbmc.getLocalizedString(24042) % percent + ' - %s KB/s %s' % (speed,esTime) try: xbmc.executebuiltin('XBMC.Notification(%s,%s,3000,%s)'%(message.encode('utf-8'),filename,icon)) except: error('Unable to show notification') downloader = Downloader(callback) result = downloader.download(url,local,filename,headers) try: if result == True: if xbmc.Player().isPlaying(): xbmc.executebuiltin('XBMC.Notification(%s,%s,8000,%s)' % (xbmc.getLocalizedString(20177),filename,icon)) else: if notifyFinishDialog: xbmcgui.Dialog().ok(xbmc.getLocalizedString(20177),filename) else: xbmc.executebuiltin('XBMC.Notification(%s,%s,3000,%s)' % (xbmc.getLocalizedString(20177),filename,icon)) else: xbmc.executebuiltin('XBMC.Notification(%s,%s,5000,%s)' % (xbmc.getLocalizedString(257),filename,icon)) xbmcgui.Dialog().ok(filename,xbmc.getLocalizedString(257) +' : '+result) except: traceback.print_exc()