def update_settings(): full_path = os.path.join(kodi.get_path(), 'resources', 'settings.xml') try: # open for append; skip update if it fails with open(full_path, 'a') as f: pass except Exception as e: log_utils.log('Dynamic settings update skipped: %s' % (e), log_utils.LOGWARNING) else: with open(full_path, 'r') as f: xml = f.read() new_settings = [] cat_count = 1 old_xml = xml classes = scraper.Scraper.__class__.__subclasses__(scraper.Scraper) # @UndefinedVariable classes += proxy.Proxy.__class__.__subclasses__(proxy.Proxy) # @UndefinedVariable for cls in sorted(classes, key=lambda x: x.get_name().upper()): if not cls.get_name() or cls.has_proxy(): continue new_settings += cls.get_settings() if len(new_settings) > 90: xml = update_xml(xml, new_settings, cat_count) new_settings = [] cat_count += 1 if new_settings: xml = update_xml(xml, new_settings, cat_count) if xml != old_xml: with open(full_path, 'w') as f: f.write(xml) else: log_utils.log('No Settings Update Needed', log_utils.LOGDEBUG)
def update_scraper(filename, scraper_url): try: if not filename: return py_path = os.path.join(kodi.get_path(), 'scrapers', filename) exists = os.path.exists(py_path) scraper_password = kodi.get_setting('scraper_password') if scraper_url and scraper_password: old_lm = None old_py = '' if exists: with open(py_path, 'r') as f: old_py = f.read() match = re.search('^#\s+Last-Modified:\s*(.*)', old_py) if match: old_lm = match.group(1).strip() new_lm, new_py = utils2.get_and_decrypt(scraper_url, scraper_password, old_lm) if new_py: logger.log( '%s path: %s, new_py: %s, match: %s' % (filename, py_path, bool(new_py), new_py == old_py), log_utils.LOGDEBUG) if old_py != new_py: with open(py_path, 'w') as f: f.write('# Last-Modified: %s\n' % (new_lm)) f.write(new_py) kodi.notify(msg=utils2.i18n('scraper_updated') + filename) except Exception as e: logger.log('Failure during %s scraper update: %s' % (filename, e), log_utils.LOGWARNING)
def do_auto_config(): ACTION_PREVIOUS_MENU = 10 ACTION_BACK = 92 CONTINUE_BUTTON = 200 CANCEL_BUTTON = 201 RADIO_BUTTONS = range(302, 316) class AutoConfDialog(xbmcgui.WindowXMLDialog): def onInit(self): log_utils.log('onInit:', log_utils.LOGDEBUG, COMPONENT) self.OK = False try: responses = json.loads(kodi.get_setting('prev_responses')) except: responses = [True] * len(RADIO_BUTTONS) if len(responses) < len(RADIO_BUTTONS): responses += [True] * (len(RADIO_BUTTONS) - len(responses)) for button, response in zip(RADIO_BUTTONS, responses): self.getControl(button).setSelected(response) def onAction(self, action): # log_utils.log('Action: %s' % (action.getId()), log_utils.LOGDEBUG, COMPONENT) if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK: self.close() def onControl(self, control): # log_utils.log('onControl: %s' % (control), log_utils.LOGDEBUG, COMPONENT) pass def onFocus(self, control): # log_utils.log('onFocus: %s' % (control), log_utils.LOGDEBUG, COMPONENT) pass def onClick(self, control): # log_utils.log('onClick: %s' % (control), log_utils.LOGDEBUG, COMPONENT) focus_button = self.getControl(control) if focus_button.getId() == RADIO_BUTTONS[-1]: all_status = focus_button.isSelected() for button in RADIO_BUTTONS: self.getControl(button).setSelected(all_status) if control == CONTINUE_BUTTON: self.OK = True if control == CANCEL_BUTTON: self.OK = False if control == CONTINUE_BUTTON or control == CANCEL_BUTTON: self.close() def get_responses(self): return [bool(self.getControl(button).isSelected()) for button in RADIO_BUTTONS] dialog = AutoConfDialog('AutoConfDialog.xml', kodi.get_path()) dialog.doModal() if dialog.OK: responses = dialog.get_responses() kodi.set_setting('prev_responses', json.dumps(responses)) perform_auto_conf(responses) del dialog
def do_auto_config(): ACTION_PREVIOUS_MENU = 10 ACTION_BACK = 92 CONTINUE_BUTTON = 200 CANCEL_BUTTON = 201 RADIO_BUTTONS = range(302, 316) class AutoConfDialog(xbmcgui.WindowXMLDialog): def onInit(self): logger.log('onInit:', log_utils.LOGDEBUG) self.OK = False try: responses = json.loads(kodi.get_setting('prev_responses')) except: responses = [True] * len(RADIO_BUTTONS) if len(responses) < len(RADIO_BUTTONS): responses += [True] * (len(RADIO_BUTTONS) - len(responses)) for button, response in zip(RADIO_BUTTONS, responses): self.getControl(button).setSelected(response) def onAction(self, action): # logger.log('Action: %s' % (action.getId()), log_utils.LOGDEBUG) if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK: self.close() def onControl(self, control): # logger.log('onControl: %s' % (control), log_utils.LOGDEBUG) pass def onFocus(self, control): # logger.log('onFocus: %s' % (control), log_utils.LOGDEBUG) pass def onClick(self, control): # logger.log('onClick: %s' % (control), log_utils.LOGDEBUG) focus_button = self.getControl(control) if focus_button.getId() == RADIO_BUTTONS[-1]: all_status = focus_button.isSelected() for button in RADIO_BUTTONS: self.getControl(button).setSelected(all_status) if control == CONTINUE_BUTTON: self.OK = True if control == CANCEL_BUTTON: self.OK = False if control == CONTINUE_BUTTON or control == CANCEL_BUTTON: self.close() def get_responses(self): return [bool(self.getControl(button).isSelected()) for button in RADIO_BUTTONS] dialog = AutoConfDialog('AutoConfDialog.xml', kodi.get_path()) dialog.doModal() if dialog.OK: responses = dialog.get_responses() kodi.set_setting('prev_responses', json.dumps(responses)) perform_auto_conf(responses) del dialog
def update_settings(): full_path = os.path.join(kodi.get_path(), 'resources', 'settings.xml') try: # open for append; skip update if it fails with open(full_path, 'a') as f: pass except Exception as e: logger.log('Dynamic settings update skipped: %s' % (e), log_utils.LOGWARNING) else: with open(full_path, 'r') as f: xml = f.read() new_settings = [] cat_count = 1 old_xml = xml classes = scraper.Scraper.__class__.__subclasses__(scraper.Scraper) # @UndefinedVariable classes += proxy.Proxy.__class__.__subclasses__(proxy.Proxy) # @UndefinedVariable for cls in sorted(classes, key=lambda x: x.get_name().upper()): if not cls.get_name() or cls.has_proxy(): continue new_settings += cls.get_settings() if len(new_settings) > 90: xml = update_xml(xml, new_settings, cat_count) new_settings = [] cat_count += 1 if new_settings: xml = update_xml(xml, new_settings, cat_count) if xml != old_xml: with open(full_path, 'w') as f: f.write(xml) else: logger.log('No Settings Update Needed', log_utils.LOGDEBUG)
def update_scraper(filename, scraper_url): try: if not filename: return py_path = os.path.join(kodi.get_path(), 'scrapers', filename) exists = os.path.exists(py_path) scraper_password = kodi.get_setting('scraper_password') if scraper_url and scraper_password: old_lm = None old_py = '' if exists: with open(py_path, 'r') as f: old_py = f.read() match = re.search('^#\s+Last-Modified:\s*(.*)', old_py) if match: old_lm = match.group(1).strip() new_lm, new_py = utils2.get_and_decrypt(scraper_url, scraper_password, old_lm) if new_py: logger.log('%s path: %s, new_py: %s, match: %s' % (filename, py_path, bool(new_py), new_py == old_py), log_utils.LOGDEBUG) if old_py != new_py: with open(py_path, 'w') as f: f.write('# Last-Modified: %s\n' % (new_lm)) f.write(new_py) kodi.notify(msg=utils2.i18n('scraper_updated') + filename) except Exception as e: logger.log('Failure during %s scraper update: %s' % (filename, e), log_utils.LOGWARNING)
def _initialize(self): self.connect() schema_file = kodi.vfs.join(kodi.get_path(), 'resources/database/schema.%s.sql' % self.db_type) if self.run_script(schema_file, commit=False): self.execute('DELETE FROM version WHERE 1', silent=True) self.execute('INSERT INTO version(db_version) VALUES(?)', [self.db_version], silent=True) self.commit() self.disconnect()
def art(name): path = os.path.join(THEME_PATH, name) if not xbmcvfs.exists(path): if name == "fanart.jpg": path = os.path.join(kodi.get_path(), name) else: path.replace(".png", ".jpg") return path
def art(name): path = os.path.join(THEME_PATH, name) if not xbmcvfs.exists(path): if name == 'fanart.jpg': path = os.path.join(kodi.get_path(), name) else: path = path.replace('.png', '.jpg') return path
def create(self, heading, line1='', line2='', line3=''): try: self.dialog = ProgressDialog.Window(DIALOG_XML, kodi.get_setting('xml_folder')) except: self.dialog = ProgressDialog.Window(DIALOG_XML, kodi.get_path()) self.dialog.show() self.dialog.setHeading(heading) self.dialog.setLine1(line1) self.dialog.setLine2(line2) self.dialog.setLine3(line3)
def art(name): path = os.path.join(THEME_PATH, name) if not xbmcvfs.exists(path): if name == 'fanart.jpg': path = os.path.join(kodi.get_path(), name) else: path.replace('.png', '.jpg') return path
def __add_editcontrol(self, x, y, height, width): media_path = os.path.join(kodi.get_path(), 'resources', 'skins', 'Default', 'media') temp = xbmcgui.ControlEdit(0, 0, 0, 0, '', font='font12', textColor='0xFFFFFFFF', focusTexture=os.path.join(media_path, 'button-focus2.png'), noFocusTexture=os.path.join(media_path, 'button-nofocus.png'), _alignment=CENTER_Y | CENTER_X) temp.setPosition(x, y) temp.setHeight(height) temp.setWidth(width) self.addControl(temp) return temp
def reset_base_url(): xml_path = os.path.join(kodi.get_path(), 'resources', 'settings.xml') tree = ET.parse(xml_path) for category in tree.getroot().findall('category'): if category.get('label').startswith('Scrapers '): for setting in category.findall('setting'): if setting.get('id').endswith('-base_url'): log_utils.log('Resetting: %s -> %s' % (setting.get('id'), setting.get('default')), xbmc.LOGDEBUG) kodi.set_setting(setting.get('id'), setting.get('default'))
def reset_base_url(): xml_path = os.path.join(kodi.get_path(), 'resources', 'settings.xml') tree = ET.parse(xml_path) for category in tree.getroot().findall('category'): if category.get('label').startswith('Scrapers '): for setting in category.findall('setting'): if re.search('-base_url\d*$', setting.get('id')): log_utils.log('Resetting: %s -> %s' % (setting.get('id'), setting.get('default')), xbmc.LOGDEBUG) kodi.set_setting(setting.get('id'), setting.get('default'))
def _initialize(self): self.connect() schema_file = kodi.vfs.join( kodi.get_path(), 'resources/database/schema.%s.sql' % self.db_type) if self.run_script(schema_file, commit=False): self.execute('DELETE FROM version WHERE 1') self.execute('INSERT INTO version(db_version) VALUES(?)', [self.db_version]) self.commit() self.disconnect()
def update_scraper(file_name, scraper_url, scraper_key): py_path = os.path.join(kodi.get_path(), 'scrapers', file_name) exists = os.path.exists(py_path) if not exists or (time.time() - os.path.getmtime(py_path)) > (8 * 60 * 60): new_py = utils2.get_and_decrypt(scraper_url, scraper_key) if new_py: if exists: with open(py_path, 'r') as f: old_py = f.read() else: old_py = '' logger.log('%s path: %s, new_py: %s, match: %s' % (__file__, py_path, bool(new_py), new_py == old_py), log_utils.LOGDEBUG) if old_py != new_py: with open(py_path, 'w') as f: f.write(new_py)
def _update_db(): db_ver = None if xbmcvfs.exists(DB_PATH): db_connection = db_utils.DBCache(DB_PATH) db_ver = db_connection.get_setting('db_version') db_connection.close() if db_ver != kodi.get_version(): try: zip_path = os.path.join(kodi.translate_path(kodi.get_path()), 'tmdb_cache.zip') zip_file = zipfile.ZipFile(zip_path, 'r') zip_file.extract(DB_NAME, DB_FOLDER) db_connection = db_utils.DBCache(DB_PATH) db_connection.set_setting('db_version', kodi.get_version()) finally: try: zip_file.close() except UnboundLocalError: pass
def update_scraper(filename, scraper_url): try: if not filename: return py_path = os.path.join(kodi.get_path(), 'scrapers', filename) exists = os.path.exists(py_path) scraper_password = kodi.get_setting('scraper_password') if scraper_url and scraper_password: new_py = utils2.get_and_decrypt(scraper_url, scraper_password) if new_py: if exists: with open(py_path, 'r') as f: old_py = f.read() else: old_py = '' log_utils.log('%s path: %s, new_py: %s, match: %s' % (filename, py_path, bool(new_py), new_py == old_py), log_utils.LOGDEBUG) if old_py != new_py: with open(py_path, 'w') as f: f.write(new_py) except Exception as e: log_utils.log('Failure during %s scraper update: %s' % (filename, e), log_utils.LOGWARNING)
import xbmc import xbmcaddon import xbmcvfs import xbmcgui import xbmcplugin import kodi import strings from constants import * THEME_LIST = ['Shine', 'Luna_Blue', 'Iconic', 'Simple', 'SALTy', 'SALTy (Blended)', 'SALTy (Blue)', 'SALTy (Frog)', 'SALTy (Green)', 'SALTy (Macaw)', 'SALTier (Green)', 'SALTier (Orange)', 'SALTier (Red)', 'IGDB', 'Simply Elegant', 'IGDB Redux'] THEME = THEME_LIST[int(kodi.get_setting('theme'))] if xbmc.getCondVisibility('System.HasAddon(script.salts.themepak)'): themepak_path = xbmcaddon.Addon('script.salts.themepak').getAddonInfo('path') else: themepak_path = kodi.get_path() THEME_PATH = os.path.join(themepak_path, 'art', 'themes', THEME) PLACE_POSTER = os.path.join(kodi.get_path(), 'resources', 'place_poster.png') SORT_FIELDS = [ (SORT_LIST[int(kodi.get_setting('sort1_field'))], SORT_SIGNS[kodi.get_setting('sort1_order')]), (SORT_LIST[int(kodi.get_setting('sort2_field'))], SORT_SIGNS[kodi.get_setting('sort2_order')]), (SORT_LIST[int(kodi.get_setting('sort3_field'))], SORT_SIGNS[kodi.get_setting('sort3_order')]), (SORT_LIST[int(kodi.get_setting('sort4_field'))], SORT_SIGNS[kodi.get_setting('sort4_order')]), (SORT_LIST[int(kodi.get_setting('sort5_field'))], SORT_SIGNS[kodi.get_setting('sort5_order')]), (SORT_LIST[int(kodi.get_setting('sort6_field'))], SORT_SIGNS[kodi.get_setting('sort6_order')])] def art(name): path = os.path.join(THEME_PATH, name) if not xbmcvfs.exists(path): if name == 'fanart.jpg':
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. *''' import kodi import time import xbmcgui import zipfile try: from libs import requests except: path = kodi.vfs.join(kodi.get_path(), "libs") sys.path.append(path) import requests class downloaderException(Exception): pass def format_speed(speed): if speed > 2000: speed = float(speed) / 1000 speed = "Speed %.2f MB/s" % speed else: speed = "Speed %.0f KB/s" % speed return speed
def do_ip_auth(scraper, visit_url, qr_code): EXPIRE_DURATION = 60 * 5 ACTION_PREVIOUS_MENU = 10 ACTION_BACK = 92 CANCEL_BUTTON = 200 INSTR_LABEL = 101 QR_CODE_CTRL = 102 PROGRESS_CTRL = 103 class IpAuthDialog(xbmcgui.WindowXMLDialog): def onInit(self): # log_utils.log('onInit:', log_utils.LOGDEBUG) self.cancel = False self.getControl(INSTR_LABEL).setLabel(i18n('ip_auth_line1') + visit_url + i18n('ip_auth_line2')) self.progress = self.getControl(PROGRESS_CTRL) self.progress.setPercent(100) if qr_code: img = self.getControl(QR_CODE_CTRL) img.setImage(qr_code) def onAction(self, action): # log_utils.log('Action: %s' % (action.getId()), log_utils.LOGDEBUG) if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK: self.cancel = True self.close() def onControl(self, control): # log_utils.log('onControl: %s' % (control), log_utils.LOGDEBUG) pass def onFocus(self, control): # log_utils.log('onFocus: %s' % (control), log_utils.LOGDEBUG) pass def onClick(self, control): # log_utils.log('onClick: %s' % (control), log_utils.LOGDEBUG) if control == CANCEL_BUTTON: self.cancel = True self.close() def setProgress(self, progress): self.progress.setPercent(progress) dialog = IpAuthDialog('IpAuthDialog.xml', kodi.get_path()) dialog.show() interval = 5000 begin = time.time() try: while True: for _ in range(INTERVALS): kodi.sleep(interval / INTERVALS) elapsed = time.time() - begin progress = int((EXPIRE_DURATION - elapsed) * 100 / EXPIRE_DURATION) dialog.setProgress(progress) if progress <= 0 or dialog.cancel: return False authorized, result = scraper.check_auth() if authorized: return result finally: del dialog
def do_auto_config(): ACTION_PREVIOUS_MENU = 10 ACTION_BACK = 92 CONTINUE_BUTTON = 200 CANCEL_BUTTON = 201 starty = 60 posx = 30 gap = 35 RADIO_BUTTONS = [ i18n('set_trakt_timeout'), i18n('set_cal_start'), i18n('set_cal_airtime'), i18n('set_scraper_timeout'), i18n('set_wl_mne'), i18n('set_test_direct'), i18n('set_filter_unusable'), i18n('set_show_debrid'), i18n('set_no_limit'), i18n('set_source_sort'), i18n('set_sso'), i18n('set_reset_url'), i18n('select_all_none') ] class AutoConfDialog(xbmcgui.WindowXMLDialog): def onInit(self): log_utils.log('onInit:', log_utils.LOGDEBUG) self.OK = False self.radio_buttons = [] posy = starty for label in RADIO_BUTTONS: self.radio_buttons.append( self.__get_radio_button(posx, posy, label)) posy += gap try: responses = json.loads(kodi.get_setting('prev_responses')) except: responses = [True] * len(self.radio_buttons) if len(responses) < len(self.radio_buttons): responses += [True ] * (len(self.radio_buttons) - len(responses)) self.addControls(self.radio_buttons) last_button = None for response, radio_button in zip(responses, self.radio_buttons): radio_button.setSelected(response) if last_button is not None: radio_button.controlUp(last_button) radio_button.controlLeft(last_button) last_button.controlDown(radio_button) last_button.controlRight(radio_button) last_button = radio_button continue_ctrl = self.getControl(CONTINUE_BUTTON) cancel_ctrl = self.getControl(CANCEL_BUTTON) self.radio_buttons[0].controlUp(cancel_ctrl) self.radio_buttons[0].controlLeft(cancel_ctrl) self.radio_buttons[-1].controlDown(continue_ctrl) self.radio_buttons[-1].controlRight(continue_ctrl) continue_ctrl.controlUp(self.radio_buttons[-1]) continue_ctrl.controlLeft(self.radio_buttons[-1]) cancel_ctrl.controlDown(self.radio_buttons[0]) cancel_ctrl.controlRight(self.radio_buttons[0]) def __get_radio_button(self, x, y, label): kwargs = { 'font': 'font12', 'focusTexture': 'button-focus2.png', 'noFocusTexture': 'button-nofocus.png', 'focusOnTexture': 'radiobutton-focus.png', 'noFocusOnTexture': 'radiobutton-focus.png', 'focusOffTexture': 'radiobutton-nofocus.png', 'noFocusOffTexture': 'radiobutton-nofocus.png' } temp = xbmcgui.ControlRadioButton(x, y, 450, 30, label, **kwargs) return temp def onAction(self, action): # log_utils.log('Action: %s' % (action.getId()), log_utils.LOGDEBUG) if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK: self.close() def onControl(self, control): # log_utils.log('onControl: %s' % (control), log_utils.LOGDEBUG) pass def onFocus(self, control): # log_utils.log('onFocus: %s' % (control), log_utils.LOGDEBUG) pass def onClick(self, control): # log_utils.log('onClick: %s' % (control), log_utils.LOGDEBUG) focus_button = self.getControl(control) if focus_button == self.radio_buttons[-1]: all_status = focus_button.isSelected() for button in self.radio_buttons: button.setSelected(all_status) if control == CONTINUE_BUTTON: self.OK = True if control == CANCEL_BUTTON: self.OK = False if control == CONTINUE_BUTTON or control == CANCEL_BUTTON: self.close() def get_responses(self): return [bool(button.isSelected()) for button in self.radio_buttons] dialog = AutoConfDialog('AutoConfDialog.xml', kodi.get_path()) dialog.doModal() if dialog.OK: responses = dialog.get_responses() kodi.set_setting('prev_responses', json.dumps(responses)) perform_auto_conf(responses) del dialog
import pyaes from constants import * from kodi import i18n THEME_LIST = [ 'Shine', 'Luna_Blue', 'Iconic', 'Simple', 'SALTy', 'SALTy (Blended)', 'SALTy (Blue)', 'SALTy (Frog)', 'SALTy (Green)', 'SALTy (Macaw)', 'SALTier (Green)', 'SALTier (Orange)', 'SALTier (Red)', 'IGDB', 'Simply Elegant', 'IGDB Redux', 'NaCl' ] THEME = THEME_LIST[int(kodi.get_setting('theme'))] if xbmc.getCondVisibility('System.HasAddon(script.salts.themepak)'): themepak_path = xbmcaddon.Addon('plugin.video.saltsrd.lite').getAddonInfo( 'path') else: themepak_path = kodi.get_path() THEME_PATH = os.path.join(themepak_path, 'art', 'themes', THEME) PLACE_POSTER = os.path.join(kodi.get_path(), 'resources', 'place_poster.png') SORT_FIELDS = [(SORT_LIST[int(kodi.get_setting('sort1_field'))], SORT_SIGNS[kodi.get_setting('sort1_order')]), (SORT_LIST[int(kodi.get_setting('sort2_field'))], SORT_SIGNS[kodi.get_setting('sort2_order')]), (SORT_LIST[int(kodi.get_setting('sort3_field'))], SORT_SIGNS[kodi.get_setting('sort3_order')]), (SORT_LIST[int(kodi.get_setting('sort4_field'))], SORT_SIGNS[kodi.get_setting('sort4_order')]), (SORT_LIST[int(kodi.get_setting('sort5_field'))], SORT_SIGNS[kodi.get_setting('sort5_order')]), (SORT_LIST[int(kodi.get_setting('sort6_field'))], SORT_SIGNS[kodi.get_setting('sort6_order')])]
def get_pin(): AUTH_BUTTON = 200 LATER_BUTTON = 201 NEVER_BUTTON = 202 ACTION_PREVIOUS_MENU = 10 ACTION_BACK = 92 CENTER_Y = 6 CENTER_X = 2 class PinAuthDialog(xbmcgui.WindowXMLDialog): auth = False def onInit(self): self.pin_edit_control = self.__add_editcontrol(30, 240, 40, 550) self.setFocus(self.pin_edit_control) auth = self.getControl(AUTH_BUTTON) never = self.getControl(NEVER_BUTTON) self.pin_edit_control.controlUp(never) self.pin_edit_control.controlLeft(never) self.pin_edit_control.controlDown(auth) self.pin_edit_control.controlRight(auth) auth.controlUp(self.pin_edit_control) auth.controlLeft(self.pin_edit_control) never.controlDown(self.pin_edit_control) never.controlRight(self.pin_edit_control) def onAction(self, action): # print 'Action: %s' % (action.getId()) if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK: self.close() def onControl(self, control): # print 'onControl: %s' % (control) pass def onFocus(self, control): # print 'onFocus: %s' % (control) pass def onClick(self, control): # print 'onClick: %s' % (control) if control == AUTH_BUTTON: print "PIN INPUT" if not self.__get_token(): kodi.notify(header='Not Authorized', msg='Using Standard Menus', duration=5000, sound=None) #self.auth = True if control == NEVER_BUTTON: #xbmc.executebuiltin('RunPlugin(%s)' % addon.build_plugin_url({'mode':None})) kodi.notify(header='Not Authorized', msg='Using Standard Menus', duration=5000, sound=None) # kodi.notify(msg=i18n('use_addon_settings'), duration=5000) # kodi.set_setting('last_reminder', '-1') if control in [AUTH_BUTTON, LATER_BUTTON, NEVER_BUTTON]: self.close() def __get_token(self): pin = self.pin_edit_control.getText().strip() if pin: try: trakt_api = trakt.TraktAPI() trakt_api.authorize(pin=pin) # trakt_api = Trakt_API(use_https=use_https, timeout=trakt_timeout) # result = trakt_api.get_token(pin=pin) # kodi.set_setting('trakt_oauth_token', result['access_token']) # kodi.set_setting('trakt_refresh_token', result['refresh_token']) # profile = trakt_api.get_user_profile(cached=False) # kodi.set_setting('trakt_user', '%s (%s)' % (profile['username'], profile['name'])) return True except Exception as e: log_utils.log('Trakt Authorization Failed: %s' % (e), log_utils.LOGDEBUG) return False return False # have to add edit controls programatically because getControl() (hard) crashes XBMC on them def __add_editcontrol(self, x, y, height, width): media_path = os.path.join(kodi.get_path(), 'resources', 'skins', 'Default', 'media') temp = xbmcgui.ControlEdit( 5, 5, 5, 5, '', font='font12', textColor='0xFFFFFFFF', focusTexture=os.path.join(media_path, 'button-focus2.png'), noFocusTexture=os.path.join(media_path, 'button-nofocus.png'), _alignment=CENTER_Y | CENTER_X) temp.setPosition(x, y) temp.setHeight(height) temp.setWidth(width) self.addControl(temp) return temp dialog = PinAuthDialog('TraktPinAuthDialog.xml', kodi.get_path()) dialog.doModal() del dialog
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcgui import time import os import kodi import random import json from utils import reset_base_url from trans_utils import i18n from trakt_api import Trakt_API from salts_lib import log_utils ICON_PATH = os.path.join(kodi.get_path(), 'icon.png') use_https = kodi.get_setting('use_https') == 'true' trakt_timeout = int(kodi.get_setting('trakt_timeout')) def get_pin(): AUTH_BUTTON = 200 LATER_BUTTON = 201 NEVER_BUTTON = 202 ACTION_PREVIOUS_MENU = 10 ACTION_BACK = 92 CENTER_Y = 6 CENTER_X = 2 class PinAuthDialog(xbmcgui.WindowXMLDialog): auth = False
import xbmcvfs import log_utils import sys import urlparse import urllib import urllib2 import traceback import kodi from constants import * from trans_utils import i18n from scrapers import * # import all scrapers into this namespace from trakt_api import Trakt_API from db_utils import DB_Connection import threading ICON_PATH = os.path.join(kodi.get_path(), "icon.png") SORT_FIELDS = [ (SORT_LIST[int(kodi.get_setting("sort1_field"))], SORT_SIGNS[kodi.get_setting("sort1_order")]), (SORT_LIST[int(kodi.get_setting("sort2_field"))], SORT_SIGNS[kodi.get_setting("sort2_order")]), (SORT_LIST[int(kodi.get_setting("sort3_field"))], SORT_SIGNS[kodi.get_setting("sort3_order")]), (SORT_LIST[int(kodi.get_setting("sort4_field"))], SORT_SIGNS[kodi.get_setting("sort4_order")]), (SORT_LIST[int(kodi.get_setting("sort5_field"))], SORT_SIGNS[kodi.get_setting("sort5_order")]), (SORT_LIST[int(kodi.get_setting("sort6_field"))], SORT_SIGNS[kodi.get_setting("sort6_order")]), ] last_check = datetime.datetime.fromtimestamp(0) TOKEN = kodi.get_setting("trakt_oauth_token") use_https = kodi.get_setting("use_https") == "true" trakt_timeout = int(kodi.get_setting("trakt_timeout")) list_size = int(kodi.get_setting("list_size"))
def do_auto_config(): ACTION_PREVIOUS_MENU = 10 ACTION_BACK = 92 CONTINUE_BUTTON = 200 CANCEL_BUTTON = 201 starty = 60 posx = 30 gap = 35 RADIO_BUTTONS = [ i18n('set_trakt_timeout'), i18n('set_cal_start'), i18n('set_cal_airtime'), i18n('set_scraper_timeout'), i18n('set_wl_mne'), i18n('set_test_direct'), i18n('set_filter_unusable'), i18n('set_show_debrid'), i18n('set_no_limit'), i18n('set_source_sort'), i18n('set_sso'), i18n('set_reset_url'), i18n('select_all_none')] class AutoConfDialog(xbmcgui.WindowXMLDialog): def onInit(self): log_utils.log('onInit:', log_utils.LOGDEBUG) self.OK = False self.radio_buttons = [] posy = starty for label in RADIO_BUTTONS: self.radio_buttons.append(self.__get_radio_button(posx, posy, label)) posy += gap try: responses = json.loads(kodi.get_setting('prev_responses')) except: responses = [True] * len(self.radio_buttons) if len(responses) < len(self.radio_buttons): responses += [True] * (len(self.radio_buttons) - len(responses)) self.addControls(self.radio_buttons) last_button = None for response, radio_button in zip(responses, self.radio_buttons): radio_button.setSelected(response) if last_button is not None: radio_button.controlUp(last_button) radio_button.controlLeft(last_button) last_button.controlDown(radio_button) last_button.controlRight(radio_button) last_button = radio_button continue_ctrl = self.getControl(CONTINUE_BUTTON) cancel_ctrl = self.getControl(CANCEL_BUTTON) self.radio_buttons[0].controlUp(cancel_ctrl) self.radio_buttons[0].controlLeft(cancel_ctrl) self.radio_buttons[-1].controlDown(continue_ctrl) self.radio_buttons[-1].controlRight(continue_ctrl) continue_ctrl.controlUp(self.radio_buttons[-1]) continue_ctrl.controlLeft(self.radio_buttons[-1]) cancel_ctrl.controlDown(self.radio_buttons[0]) cancel_ctrl.controlRight(self.radio_buttons[0]) def __get_radio_button(self, x, y, label): kwargs = {'font': 'font12', 'focusTexture': 'button-focus2.png', 'noFocusTexture': 'button-nofocus.png', 'focusOnTexture': 'radiobutton-focus.png', 'noFocusOnTexture': 'radiobutton-focus.png', 'focusOffTexture': 'radiobutton-nofocus.png', 'noFocusOffTexture': 'radiobutton-nofocus.png'} temp = xbmcgui.ControlRadioButton(x, y, 450, 30, label, **kwargs) return temp def onAction(self, action): # log_utils.log('Action: %s' % (action.getId()), log_utils.LOGDEBUG) if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK: self.close() def onControl(self, control): # log_utils.log('onControl: %s' % (control), log_utils.LOGDEBUG) pass def onFocus(self, control): # log_utils.log('onFocus: %s' % (control), log_utils.LOGDEBUG) pass def onClick(self, control): # log_utils.log('onClick: %s' % (control), log_utils.LOGDEBUG) focus_button = self.getControl(control) if focus_button == self.radio_buttons[-1]: all_status = focus_button.isSelected() for button in self.radio_buttons: button.setSelected(all_status) if control == CONTINUE_BUTTON: self.OK = True if control == CANCEL_BUTTON: self.OK = False if control == CONTINUE_BUTTON or control == CANCEL_BUTTON: self.close() def get_responses(self): return [bool(button.isSelected()) for button in self.radio_buttons] dialog = AutoConfDialog('AutoConfDialog.xml', kodi.get_path()) dialog.doModal() if dialog.OK: responses = dialog.get_responses() kodi.set_setting('prev_responses', json.dumps(responses)) perform_auto_conf(responses) del dialog
""" import os import time import urllib2 import re import HTMLParser import socket import xbmc import xbmcvfs import log_utils import kodi from constants import VIDEO_TYPES from constants import SRT_SOURCE from db_utils import DB_Connection ADDON_PATH = kodi.get_path() ICON_PATH = os.path.join(ADDON_PATH, 'icon.png') MAX_RETRIES = 2 TEMP_ERRORS = [500, 502, 503, 504] USER_AGENT = ("User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64)" "AppleWebKit/537.17 (KHTML, like Gecko)" "Chrome/24.0.1312.56") BASE_URL = 'http://www.addic7ed.com' BASE_PATH = kodi.get_setting('subtitle-folder') db_connection = DB_Connection() class SRT_Scraper(): def __init__(self): pass
def __init__(self, *args, **kwargs): bg_image = os.path.join(kodi.get_path(), 'resources', 'skins', 'Default', 'media', 'DialogBack2.png') check_image = os.path.join(kodi.get_path(), 'resources', 'skins', 'Default', 'media', 'checked.png') self.cancelled = False self.chk = [0] * 9 self.chkbutton = [0] * 9 self.chkstate = [False] * 9 imgX, imgY, imgw, imgh = 436, 210, 408, 300 ph, pw = imgh / 3, imgw / 3 x_gap = 70 y_gap = 70 button_gap = 40 button_h = 40 button_y = imgY + imgh + button_gap middle = imgX + (imgw / 2) win_x = imgX - x_gap win_y = imgY - y_gap win_h = imgh + 2 * y_gap + button_h + button_gap win_w = imgw + 2 * x_gap ctrlBackgound = xbmcgui.ControlImage(win_x, win_y, win_w, win_h, bg_image) self.addControl(ctrlBackgound) self.msg = '[COLOR red]%s[/COLOR]' % (kwargs.get('msg')) self.strActionInfo = xbmcgui.ControlLabel(imgX, imgY - 30, imgw, 20, self.msg, 'font13') self.addControl(self.strActionInfo) img = xbmcgui.ControlImage(imgX, imgY, imgw, imgh, kwargs.get('captcha')) self.addControl(img) self.iteration = kwargs.get('iteration') self.strActionInfo = xbmcgui.ControlLabel(imgX, imgY + imgh, imgw, 20, 'Captcha Round: %s [I](2 Rounds is typical)[/I]' % (str(self.iteration)), 'font40') self.addControl(self.strActionInfo) self.cancelbutton = xbmcgui.ControlButton(middle - 110, button_y, 100, button_h, 'Cancel', alignment=2) self.okbutton = xbmcgui.ControlButton(middle + 10, button_y, 100, button_h, 'OK', alignment=2) self.addControl(self.okbutton) self.addControl(self.cancelbutton) for i in xrange(9): row = i / 3 col = i % 3 x_pos = imgX + (pw * col) y_pos = imgY + (ph * row) self.chk[i] = xbmcgui.ControlImage(x_pos, y_pos, pw, ph, check_image) self.addControl(self.chk[i]) self.chk[i].setVisible(False) self.chkbutton[i] = xbmcgui.ControlButton(x_pos, y_pos, pw, ph, str(i + 1), font='font1') self.addControl(self.chkbutton[i]) for i in xrange(9): row_start = (i / 3) * 3 right = row_start + (i + 1) % 3 left = row_start + (i - 1) % 3 up = (i - 3) % 9 down = (i + 3) % 9 self.chkbutton[i].controlRight(self.chkbutton[right]) self.chkbutton[i].controlLeft(self.chkbutton[left]) if i <= 2: self.chkbutton[i].controlUp(self.okbutton) else: self.chkbutton[i].controlUp(self.chkbutton[up]) if i >= 6: self.chkbutton[i].controlDown(self.okbutton) else: self.chkbutton[i].controlDown(self.chkbutton[down]) self.okbutton.controlLeft(self.cancelbutton) self.okbutton.controlRight(self.cancelbutton) self.cancelbutton.controlLeft(self.okbutton) self.cancelbutton.controlRight(self.okbutton) self.okbutton.controlDown(self.chkbutton[2]) self.okbutton.controlUp(self.chkbutton[8]) self.cancelbutton.controlDown(self.chkbutton[0]) self.cancelbutton.controlUp(self.chkbutton[6]) self.setFocus(self.okbutton)
def __init__(self, *args, **kwargs): # @UnusedVariable media_path = os.path.join(kodi.get_path(), 'resources', 'skins', 'Default', 'media') bg_image = os.path.join(media_path, 'DialogBack2.png') check_image = os.path.join(media_path, 'checked.png') button_fo = os.path.join(media_path, 'button-fo.png') button_nofo = os.path.join(media_path, 'button-nofo.png') self.cancelled = False self.chk = [0] * 9 self.chkbutton = [0] * 9 self.chkstate = [False] * 9 imgX, imgY, imgw, imgh = 436, 210, 408, 300 ph, pw = imgh / 3, imgw / 3 x_gap = 70 y_gap = 70 button_gap = 40 button_h = 40 button_y = imgY + imgh + button_gap middle = imgX + (imgw / 2) win_x = imgX - x_gap win_y = imgY - y_gap win_h = imgh + 2 * y_gap + button_h + button_gap win_w = imgw + 2 * x_gap ctrlBackgound = xbmcgui.ControlImage(win_x, win_y, win_w, win_h, bg_image) self.addControl(ctrlBackgound) self.msg = '[COLOR red]%s[/COLOR]' % (kwargs.get('msg')) self.strActionInfo = xbmcgui.ControlLabel(imgX, imgY - 30, imgw, 20, self.msg, 'font13') self.addControl(self.strActionInfo) img = xbmcgui.ControlImage(imgX, imgY, imgw, imgh, kwargs.get('captcha')) self.addControl(img) self.iteration = kwargs.get('iteration') name = kwargs.get('name') name = 'for: [I]%s[/I]' % (name) if name is not None else '' self.strActionInfo = xbmcgui.ControlLabel( imgX, imgY + imgh, imgw, 20, 'Captcha Round: %s %s' % (self.iteration, name), 'font40') self.addControl(self.strActionInfo) self.cancelbutton = xbmcgui.ControlButton(middle - 110, button_y, 100, button_h, 'Cancel', focusTexture=button_fo, noFocusTexture=button_nofo, alignment=2) self.okbutton = xbmcgui.ControlButton(middle + 10, button_y, 100, button_h, 'OK', focusTexture=button_fo, noFocusTexture=button_nofo, alignment=2) self.addControl(self.okbutton) self.addControl(self.cancelbutton) for i in xrange(9): row = i / 3 col = i % 3 x_pos = imgX + (pw * col) y_pos = imgY + (ph * row) self.chk[i] = xbmcgui.ControlImage(x_pos, y_pos, pw, ph, check_image) self.addControl(self.chk[i]) self.chk[i].setVisible(False) self.chkbutton[i] = xbmcgui.ControlButton( x_pos, y_pos, pw, ph, str(i + 1), font='font1', focusTexture=button_fo, noFocusTexture=button_nofo) self.addControl(self.chkbutton[i]) for i in xrange(9): row_start = (i / 3) * 3 right = row_start + (i + 1) % 3 left = row_start + (i - 1) % 3 up = (i - 3) % 9 down = (i + 3) % 9 self.chkbutton[i].controlRight(self.chkbutton[right]) self.chkbutton[i].controlLeft(self.chkbutton[left]) if i <= 2: self.chkbutton[i].controlUp(self.okbutton) else: self.chkbutton[i].controlUp(self.chkbutton[up]) if i >= 6: self.chkbutton[i].controlDown(self.okbutton) else: self.chkbutton[i].controlDown(self.chkbutton[down]) self.okbutton.controlLeft(self.cancelbutton) self.okbutton.controlRight(self.cancelbutton) self.cancelbutton.controlLeft(self.okbutton) self.cancelbutton.controlRight(self.okbutton) self.okbutton.controlDown(self.chkbutton[2]) self.okbutton.controlUp(self.chkbutton[8]) self.cancelbutton.controlDown(self.chkbutton[0]) self.cancelbutton.controlUp(self.chkbutton[6]) self.setFocus(self.okbutton)
import os import time import urllib2 import re import HTMLParser import socket import xbmc import xbmcvfs import log_utils import kodi from constants import VIDEO_TYPES from constants import SRT_SOURCE from constants import USER_AGENT from db_utils import DB_Connection ADDON_PATH = kodi.get_path() ICON_PATH = os.path.join(ADDON_PATH, 'icon.png') MAX_RETRIES = 2 TEMP_ERRORS = [500, 502, 503, 504] BASE_URL = 'http://www.addic7ed.com' BASE_PATH = kodi.get_setting('subtitle-folder') db_connection = DB_Connection() class SRT_Scraper(): def __init__(self): pass def get_tvshow_id(self, title, year=None): match_title = title.lower() rows = db_connection.get_related_url(VIDEO_TYPES.TVSHOW, title, year, SRT_SOURCE) if rows:
along with this program. If not, see <http://www.gnu.org/licenses/>. """ import xbmcgui, xbmc, sys import time import os import kodi import random import json from libs import log_utils from t0mm0.common.addon import Addon from libs import trakt addon_id = kodi.addon_id addon = Addon(addon_id, sys.argv) ICON_PATH = os.path.join(kodi.get_path(), 'icon.png') #use_https = kodi.get_setting('use_https') == 'true' #trakt_timeout = int(kodi.get_setting('trakt_timeout')) def get_pin(): AUTH_BUTTON = 200 LATER_BUTTON = 201 NEVER_BUTTON = 202 ACTION_PREVIOUS_MENU = 10 ACTION_BACK = 92 CENTER_Y = 6 CENTER_X = 2 class PinAuthDialog(xbmcgui.WindowXMLDialog): auth = False
import xbmcaddon import xbmcvfs import kodi import pyaes from constants import * # @UnusedWildImport from salts_lib import strings logger = log_utils.Logger.get_logger() THEME_LIST = ['Shine', 'Luna_Blue', 'Iconic', 'Simple', 'SALTy', 'SALTy (Blended)', 'SALTy (Blue)', 'SALTy (Frog)', 'SALTy (Green)', 'SALTy (Macaw)', 'SALTier (Green)', 'SALTier (Orange)', 'SALTier (Red)', 'IGDB', 'Simply Elegant', 'IGDB Redux', 'NaCl'] THEME = THEME_LIST[int(kodi.get_setting('theme') or 0)] if kodi.has_addon('script.salts.themepak'): themepak_path = xbmcaddon.Addon('script.salts.themepak').getAddonInfo('path') else: themepak_path = kodi.get_path() THEME_PATH = os.path.join(themepak_path, 'art', 'themes', THEME) translations = kodi.Translations(strings.STRINGS) SORT_FIELDS = [ (SORT_LIST[int(kodi.get_setting('sort1_field'))], SORT_SIGNS[kodi.get_setting('sort1_order')]), (SORT_LIST[int(kodi.get_setting('sort2_field'))], SORT_SIGNS[kodi.get_setting('sort2_order')]), (SORT_LIST[int(kodi.get_setting('sort3_field'))], SORT_SIGNS[kodi.get_setting('sort3_order')]), (SORT_LIST[int(kodi.get_setting('sort4_field'))], SORT_SIGNS[kodi.get_setting('sort4_order')]), (SORT_LIST[int(kodi.get_setting('sort5_field'))], SORT_SIGNS[kodi.get_setting('sort5_order')]), (SORT_LIST[int(kodi.get_setting('sort6_field'))], SORT_SIGNS[kodi.get_setting('sort6_order')])] def art(name): path = os.path.join(THEME_PATH, name) if not xbmcvfs.exists(path): if name == 'fanart.jpg':
def get_pin(): AUTH_BUTTON = 200 LATER_BUTTON = 201 NEVER_BUTTON = 202 ACTION_PREVIOUS_MENU = 10 ACTION_BACK = 92 CENTER_Y = 6 CENTER_X = 2 class PinAuthDialog(xbmcgui.WindowXMLDialog): auth = False def onInit(self): self.pin_edit_control = self.__add_editcontrol(30, 240, 40, 450) self.setFocus(self.pin_edit_control) auth = self.getControl(AUTH_BUTTON) never = self.getControl(NEVER_BUTTON) self.pin_edit_control.controlUp(never) self.pin_edit_control.controlLeft(never) self.pin_edit_control.controlDown(auth) self.pin_edit_control.controlRight(auth) auth.controlUp(self.pin_edit_control) auth.controlLeft(self.pin_edit_control) never.controlDown(self.pin_edit_control) never.controlRight(self.pin_edit_control) def onAction(self, action): #print 'Action: %s' % (action.getId()) if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK: self.close() def onControl(self, control): #print 'onControl: %s' % (control) pass def onFocus(self, control): #print 'onFocus: %s' % (control) pass def onClick(self, control): #print 'onClick: %s' % (control) if control == AUTH_BUTTON: if not self.__get_token(): kodi.notify(msg=i18n('pin_auth_failed'), duration=5000) return self.auth = True if control == LATER_BUTTON: kodi.notify(msg=i18n('remind_in_24hrs'), duration=5000) kodi.set_setting('last_reminder', str(int(time.time()))) if control == NEVER_BUTTON: kodi.notify(msg=i18n('use_addon_settings'), duration=5000) kodi.set_setting('last_reminder', '-1') if control in [AUTH_BUTTON, LATER_BUTTON, NEVER_BUTTON]: self.close() def __get_token(self): pin = self.pin_edit_control.getText().strip() if pin: try: trakt_api = Trakt_API(use_https=use_https, timeout=trakt_timeout) result = trakt_api.get_token(pin=pin) kodi.set_setting('trakt_oauth_token', result['access_token']) kodi.set_setting('trakt_refresh_token', result['refresh_token']) profile = trakt_api.get_user_profile(cached=False) kodi.set_setting( 'trakt_user', '%s (%s)' % (profile['username'], profile['name'])) return True except: return False return False # have to add edit controls programatically because getControl() (hard) crashes XBMC on them def __add_editcontrol(self, x, y, height, width): media_path = os.path.join(kodi.get_path(), 'resources', 'skins', 'Default', 'media') temp = xbmcgui.ControlEdit( 0, 0, 0, 0, '', font='font12', textColor='0xFFFFFFFF', focusTexture=os.path.join(media_path, 'button-focus2.png'), noFocusTexture=os.path.join(media_path, 'button-nofocus.png'), _alignment=CENTER_Y | CENTER_X) temp.setPosition(x, y) temp.setHeight(height) temp.setWidth(width) self.addControl(temp) return temp dialog = PinAuthDialog('TraktPinAuthDialog.xml', kodi.get_path()) dialog.doModal() if dialog.auth: kodi.notify(msg=i18n('trakt_auth_complete'), duration=3000) del dialog
def get_pin(): AUTH_BUTTON = 200 LATER_BUTTON = 201 NEVER_BUTTON = 202 ACTION_PREVIOUS_MENU = 10 ACTION_BACK = 92 CENTER_Y = 6 CENTER_X = 2 class PinAuthDialog(xbmcgui.WindowXMLDialog): auth = False def onInit(self): self.pin_edit_control = self.__add_editcontrol(30, 240, 40, 450) self.setFocus(self.pin_edit_control) auth = self.getControl(AUTH_BUTTON) never = self.getControl(NEVER_BUTTON) self.pin_edit_control.controlUp(never) self.pin_edit_control.controlLeft(never) self.pin_edit_control.controlDown(auth) self.pin_edit_control.controlRight(auth) auth.controlUp(self.pin_edit_control) auth.controlLeft(self.pin_edit_control) never.controlDown(self.pin_edit_control) never.controlRight(self.pin_edit_control) def onAction(self, action): # print 'Action: %s' % (action.getId()) if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK: self.close() def onControl(self, control): # print 'onControl: %s' % (control) pass def onFocus(self, control): # print 'onFocus: %s' % (control) pass def onClick(self, control): # print 'onClick: %s' % (control) if control == AUTH_BUTTON: if not self.__get_token(): kodi.notify(msg=i18n('pin_auth_failed'), duration=5000) return self.auth = True if control == LATER_BUTTON: kodi.notify(msg=i18n('remind_in_24hrs'), duration=5000) kodi.set_setting('last_reminder', str(int(time.time()))) if control == NEVER_BUTTON: kodi.notify(msg=i18n('use_addon_settings'), duration=5000) kodi.set_setting('last_reminder', '-1') if control in [AUTH_BUTTON, LATER_BUTTON, NEVER_BUTTON]: self.close() def __get_token(self): pin = self.pin_edit_control.getText().strip() if pin: try: trakt_api = Trakt_API(use_https=use_https, timeout=trakt_timeout) result = trakt_api.get_token(pin=pin) kodi.set_setting('trakt_oauth_token', result['access_token']) kodi.set_setting('trakt_refresh_token', result['refresh_token']) profile = trakt_api.get_user_profile(cached=False) kodi.set_setting('trakt_user', '%s (%s)' % (profile['username'], profile['name'])) return True except Exception as e: log_utils.log('Trakt Authorization Failed: %s' % (e), log_utils.LOGDEBUG) return False return False # have to add edit controls programatically because getControl() (hard) crashes XBMC on them def __add_editcontrol(self, x, y, height, width): media_path = os.path.join(kodi.get_path(), 'resources', 'skins', 'Default', 'media') temp = xbmcgui.ControlEdit(0, 0, 0, 0, '', font='font12', textColor='0xFFFFFFFF', focusTexture=os.path.join(media_path, 'button-focus2.png'), noFocusTexture=os.path.join(media_path, 'button-nofocus.png'), _alignment=CENTER_Y | CENTER_X) temp.setPosition(x, y) temp.setHeight(height) temp.setWidth(width) self.addControl(temp) return temp dialog = PinAuthDialog('TraktPinAuthDialog.xml', kodi.get_path()) dialog.doModal() if dialog.auth: kodi.notify(msg=i18n('trakt_auth_complete'), duration=3000) del dialog
def do_ip_auth(scraper, visit_url, qr_code): EXPIRE_DURATION = 60 * 5 ACTION_PREVIOUS_MENU = 10 ACTION_BACK = 92 CANCEL_BUTTON = 200 INSTR_LABEL = 101 QR_CODE_CTRL = 102 PROGRESS_CTRL = 103 class IpAuthDialog(xbmcgui.WindowXMLDialog): def onInit(self): # logger.log('onInit:', log_utils.LOGDEBUG) self.cancel = False self.getControl(INSTR_LABEL).setLabel(i18n('ip_auth_line1') + visit_url + i18n('ip_auth_line2')) self.progress = self.getControl(PROGRESS_CTRL) self.progress.setPercent(100) if qr_code: img = self.getControl(QR_CODE_CTRL) img.setImage(qr_code) def onAction(self, action): # logger.log('Action: %s' % (action.getId()), log_utils.LOGDEBUG) if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK: self.cancel = True self.close() def onControl(self, control): # logger.log('onControl: %s' % (control), log_utils.LOGDEBUG) pass def onFocus(self, control): # logger.log('onFocus: %s' % (control), log_utils.LOGDEBUG) pass def onClick(self, control): # logger.log('onClick: %s' % (control), log_utils.LOGDEBUG) if control == CANCEL_BUTTON: self.cancel = True self.close() def setProgress(self, progress): self.progress.setPercent(progress) dialog = IpAuthDialog('IpAuthDialog.xml', kodi.get_path()) dialog.show() interval = 5000 begin = time.time() try: while True: for _ in range(INTERVALS): kodi.sleep(interval / INTERVALS) elapsed = time.time() - begin progress = int((EXPIRE_DURATION - elapsed) * 100 / EXPIRE_DURATION) dialog.setProgress(progress) if progress <= 0 or dialog.cancel: return False authorized, result = scraper.check_auth() if authorized: return result finally: del dialog
from sigsaur_lib import strings logger = log_utils.Logger.get_logger() THEME_LIST = [ 'Shine', 'Luna_Blue', 'Iconic', 'Simple', 'SALTy', 'SALTy (Blended)', 'SALTy (Blue)', 'SALTy (Frog)', 'SALTy (Green)', 'SALTy (Macaw)', 'SALTier (Green)', 'SALTier (Orange)', 'SALTier (Red)', 'IGDB', 'Simply Elegant', 'IGDB Redux', 'NaCl' ] THEME = THEME_LIST[int(kodi.get_setting('theme') or 0)] if kodi.has_addon('script.sigsaur.themepak'): themepak_path = xbmcaddon.Addon('script.sigsaur.themepak').getAddonInfo( 'path') else: themepak_path = kodi.get_path() THEME_PATH = os.path.join(themepak_path, 'art', 'themes', THEME) translations = kodi.Translations(strings.STRINGS) SORT_FIELDS = [(SORT_LIST[int(kodi.get_setting('sort1_field'))], SORT_SIGNS[kodi.get_setting('sort1_order')]), (SORT_LIST[int(kodi.get_setting('sort2_field'))], SORT_SIGNS[kodi.get_setting('sort2_order')]), (SORT_LIST[int(kodi.get_setting('sort3_field'))], SORT_SIGNS[kodi.get_setting('sort3_order')]), (SORT_LIST[int(kodi.get_setting('sort4_field'))], SORT_SIGNS[kodi.get_setting('sort4_order')]), (SORT_LIST[int(kodi.get_setting('sort5_field'))], SORT_SIGNS[kodi.get_setting('sort5_order')]), (SORT_LIST[int(kodi.get_setting('sort6_field'))], SORT_SIGNS[kodi.get_setting('sort6_order')])]
import urllib2 import os import ssl import socket import json import utils import log_utils import kodi import utils2 from db_utils import DB_Connection from constants import VIDEO_TYPES _db_connection = None _tmdb_scraper = None _tvdb_scraper = None PLACE_POSTER = os.path.join(kodi.get_path(), "resources", "place_poster.png") # delay db_connection until needed to force db errors during recovery try: block def _get_db_connection(): global _tmdb_scraper if _tmdb_scraper is None: _tmdb_scraper = DB_Connection() return _tmdb_scraper def _get_tmdb_scraper(): global _tvdb_scraper if _tvdb_scraper is None: _tvdb_scraper = TMDBScraper() return _tvdb_scraper