def onCachesUpdated(self): if ADDON.getSetting('notifications.enabled') == 'true': n = notification.Notification(self.database, ADDON.getAddonInfo('path')) n.scheduleNotifications() self.database.close(None)
def VerifyKeymapHot(): if ADDON.getSetting('HOTKEY') == GETTEXT(30111): #i.e. programmable return False dest = os.path.join('special://profile/keymaps', KEYMAP_HOT) if sfile.exists(dest): return False key = ADDON.getSetting('HOTKEY') valid = [] for i in range(30028, 30040): valid.append(GETTEXT(i)) valid.append(GETTEXT(30058)) includeKey = key in valid if not includeKey: DeleteKeymap(KEYMAP_HOT) return True if isATV(): DialogOK(GETTEXT(30118), GETTEXT(30119)) return False return WriteKeymap(key.lower(), key.lower())
def CheckVersion(): try: prev = ADDON.getSetting('VERSION') curr = VERSION if xbmcgui.Window(10000).getProperty('OTT_RUNNING') != 'True': VerifyKeymaps() if prev == curr: return verifySuperSearch() src = os.path.join(ROOT, 'cache') dst = os.path.join(ROOT, 'C') sfile.rename(src, dst) ADDON.setSetting('VERSION', curr) if prev == '0.0.0' or prev == '1.0.0': sfile.makedirs(PROFILE) #call showChangeLog like this to workaround bug in openElec script = os.path.join(HOME, 'showChangelog.py') cmd = 'AlarmClock(%s,RunScript(%s),%d,True)' % ('changelog', script, 0) xbmc.executebuiltin(cmd) except: pass
def __init__(self, database): super(Scoreboard, self).__init__() if 55 - 55: iIiiiI1IiI1I1 - i1.I1i1iI1i * i11Ii11I1Ii1i * o0oOOo0O0Ooo / iIiiiI1IiI1I1 if 79 - 79: O00oOoOoO0o0O + ooO.OOoO * i11Ii11I1Ii1i % Oo0ooO0oo0oO.i1 if 94 - 94: II * I1i1iI1i / i11Ii11I1Ii1i.o0oOOo0O0Ooo * II self.database = database self.selected_program = None self.is_future = False self.top_list = [] self.right_list = [] self.left_list = [] self.bottom_list = [] self.score_list = list() self.label_list = list() self.game_list = list() self.league = '' iiiii11iII1 = os.path.join( xbmc.translatePath(ADDON.getAddonInfo('profile')), "5") if os.path.isfile(iiiii11iII1): self.team_map = ConfigParser.ConfigParser() self.team_map.read(iiiii11iII1) else: self.team_map = None xbmc.log('[%s] Team-Map not found' % ADDON.getAddonInfo('id'), xbmc.LOGERROR) if 54 - 54: OOoO.OOoO / iIiiiI1IiI1I1 / Oo0ooO0oo0oO + O00oOoOoO0o0O / Ii1I
def GETTEXT(id): text = ADDON.getLocalizedString(id) name = ADDON.getLocalizedString(30121) if name == DISPLAY: return text text = text.replace(name, DISPLAY) return text
def get_logo(channel): logo = channel.logo logo_type = int(ADDON.getSetting('logos.source')) if logo and logo_type == LOGO_TYPE_DEFAULT: return logo logo_location = ADDON.getSetting('logos.folder') if not logo and logo_type == LOGO_TYPE_DEFAULT: logo = DEFAULT_LOGO_URL + 's' + channel.id + '_h3_aa.png' elif logo_type == LOGO_TYPE_CUSTOM and not logo.startswith(logo_location): logo = logo_location + channel.title + '.png' return logo
def showChangelog(addonID=None): try: if addonID: ADDON = xbmcaddon.Addon(addonID) else: ADDON = xbmcaddon.Addon(ADDONID) text = sfile.read(ADDON.getAddonInfo('changelog')) title = '%s - %s' % (xbmc.getLocalizedString(24054), ADDON.getAddonInfo('name')) showText(title, text) except: pass
def run_service(): ok = True user = ADDON.getSetting('skyusername') passw = ADDON.getSetting('skypassword') if user == '' or passw == '': xbmc.log("[plugin.video.sportsaccess] No username or password configured!", xbmc.LOGWARNING) ok = False else: ok = verify_login(user, passw, False) if ok: xbmc.log("[plugin.video.sportsaccess] Service now being triggered...", xbmc.LOGNOTICE) Service() else: xbmc.log("[plugin.video.sportsaccess] Service cannot be triggered", xbmc.LOGWARNING)
def get_setting(key, is_list=False): value = ADDON.getSetting(key) if value and is_list: value = json.loads(value) elif is_list: value = [] return value
def reset_playing(): path = xbmc.translatePath(ADDON.getAddonInfo('profile')) if not os.path.exists(path): os.mkdir(path) proc_file = os.path.join(path, 'proc') f = open(proc_file, 'w') f.write('') f.close()
def fetch_file(self): ret_val = self.FETCH_NOT_NEEDED fetch = False if not os.path.exists(self.file_path): # always fetch if file doesn't exist! fetch = True else: interval = self.interval # int(self.addon.getSetting('xmltv.interval')) if interval != self.INTERVAL_ALWAYS: mod_time = datetime.datetime.fromtimestamp(os.path.getmtime(self.file_path)) td = datetime.datetime.now() - mod_time # need to do it this way cause Android doesn't support .total_seconds() :( diff = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6) / 10 ** 6 if ((interval == self.INTERVAL_2 and diff >= 7200) or (interval == self.INTERVAL_6 and diff >= 21600) or (interval == self.INTERVAL_12 and diff >= 43200) or (interval == self.INTERVAL_24 and diff >= 86400) or (interval == self.INTERVAL_48 and diff >= 172800)): fetch = True else: fetch = True if fetch: tmp_file = os.path.join(self.base_path, 'tmp') if self.file_type == self.TYPE_REMOTE: xbmc.log('[plugin.video.sportsaccess] file is in remote location: %s' % self.file_url, xbmc.LOGDEBUG) if not xbmcvfs.copy(self.file_url, tmp_file): xbmc.log( '[plugin.video.sportsaccess] Remote file couldn\'t be copied: %s' % self.file_url, xbmc.LOGERROR) else: f = open(tmp_file, 'wb') xbmc.log('[plugin.video.sportsaccess] file is on the internet', xbmc.LOGDEBUG) try: tmp_data = urllib2.urlopen(self.file_url) data = tmp_data.read() if tmp_data.info().get('content-encoding') == 'gzip': data = zlib.decompress(data, zlib.MAX_WBITS + 16) f.write(data) except urllib2.URLError as e: xbmc.log('[plugin.video.sportsaccess] Error downloading file: %s' % str(e), xbmc.LOGERROR) if self.show_popup: xbmcgui.Dialog().ok(ADDON.getAddonInfo('name'), '[COLOR red]Error downloading Guide Data![/COLOR]', str(e)) return self.FETCH_ERROR f.close() if os.path.getsize(tmp_file) > 256: if os.path.exists(self.file_path): os.remove(self.file_path) os.rename(tmp_file, self.file_path) ret_val = self.FETCH_OK xbmc.log('[plugin.video.sportsaccess] file %s was downloaded' % self.file_path, xbmc.LOGDEBUG) else: ret_val = self.FETCH_ERROR return ret_val
def autocrop_image(image, border = 0): from PIL import Image, ImageOps size = image.size bb_image = image bbox = bb_image.getbbox() if (size[0] == bbox[2]) and (size[1] == bbox[3]): bb_image=bb_image.convert("RGB") bb_image = ImageOps.invert(bb_image) bbox = bb_image.getbbox() image = image.crop(bbox) (width, height) = image.size width += border * 2 height += border * 2 ratio = float(width)/height cropped_image = Image.new("RGBA", (width, height), (0,0,0,0)) cropped_image.paste(image, (border, border)) #TODO find epg height logo_height = 450 / int(ADDON.getSetting('channels.per.page')) logo_height = logo_height - 2 if ADDON.getSetting('program.channel.logo') == "false": cropped_image = cropped_image.resize((int(logo_height*ratio), logo_height),Image.ANTIALIAS) return cropped_image
def login_popup(message=None): dialog = xbmcgui.Dialog() additional = 'or register if you don have an account at sportsaccess.se' if message: additional = message ret = dialog.yesno('[COLOR red]SportsAccess[/COLOR]', 'Please check your SportsAccess credentials', additional, '', 'Cancel', 'Login') if ret == 1: keyb = xbmc.Keyboard('', 'Enter Username') keyb.doModal() if (keyb.isConfirmed()): search = keyb.getText() username = search keyb = xbmc.Keyboard('', 'Enter Password:'******'skyusername', username) ADDON.setSetting('skypassword', password) return verify_login(username, password) return False
def generate_settings_file(target_path): source_path = xbmc.translatePath( os.path.join(ADDON.getAddonInfo('path'), 'resources', 'settings.xml')) root_target = ceT.Element("settings") tree_source = eT.parse(source_path) root_source = tree_source.getroot() for item in root_source.findall('category'): for setting in item.findall('setting'): if 'id' in setting.attrib: value = '' if 'default' in setting.attrib: value = setting.attrib['default'] ceT.SubElement(root_target, 'setting', id=setting.attrib['id'], value=value) tree_target = ceT.ElementTree(root_target) f = open(target_path, 'w') tree_target.write(f) f.close()
def VerifyKeymapMenu(): context = ADDON.getSetting('CONTEXT') == 'true' if not context: DeleteKeymap(KEYMAP_MENU) return True keymap = 'special://profile/keymaps' dst = os.path.join(keymap, KEYMAP_MENU) if sfile.exists(dst): return False src = os.path.join(HOME, 'resources', 'keymaps', KEYMAP_MENU) sfile.makedirs(keymap) sfile.copy(src, dst) return True
def save_setting(key, value, is_list=False): xbmc.log( '[%s] Tyring to save setting: key "%s" / value "%s"' % (ADDON.getAddonInfo('id'), key, str(value)), xbmc.LOGDEBUG) file_path = xbmc.translatePath( os.path.join(ADDON.getAddonInfo('profile'), 'settings.xml')) if not os.path.exists(file_path): generate_settings_file(file_path) tree = eT.parse(file_path) root = tree.getroot() updated = False for item in root.findall('setting'): if item.attrib['id'] == key: if is_list: cur_values = item.attrib['value'] if not cur_values: cur_values = [] else: cur_values = json.loads(cur_values) if isinstance(value, list): for val in value: if val not in cur_values: cur_values.append(val) else: if value not in cur_values: cur_values.append(value) item.attrib['value'] = json.dumps(cur_values) ADDON.setSetting(key, cur_values) else: item.attrib['value'] = value ADDON.setSetting(key, value) updated = True if updated: tree.write(file_path) return True
def save_setting(key, value, is_list=False): xbmc.log('[%s] Tyring to save setting: key "%s" / value "%s"' % (ADDON.getAddonInfo('id'), key, str(value)), xbmc.LOGDEBUG) file_path = xbmc.translatePath( os.path.join(ADDON.getAddonInfo('profile'), 'settings.xml')) if not os.path.exists(file_path): generate_settings_file(file_path) tree = eT.parse(file_path) root = tree.getroot() updated = False for item in root.findall('setting'): if item.attrib['id'] == key: if is_list: cur_values = item.attrib['value'] if not cur_values: cur_values = [] else: cur_values = json.loads(cur_values) if isinstance(value, list): for val in value: if val not in cur_values: cur_values.append(val) else: if value not in cur_values: cur_values.append(value) item.attrib['value'] = json.dumps(cur_values) ADDON.setSetting(key, cur_values) else: item.attrib['value'] = value ADDON.setSetting(key, value) updated = True if updated: tree.write(file_path) return True
def __new__(cls, database): return super(Scoreboard, cls).__new__(cls, 'script-tvguide-scoreboard.xml', ADDON.getAddonInfo('path'), OO0o) if 1 - 1: o0 - iii1I1I % i11iIiiIii + i11Ii11I1Ii1i.ooO
def __init__(self): self.database = source.Database(False) self.database.initialize(self.onInit) self.pluginData = xbmc.translatePath(os.path.join('special://profile', 'addon_data', ADDON.getAddonInfo('id')))
class FileFetcher(object): INTERVAL_ALWAYS = 0 INTERVAL_2 = 2 INTERVAL_6 = 6 INTERVAL_12 = 12 INTERVAL_24 = 24 INTERVAL_48 = 48 FETCH_ERROR = -1 FETCH_NOT_NEEDED = 0 FETCH_OK = 1 TYPE_DEFAULT = 1 TYPE_REMOTE = 2 base_path = xbmc.translatePath(ADDON.getAddonInfo('profile')) file_path = '' file_url = '' addon = None file_type = TYPE_DEFAULT def __init__(self, file_name, addon, show_popup=True, interval=None): self.addon = addon self.show_popup = show_popup if interval is None: interval = self.INTERVAL_2 self.interval = interval if file_name.startswith("http://") or file_name.startswith("sftp://") or file_name.startswith( "ftp://") or \ file_name.startswith("https://") or file_name.startswith( "ftps://") or file_name.startswith("smb://") or \ file_name.startswith("nfs://"): self.file_type = self.TYPE_REMOTE self.file_url = file_name self.file_path = os.path.join(self.base_path, file_name.split('/')[-1]) else: self.file_type = self.TYPE_DEFAULT user = addon.getSetting('skyusername') passw = addon.getSetting('skypassword') data = {'username': user, 'password': passw, 'type': file_name} data = urllib.urlencode(data) self.file_url = MAIN_URL + '?' + data self.file_path = os.path.join(self.base_path, file_name) # make sure the folder is actually there already! if not os.path.exists(self.base_path): os.makedirs(self.base_path) def fetch_file(self): ret_val = self.FETCH_NOT_NEEDED fetch = False if not os.path.exists(self.file_path): # always fetch if file doesn't exist! fetch = True else: interval = self.interval # int(self.addon.getSetting('xmltv.interval')) if interval != self.INTERVAL_ALWAYS: mod_time = datetime.datetime.fromtimestamp(os.path.getmtime(self.file_path)) td = datetime.datetime.now() - mod_time # need to do it this way cause Android doesn't support .total_seconds() :( diff = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6) / 10 ** 6 if ((interval == self.INTERVAL_2 and diff >= 7200) or (interval == self.INTERVAL_6 and diff >= 21600) or (interval == self.INTERVAL_12 and diff >= 43200) or (interval == self.INTERVAL_24 and diff >= 86400) or (interval == self.INTERVAL_48 and diff >= 172800)): fetch = True else: fetch = True if fetch: tmp_file = os.path.join(self.base_path, 'tmp') if self.file_type == self.TYPE_REMOTE: xbmc.log('[plugin.video.sportsaccess] file is in remote location: %s' % self.file_url, xbmc.LOGDEBUG) if not xbmcvfs.copy(self.file_url, tmp_file): xbmc.log( '[plugin.video.sportsaccess] Remote file couldn\'t be copied: %s' % self.file_url, xbmc.LOGERROR) else: f = open(tmp_file, 'wb') xbmc.log('[plugin.video.sportsaccess] file is on the internet', xbmc.LOGDEBUG) try: tmp_data = urllib2.urlopen(self.file_url) data = tmp_data.read() if tmp_data.info().get('content-encoding') == 'gzip': data = zlib.decompress(data, zlib.MAX_WBITS + 16) f.write(data) except urllib2.URLError as e: xbmc.log('[plugin.video.sportsaccess] Error downloading file: %s' % str(e), xbmc.LOGERROR) if self.show_popup: xbmcgui.Dialog().ok(ADDON.getAddonInfo('name'), '[COLOR red]Error downloading Guide Data![/COLOR]', str(e)) return self.FETCH_ERROR f.close() if os.path.getsize(tmp_file) > 256: if os.path.exists(self.file_path): os.remove(self.file_path) os.rename(tmp_file, self.file_path) ret_val = self.FETCH_OK xbmc.log('[plugin.video.sportsaccess] file %s was downloaded' % self.file_path, xbmc.LOGDEBUG) else: ret_val = self.FETCH_ERROR return ret_val
xbmc.log("[plugin.video.sportsaccess] No username or password configured!", xbmc.LOGWARNING) ok = False else: ok = verify_login(user, passw, False) if ok: xbmc.log("[plugin.video.sportsaccess] Service now being triggered...", xbmc.LOGNOTICE) Service() else: xbmc.log("[plugin.video.sportsaccess] Service cannot be triggered", xbmc.LOGWARNING) if __name__ == '__main__': # After a restart the proc file should be wiped! path = xbmc.translatePath(ADDON.getAddonInfo('profile')) if not os.path.exists(path): os.mkdir(path) f = open(PROC_FILE, 'w') f.write('') f.close() try: ADDON = xbmcaddon.Addon('plugin.video.sportsaccess') if ADDON.getSetting('autostart') == "true": xbmc.executebuiltin("RunAddon(plugin.video.sportsaccess)") monitor = xbmc.Monitor() xbmc.log("[plugin.video.sportsaccess] Background service started...", xbmc.LOGNOTICE) run_service()
return int(version[0]), int(version[1]) #major, minor eg, 13.9.902 def GETTEXT(id): text = ADDON.getLocalizedString(id) name = ADDON.getLocalizedString(30121) if name == DISPLAY: return text text = text.replace(name, DISPLAY) return text ADDONID = 'script.opentvguide' ADDON = xbmcaddon.Addon(ADDONID) HOME = ADDON.getAddonInfo('path') ROOT = ADDON.getSetting('FOLDER') PROFILE = os.path.join(ROOT, 'Super Favourites') VERSION = ADDON.getAddonInfo('version') ICON = os.path.join(HOME, 'icon.png') FANART = os.path.join(HOME, 'fanart.jpg') SEARCH = os.path.join(HOME, 'resources', 'media', 'search.png') DISPLAY = ADDON.getSetting('DISPLAYNAME') TITLE = GETTEXT(30000) DEBUG = ADDON.getSetting('DEBUG') == 'true' KEYMAP_HOT = 'super_favourites_hot.xml' KEYMAP_MENU = 'super_favourites_menu.xml' MAJOR, MINOR = GetXBMCVersion()
def UpdateKeymaps(): if ADDON.getSetting('HOTKEY') != GETTEXT(30111): #i.e. not programmable DeleteKeymap(KEYMAP_HOT) DeleteKeymap(KEYMAP_MENU) VerifyKeymaps()
def query_data(self): OOoOO00OOO0OO = d_t.datetime.now(pytz.timezone(self.time_zone)) iI1I111Ii111i = int(OOoOO00OOO0OO.strftime("%Y%m%d")) I11IiI1I11i1i = int(OOoOO00OOO0OO.strftime("%H%M")) if I11IiI1I11i1i < 400: if 38 - 38: Ii1I iI1I111Ii111i = int( (OOoOO00OOO0OO - d_t.timedelta(days=1)).strftime("%Y%m%d")) if 57 - 57: ooOoO / O00oOoOoO0o0O * ooO / I11i.o0 i1iIIi1 = {'in': [], 'pre': [], 'end': []} i11iIIIIIi1 = self.league try: iiII1i1 = urllib2.urlopen(self.url % (i11iIIIIIi1, iI1I111Ii111i)) o00oOO0o = iiII1i1.read() iiII1i1.close() OOO00O = o00oOO0o.replace('shsMSNBCTicker.loadGamesData(', '').replace(');', '') OOoOO0oo0ooO = json.loads(OOO00O) for O0o0O00Oo0o0 in OOoOO0oo0ooO.get('games', []): O00O0oOO00O00 = Et.XML(O0o0O00Oo0o0) if 11 - 11: i11Ii11I1Ii1i.iii1I1I if i11iIIIIIi1 == 'EPL': o0oo0oOo = O00O0oOO00O00.find('home-team') o000O0o = O00O0oOO00O00.find('visiting-team') else: o0oo0oOo = O00O0oOO00O00.find('visiting-team') o000O0o = O00O0oOO00O00.find('home-team') iI1iII1 = O00O0oOO00O00.find('gamestate') oO0OOoo0OO = o000O0o.get('nickname') O0 = o000O0o.get('alias') ii1ii1ii = o000O0o.get('score') oooooOoo0ooo = o0oo0oOo.get('nickname') I1I1IiI1 = o0oo0oOo.get('alias') III1iII1I1ii = o0oo0oOo.get('score') oOOo0 = iI1iII1.get('status') oo00O00oO = int( time.mktime( time.strptime( '%s %d' % (iI1iII1.get('gametime'), iI1I111Ii111i), '%I:%M %p %Y%m%d'))) if 23 - 23: OOooOOo + OOooOOo.O0oo0OO0 if oOOo0 == 'In-Progress': ii1ii11IIIiiI = 'in' elif oOOo0 == 'Pre-Game': ii1ii11IIIiiI = 'pre' else: ii1ii11IIIiiI = 'end' i1iIIi1[ii1ii11IIIiiI].append({ 'league': i11iIIIIIi1.upper(), 'orig-start': oo00O00oO, 'start': self._to_local_time(oo00O00oO).strftime("%I:%M %p").lstrip( '0'), 'home': oO0OOoo0OO, 'home-alias': O0.upper(), 'home-guide': self._get_mapped_team(i11iIIIIIi1, O0.upper()), 'away': oooooOoo0ooo, 'away-alias': I1I1IiI1.upper(), 'away-guide': self._get_mapped_team(i11iIIIIIi1, I1I1IiI1.upper()), 'home-score': ii1ii1ii, 'away-score': III1iII1I1ii, 'status': oOOo0, 'clock': iI1iII1.get('display_status1'), 'clock-section': iI1iII1.get('display_status2') }) except Exception, O00OOOoOoo0O: xbmc.log( "[%s] ERROR: %s" % (ADDON.getAddonInfo('id'), O00OOOoOoo0O.message), xbmc.LOGERROR) if 77 - 77: II % II * O00oOoOoO0o0O - i11iIiiIii
def get_kodi_version(): # retrieve current installed version jsonQuery = xbmc.executeJSONRPC( '{ "jsonrpc": "2.0", "method": "Application.GetProperties", "params": {"properties": ["version", "name"]}, "id": 1 }' ) jsonQuery = unicode(jsonQuery, 'utf-8', errors='ignore') jsonQuery = json.loads(jsonQuery) version = [] if jsonQuery.has_key('result') and jsonQuery['result'].has_key('version'): version = jsonQuery['result']['version'] return version['major'] if __name__ == '__main__': ok = True user = ADDON.getSetting('skyusername') passw = ADDON.getSetting('skypassword') if user == '' or passw == '': ok = login_popup() else: ok = verify_login(user, passw) if ok: # Apply Workaround for Kodi v17 on Android if xbmc.getCondVisibility('system.platform.android') and int( get_kodi_version()) == 17: ADDON.setSetting('background.stream', 'false') # After a restart the proc file should be wiped! f = open(PROC_FILE, 'w') f.write('')