def _select_profile(): profiles = api.profiles() options = [] values = [] default = -1 for index, profile in enumerate(profiles): values.append(profile) options.append( plugin.Item(label=profile['name'], art={'thumb': _get_avatar(profile['avatar_id'])})) if profile['id'] == userdata.get('profile_id'): default = index _set_profile(profile, notify=False) index = gui.select(_.SELECT_PROFILE, options=options, preselect=default, useDetails=True) if index < 0: return _set_profile(values[index])
def select_quality(qualities): options = [] options.append([QUALITY_BEST, _.QUALITY_BEST]) options.extend(qualities) options.append([QUALITY_LOWEST, _.QUALITY_LOWEST]) values = [x[0] for x in options] labels = [x[1] for x in options] current = userdata.get('last_quality') default = -1 if current: try: default = values.index(current) except: default = values.index(qualities[-1][0]) for quality in qualities: if quality[0] <= current: default = values.index(quality[0]) break index = gui.select(_.PLAYBACK_QUALITY, labels, preselect=default, autoclose=10000) #autoclose after 10seconds if index < 0: raise FailedPlayback('User cancelled quality select') userdata.set('last_quality', values[index]) return values[index]
def _select_profile(): profiles = api.user()['accountProfiles'] values = [] options = [] default = -1 for index, profile in enumerate(profiles): values.append(profile['id']) options.append( plugin.Item(label=profile['name'], art={'thumb': config.image(profile['profilePicPath'])})) if profile['id'] == userdata.get('profile_id'): default = index index = gui.select(_.SELECT_PROFILE, options=options, preselect=default, useDetails=True) if index < 0: return api.set_profile(values[index]) gui.notification(_.PROFILE_ACTIVATED, heading=userdata.get('profile_name'), icon=config.image(userdata.get('profile_img')))
def configure_merge(**kwargs): data = _app_data() data['regions'].pop(ALL, None) user_regions = userdata.get('merge_regions', []) avail_regions = sorted( data['regions'], key=lambda x: (data['regions'][x]['sort'], data['regions'][x]['name'])) options = [] preselect = [] for index, code in enumerate(avail_regions): region = data['regions'][code] options.append( plugin.Item(label=region['name'], art={'thumb': region['logo']})) if code in user_regions: preselect.append(index) indexes = gui.select(heading=_.SELECT_REGIONS, options=options, multi=True, useDetails=True, preselect=preselect) if indexes is None: return user_regions = [avail_regions[i] for i in indexes] userdata.set('merge_regions', user_regions)
def _select_profile(): account = api.account() profiles = account['profiles'] options = [] values = [] default = -1 for index, profile in enumerate(profiles): values.append(profile) options.append( plugin.Item(label=profile['name'], art={'thumb': profile['avatar']['uri']})) if profile['id'] == userdata.get('profile_id'): default = index index = gui.select(_.SELECT_PROFILE, options=options, preselect=default, useDetails=True) if index < 0: return _set_profile(values[index])
def _select_profile(): profiles = api.profiles() active = api.active_profile() avatars = _avatars([x['attributes']['avatar']['id'] for x in profiles]) options = [] values = [] default = -1 for index, profile in enumerate(profiles): values.append(profile) profile['_avatar'] = avatars.get(profile['attributes']['avatar']['id']) if profile['attributes']['parentalControls']['isPinProtected']: label = _(_.PROFILE_WITH_PIN, name=profile['profileName']) else: label = profile['profileName'] options.append( plugin.Item(label=label, art={'thumb': profile['_avatar']})) if profile['profileId'] == active.get('profileId'): default = index userdata.set('avatar', profile['_avatar']) userdata.set('profile', profile['profileName']) userdata.set('profile_id', profile['profileId']) index = gui.select(_.SELECT_PROFILE, options=options, preselect=default, useDetails=True) if index < 0: return _set_profile(values[index])
def _play_videos(videos): if not videos: plugin.exception('No videos found') default_audio = settings.getEnum('audio_lang', AUDIO_LANGS) if len(videos) == 1: chosen = videos[0] else: videos = sorted(videos, key=lambda x: x['language']) chosen = None for video in videos: if video['language']['iso_639_3'].lower() == default_audio: chosen = video break if not chosen: index = gui.select(_.SELECT_LANG, [x['language']['name'] for x in videos]) if index < 0: return chosen = videos[index] url, license_url = api.play(chosen['id']) item = plugin.Item( inputstream=inputstream.Widevine(license_url), path=url, headers=HEADERS, use_proxy= True, # Needed for https://github.com/xbmc/inputstream.adaptive/pull/606 ) return item
def configure_merge(**kwargs): user_providers = [x.lower() for x in userdata.get('merge_providers', [])] avail_providers = _providers(playlist=True) options = [] values = [] preselect = [] for index, key in enumerate( sorted(avail_providers, key=lambda x: (avail_providers[x]['sort'], avail_providers[x]['name']))): provider = avail_providers[key] values.append(key) options.append( plugin.Item(label=provider['name'], art={'thumb': provider['logo']})) if key in user_providers: preselect.append(index) indexes = gui.select(heading=_.SELECT_PROVIDERS, options=options, useDetails=True, multi=True, preselect=preselect) if indexes is None: return user_providers = [values[i] for i in indexes] userdata.set('merge_providers', user_providers)
def _add_profile(taken_names, taken_avatars): ## PROFILE AVATAR ## options = [ plugin.Item(label=_(_.RANDOM_AVATAR, _bold=True)), ] values = [ ['_random', None], ] avatars = [] unused = [] for icon_set in api.profile_icons(): for row in icon_set['icons']: icon_info = [icon_set['iconSet'], row['iconIndex']] values.append(icon_info) avatars.append(icon_info) if row['iconImage'] in taken_avatars: label = _(_.AVATAR_USED, label=icon_set['label']) else: label = icon_set['label'] unused.append(icon_info) options.append( plugin.Item(label=label, art={'thumb': row['iconImage']})) index = gui.select(_.SELECT_AVATAR, options=options, useDetails=True) if index < 0: return avatar = values[index] if avatar[0] == '_random': avatar = random.choice(unused or avatars) ## PROFLE KIDS ## kids = gui.yes_no(_.KIDS_PROFILE_INFO, heading=_.KIDS_PROFILE) ## PROFILE NAME ## name = '' while True: name = gui.input(_.PROFILE_NAME, default=name).strip() if not name: return elif name.lower() in taken_names: gui.notification(_(_.PROFILE_NAME_TAKEN, name=name)) else: break ## ADD PROFILE ## profile = api.add_profile(name, icon_set=avatar[0], icon_index=avatar[1], kids=kids) if 'message' in profile: raise PluginError(profile['message']) _set_profile(profile)
def login(self, username, password, kickdevice=None): self.logout() raw_id = self._format_id(settings.get('device_id')).lower() device_id = hashlib.sha1(raw_id.encode('utf8')).hexdigest() log.debug('Raw device id: {}'.format(raw_id)) log.debug('Hashed device id: {}'.format(device_id)) hex_password = self._hex_password(password, device_id) params = { 'appID': APP_ID, 'format': 'json', } payload = { 'username': username, 'password': hex_password, 'deviceId': device_id, 'accountType': 'foxtel', } if kickdevice: payload['deviceToKick'] = kickdevice log.debug('Kicking device: {}'.format(kickdevice)) data = self._session.post( '/auth.class.api.php/logon/{site_id}'.format(site_id=VOD_SITEID), data=payload, params=params).json() response = data['LogonResponse'] devices = response.get('CurrentDevices', []) error = response.get('Error') success = response.get('Success') if error: if not devices or kickdevice: raise APIError(_(_.LOGIN_ERROR, msg=error.get('Message'))) options = [d['Nickname'] for d in devices] index = gui.select(_.DEREGISTER_CHOOSE, options) if index < 0: raise APIError(_(_.LOGIN_ERROR, msg=error.get('Message'))) kickdevice = devices[index]['DeviceID'] return self.login(username, password, kickdevice=kickdevice) userdata.set('token', success['LoginToken']) userdata.set('deviceid', success['DeviceId']) userdata.set('entitlements', success.get('Entitlements', '')) if settings.getBool('save_password', False): userdata.set('pswd', password) log.debug('Password Saved') self.logged_in = True
def _add_profile(taken_names, taken_avatars): ## PROFILE AVATAR ## options = [plugin.Item(label=_(_.RANDOM_AVATAR, _bold=True)),] values = ['_random',] avatars = {} unused = [] data = api.collection_by_slug('avatars', 'avatars') for container in data['containers']: if container['set']['contentClass'] == 'hidden': continue category = _get_text(container['set']['texts'], 'title', 'set') for row in container['set'].get('items', []): if row['images'][0]['url'] in taken_avatars: label = _(_.AVATAR_USED, label=category) else: label = category unused.append(row['avatarId']) options.append(plugin.Item(label=label, art={'thumb': row['images'][0]['url']})) values.append(row['avatarId']) avatars[row['avatarId']] = row['images'][0]['url'] index = gui.select(_.SELECT_AVATAR, options=options, useDetails=True) if index < 0: return avatar = values[index] if avatar == '_random': avatar = random.choice(unused or avatars.keys()) ## PROFLE KIDS ## kids = gui.yes_no(_.KIDS_PROFILE_INFO, heading=_.KIDS_PROFILE) ## PROFILE NAME ## name = '' while True: name = gui.input(_.PROFILE_NAME, default=name).strip() if not name: return elif name in taken_names: gui.notification(_(_.PROFILE_NAME_TAKEN, name=name)) else: break profile = api.add_profile(name, kids=kids, avatar=avatar) profile['_avatar'] = avatars[avatar] if 'errors' in profile: raise PluginError(profile['errors'][0].get('description')) _set_profile(profile)
def _delete_profile(profiles): options = [] for index, profile in enumerate(profiles): options.append(plugin.Item(label=profile['name'], art={'thumb': profile['iconImage']['url']})) index = gui.select(_.SELECT_DELETE_PROFILE, options=options, useDetails=True) if index < 0: return selected = profiles[index] if gui.yes_no(_.DELETE_PROFILE_INFO, heading=_(_.DELTE_PROFILE_HEADER, name=selected['name'])) and api.delete_profile(selected['id']): gui.notification(_.PROFILE_DELETED, heading=selected['name'], icon=selected['iconImage']['url'])
def select_pin(self): options = [_(_.PIN_LABEL, pin=x) for x in BCM_PINS] index = gui.select(_.BTN_PIN, options) if index < 0: return False self.pin = BCM_PINS[index] if self.enabled: self.enabled = False self.toggle_enabled() return True
def _add_profile(taken_names, taken_avatars): ## PROFILE AVATAR ## options = [ plugin.Item(label=_(_.RANDOM_AVATAR, _bold=True)), ] values = [ '_random', ] avatars = [] unused = [] for avatar in api.profile_config()['avatars']: values.append(avatar['id']) avatars.append(avatar['id']) if avatar['id'] in taken_avatars: label = _(_.AVATAR_USED, _bold=True) else: label = _.AVATAR_NOT_USED unused.append(avatar['id']) options.append( plugin.Item(label=label, art={'thumb': _get_avatar(avatar['id'])})) index = gui.select(_.SELECT_AVATAR, options=options, useDetails=True) if index < 0: return avatar_id = values[index] if avatar_id == '_random': avatar_id = random.choice(unused or avatars) ## PROFILE NAME ## name = '' while True: name = gui.input(_.PROFILE_NAME, default=name).strip() if not name: return elif name.lower() in taken_names: gui.notification(_(_.PROFILE_NAME_TAKEN, name=name)) else: break ## ADD PROFILE ## profile = api.add_profile(name, avatar_id) if 'message' in profile: raise PluginError(profile['message']) _set_profile(profile)
def _select_profile(): profiles = api.profiles() active = api.active_profile() avatars = _avatars([x['attributes']['avatar']['id'] for x in profiles]) options = [] values = [] can_delete = [] default = -1 for index, profile in enumerate(profiles): values.append(profile) profile['_avatar'] = avatars.get(profile['attributes']['avatar']['id']) if profile['attributes']['parentalControls']['isPinProtected']: label = _(_.PROFILE_WITH_PIN, name=profile['profileName']) else: label = profile['profileName'] options.append(plugin.Item(label=label, art={'thumb': profile['_avatar']})) if profile['profileId'] == active.get('profileId'): default = index userdata.set('avatar', profile['_avatar']) userdata.set('profile', profile['profileName']) userdata.set('profile_id', profile['profileId']) elif not profile['attributes']['isDefault']: can_delete.append(profile) options.append(plugin.Item(label=_(_.ADD_PROFILE, _bold=True))) values.append('_add') if can_delete: options.append(plugin.Item(label=_(_.DELETE_PROFILE, _bold=True))) values.append('_delete') index = gui.select(_.SELECT_PROFILE, options=options, preselect=default, useDetails=True) if index < 0: return selected = values[index] if selected == '_delete': _delete_profile(can_delete) elif selected == '_add': _add_profile(taken_names=[x['profileName'] for x in profiles], taken_avatars=[avatars[x] for x in avatars]) else: _set_profile(selected)
def _select_profile(): profiles = api.profiles() options = [] values = [] can_delete = [] default = -1 avatars = {} for avatar in api.profile_avatars(): avatars[avatar['id']] = avatar['url'] for index, profile in enumerate(profiles): profile['avatar'] = avatars.get(profile['avatar_id']) values.append(profile) options.append( plugin.Item(label=profile['name'], art={'thumb': profile['avatar']})) if profile['id'] == userdata.get('profile_id'): default = index _set_profile(profile, notify=False) elif not profile['root_flag']: can_delete.append(profile) options.append(plugin.Item(label=_(_.ADD_PROFILE, _bold=True))) values.append('_add') if can_delete: options.append(plugin.Item(label=_(_.DELETE_PROFILE, _bold=True))) values.append('_delete') index = gui.select(_.SELECT_PROFILE, options=options, preselect=default, useDetails=True) if index < 0: return selected = values[index] if selected == '_delete': _delete_profile(can_delete) elif selected == '_add': _add_profile(taken_names=[x['name'].lower() for x in profiles], avatars=avatars, taken_avatars=[x['avatar_id'] for x in profiles]) else: _set_profile(selected)
def select_archive_type(self): values = [self.ARCHIVE_NONE, self.ARCHIVE_GZIP, self.ARCHIVE_XZ] labels = [_.NOT_ARCHIVED, _.GZIP, _.XZ] try: default = values.index(self.archive_type) except: default = 0 index = gui.select(_.SELECT_ARCHIVE_TYPE, labels, preselect=default) if index < 0: return False self.archive_type = values[index] return True
def select_source(match_id, sources, **kwargs): match_id = int(match_id) sources = json.loads(sources) options = [x['priority'] for x in sources] labels = [x['title'] for x in sources] index = gui.select(_.PLAYBACK_SOURCE, options=labels) if index < 0: return priority = int(options[index]) url = api.play_live(match_id, priority) return _play(url)
def _add_profile(taken_names, taken_avatars): ## PROFILE AVATAR ## options = [ plugin.Item(label=_(_.RANDOM_AVATAR, _bold=True)), ] values = [ '_random', ] unused = [] for key in AVATARS: label = '' if key in taken_avatars: label = _(_.AVATAR_USED, label=label) else: unused.append(key) options.append(plugin.Item(label=label, art={'thumb': AVATARS[key]})) values.append(key) index = gui.select(_.SELECT_AVATAR, options=options, useDetails=True) if index < 0: return avatar = values[index] if avatar == '_random': avatar = random.choice(unused or AVATARS.keys()) ## PROFLE KIDS ## kids = gui.yes_no(_.KIDS_PROFILE_INFO, heading=_.KIDS_PROFILE) ## PROFILE NAME ## name = '' while True: name = gui.input(_.PROFILE_NAME, default=name).strip() if not name: return elif name in taken_names: gui.notification(_(_.PROFILE_NAME_TAKEN, name=name)) else: break profile = api.add_profile(name, kids, avatar) _set_profile(profile)
def _select_profile(): profiles = api.profiles() options = [] values = [] can_delete = [] default = -1 for index, profile in enumerate(profiles): values.append(profile) options.append( plugin.Item(label=profile['name'], art={'thumb': _avatar(profile['avatarId'])})) if profile['isMe']: default = index _set_profile(profile, switching=False) elif not profile['isPrimary']: can_delete.append(profile) # options.append(plugin.Item(label=_(_.ADD_PROFILE, _bold=True))) # values.append('_add') # if can_delete: # options.append(plugin.Item(label=_(_.DELETE_PROFILE, _bold=True))) # values.append('_delete') index = gui.select(_.SELECT_PROFILE, options=options, preselect=default, useDetails=True) if index < 0: return selected = values[index] if selected == '_delete': _delete_profile(can_delete) elif selected == '_add': _add_profile( taken_names=[x['name'] for x in profiles], taken_avatars=[x['avatarId'] or DEFAULT_AVATAR for x in profiles]) else: _set_profile(selected)
def _select_profile(): account = api.account() profiles = account['profiles'] options = [] values = [] can_delete = [] default = -1 for index, profile in enumerate(profiles): values.append(profile) options.append( plugin.Item(label=profile['name'], art={'thumb': profile['avatar']['uri']})) if profile['id'] == userdata.get('profile_id'): default = index elif not profile['isDefault']: can_delete.append(profile) # options.append(plugin.Item(label=_(_.ADD_PROFILE, _bold=True))) # values.append('_add') # if can_delete: # options.append(plugin.Item(label=_(_.DELETE_PROFILE, _bold=True))) # values.append('_delete') index = gui.select(_.SELECT_PROFILE, options=options, preselect=default, useDetails=True) if index < 0: return selected = values[index] # if selected == '_delete': # _delete_profile(can_delete) # elif selected == '_add': # _add_profile(taken_names=[x['name'].lower() for x in profiles], taken_avatars=[x['iconImage']['url'] for x in profiles]) # else: _set_profile(selected)
def _select_profile(): options = [] values = [] default = -1 for index, profile in enumerate(api.profiles()): values.append(profile) options.append(plugin.Item(label=profile['alias'], art={'thumb': profile['avatar']['uri']})) if profile['id'] == userdata.get('profile'): default = index userdata.set('avatar', profile['avatar']['uri']) userdata.set('profile', profile['alias']) index = gui.select(_.SELECT_PROFILE, options=options, preselect=default, useDetails=True) if index < 0: return _set_profile(values[index])
def _select_profile(): profiles = api.profiles() options = [] values = [] default = -1 for index, profile in enumerate(profiles): values.append(profile) options.append(plugin.Item(label=profile['name'], art={'thumb': _avatar(profile)})) if profile['isMe']: default = index _set_profile(profile, switching=False) index = gui.select(_.SELECT_PROFILE, options=options, preselect=default, useDetails=True) if index < 0: return _set_profile(values[index])
def _select_profile(): options = [] values = [] can_delete = [] default = -1 for index, profile in enumerate(api.profiles()): values.append(profile) options.append( plugin.Item(label=profile['alias'], art={'thumb': profile['avatar']['uri']})) if profile['id'] == userdata.get('profile'): default = index userdata.set('avatar', profile['avatar']['uri']) userdata.set('profile', profile['alias']) elif profile['id'] and profile['canDelete']: can_delete.append(profile) index = gui.select(_.SELECT_PROFILE, options=options, preselect=default, useDetails=True) if index < 0: return selected = values[index] if selected == '_delete': pass # _delete_profile(can_delete) elif selected == '_add': pass # _add_profile(taken_names=[x['profileName'] for x in profiles], taken_avatars=[avatars[x] for x in avatars]) else: _set_profile(selected)
def _quality_select(self, qualities): def codec_rank(_codecs): highest = -1 for codec in _codecs: for _codec in CODECS: if codec.lower().startswith( _codec[0].lower()) and _codec[1] in CODEC_RANKING: rank = CODEC_RANKING.index(_codec[1]) if not highest or rank > highest: highest = rank return highest def compare(a, b): if a['resolution'] and b['resolution']: if int(a['resolution'].split('x')[0]) > int( b['resolution'].split('x')[0]): return 1 elif int(a['resolution'].split('x')[0]) < int( b['resolution'].split('x')[0]): return -1 # Same resolution - compare codecs a_rank = codec_rank(a['codecs']) b_rank = codec_rank(b['codecs']) if a_rank > b_rank: return 1 elif a_rank < b_rank: return -1 # Same codec rank - compare bandwidth if a['bandwidth'] and b['bandwidth']: if a['bandwidth'] > b['bandwidth']: return 1 elif a['bandwidth'] < b['bandwidth']: return -1 # Same bandwidth - they are equal (could compare framerate) return 0 def _stream_label(stream): try: fps = _(_.QUALITY_FPS, fps=float(stream['frame_rate'])) except: fps = '' codec_string = '' for codec in stream['codecs']: for _codec in CODECS: if codec.lower().startswith(_codec[0].lower()): codec_string += ' ' + _codec[1] return _(_.QUALITY_BITRATE, bandwidth=int((stream['bandwidth'] / 10000.0)) / 100.00, resolution=stream['resolution'], fps=fps, codecs=codec_string.strip()).replace(' ', ' ') if self._session.get('selected_quality') is not None: if self._session['selected_quality'] in (QUALITY_DISABLED, QUALITY_SKIP): return None else: return qualities[self._session['selected_quality']] quality_compare = cmp_to_key(compare) quality = int(self._session.get('quality', QUALITY_ASK)) streams = sorted(qualities, key=quality_compare, reverse=True) if not streams: quality = QUALITY_DISABLED elif len(streams) < 2: quality = QUALITY_BEST if quality == QUALITY_ASK: options = [] options.append([QUALITY_BEST, _.QUALITY_BEST]) for x in streams: options.append([x, _stream_label(x)]) options.append([QUALITY_LOWEST, _.QUALITY_LOWEST]) options.append([QUALITY_SKIP, _.QUALITY_SKIP]) values = [x[0] for x in options] labels = [x[1] for x in options] default = 0 remove = None for quality in PROXY_GLOBAL['last_qualities']: if quality[0] == self._session['slug']: remove = quality default = quality[1] break index = gui.select(_.PLAYBACK_QUALITY, labels, preselect=default, autoclose=5000) if index < 0: raise Exit('Cancelled quality select') quality = values[index] if remove: PROXY_GLOBAL['last_qualities'].remove(remove) if index != default: PROXY_GLOBAL['last_qualities'].insert( 0, [self._session['slug'], index]) PROXY_GLOBAL['last_qualities'] = PROXY_GLOBAL[ 'last_qualities'][:MAX_QUALITY_HISTORY] if quality in (QUALITY_DISABLED, QUALITY_SKIP): quality = quality elif quality == QUALITY_BEST: quality = streams[0] elif quality == QUALITY_LOWEST: quality = streams[-1] elif quality not in streams: options = [streams[-1]] for stream in streams: if quality >= stream['bandwidth']: options.append(stream) quality = sorted(options, key=quality_compare, reverse=True)[0] if quality in qualities: self._session['selected_quality'] = qualities.index(quality) return qualities[self._session['selected_quality']] else: self._session['selected_quality'] = quality return None
def select_path(self, creating=False): try: default = self.TYPES.index(self.source_type) except: default = -1 index = gui.select(_.SELECT_SOURCE_TYPE, [self.TYPE_LABELS[x] for x in self.TYPES], preselect=default) if index < 0: return False orig_source_type = self.source_type self.source_type = self.TYPES[index] if self.source_type == self.TYPE_ADDON: addons = self.get_addon_sources() if not addons: raise Error(_.NO_SOURCE_ADDONS) options = [] default = -1 addons.sort(key=lambda x: x[0].getAddonInfo('name').lower()) for idx, row in enumerate(addons): options.append( plugin.Item(label=row[0].getAddonInfo('name'), art={'thumb': row[0].getAddonInfo('icon')})) if orig_source_type == self.TYPE_ADDON and row[0].getAddonInfo( 'id') == self.path: default = idx index = gui.select(_.SELECT_SOURCE_ADDON, options, preselect=default, useDetails=True) if index < 0: return False addon, data = addons[index] self.path = addon.getAddonInfo('id') elif self.source_type == self.TYPE_URL: self.path = gui.input(_.ENTER_SOURCE_URL, default=self.path if orig_source_type == self.TYPE_URL else '').strip() elif self.source_type == self.TYPE_FILE: self.path = xbmcgui.Dialog().browseSingle( 1, _.SELECT_SOURCE_FILE, '', '', defaultt=self.path if orig_source_type == self.TYPE_FILE else '') elif self.source_type == self.TYPE_CUSTOM: self.path = gui.input('Custom Name', default=self.path if orig_source_type == self.TYPE_CUSTOM else '').strip() if not self.path: return False self.save() if self.source_type == self.TYPE_ADDON: if creating: if self.__class__ == Playlist and METHOD_EPG in data: epg = EPG(source_type=EPG.TYPE_ADDON, path=self.path) try: epg.save() except: pass elif self.__class__ == EPG and METHOD_PLAYLIST in data: playlist = Playlist(source_type=Playlist.TYPE_ADDON, path=self.path) try: playlist.save() except: pass for key in data.get('settings', {}): value = data['settings'][key].replace('$ID', self.path) log.debug('Set setting {}={} for addon {}'.format( key, value, self.path)) addon.setSetting(key, value) if 'configure' in data: path = data['configure'].replace('$ID', self.path) run_plugin(path, wait=True) return True
def _select_device(self, token): data = self._session.post('proxy/casAvailableDevice', headers={'X-AN-WebService-CustomerAuthToken': token}).json() devices = data['result'].get('device', []) while True: if devices: options = [] values = [] for row in devices: options.append(_(_.DEVICE_LABEL, name=row['name'], last_login=arrow.get(row['lastLoginDate']).to('local').format('D MMMM YYYY'))) values.append(row) options.append(_.NEW_DEVICE) values.append('new') options.append(_.REMOVE_DEVICE) values.append('remove') index = gui.select(_.SELECT_DEVICE, options=options) if index == -1: return selected = values[index] else: selected = 'new' if selected == 'new': device_name = gui.input(_.DEVICE_NAME).strip() if not device_name or not gui.yes_no(_(_.NEW_CONFIRM, device_name=device_name)): if devices: continue else: return return { 'uniqueDeviceId': hash_6('{}{}'.format(int(time.time()), device_name), length=16), 'name': device_name, 'type': 'Android', } elif selected == 'remove': options = [] values = [] for row in devices: options.append(row['name']) values.append(row) to_remove = None while not to_remove: index = gui.select(_.SELECT_REMOVE_DEVICE, options=options) if index == -1: break if gui.yes_no(_(_.REMOVE_CONFIRM, device_name=values[index]['name'])): to_remove = values[index] if not to_remove: continue data = { 'casDeviceId': to_remove['uniqueDeviceId'], } data = self._session.post('proxy/casRemoveDevice', data=data, headers={'X-AN-WebService-CustomerAuthToken': token}).json() if data['error']: gui.error(data['error']['message']) continue return self._select_device(data['result']['newAuthToken']) else: return selected