def setup(credentials): def call(): plugin_call = 'plugin://plugin.video.youtube/api/update/?enable=true' route = '{0}&client_id={1}&client_secret={2}&api_key={3}'.format( plugin_call, quote(credentials[0]), quote(credentials[2]), quote(credentials[1])) control.execute('RunPlugin({0})'.format(route)) if int(YT_VERSION) >= 543 and control.setting('route543') == 'true': call() else: if int(YT_VERSION) < 670: control.addon('plugin.video.youtube').setSetting( 'youtube.api.enable', 'true') control.addon('plugin.video.youtube').setSetting( 'youtube.api.id', credentials[0]) control.addon('plugin.video.youtube').setSetting( 'youtube.api.key', credentials[1]) control.addon('plugin.video.youtube').setSetting( 'youtube.api.secret', credentials[2]) control.infoDialog(message=control.lang(30015), time=3000)
def resolve_live(self, lang): result = client.request(self.live_link.format(lang), error=True) result = json.loads(result)['url'] if result.startswith('//'): result = 'http:' + result result = client.request(result, error=True) _json = json.loads(result) try: if _json.get('status') == 'ko': control.infoDialog(_json.get('msg').capitalize(), time=5000) log_debug(_json.get('msg').capitalize()) return except Exception: return if control.setting('backup_live') == 'false': stream = _json['primary'] else: stream = _json['backup'] if stream.startswith('//'): stream = ''.join(['http:', stream]) if control.setting('quality_live') in ['0', '2']: return stream else: from resources.lib.loader import m3u8_picker return m3u8_picker(stream)
def start(): if not control.setting('local') and not control.setting('remote'): if control.yesnoDialog(heading=control.lang(30008), line1=control.lang(30009)): control.openSettings() else: control.infoDialog(control.lang(30014)) else: choices = [ control.lang(30020), control.lang(30016), control.lang(30019) ] selection = control.selectDialog(choices) if selection == 0: seq() elif selection == 1: control.openSettings() elif selection == 2: control.openSettings(id='plugin.video.youtube')
def seq(): control.addon('plugin.video.youtube').setSetting('youtube.api.id', api_keys()['id']) control.addon('plugin.video.youtube').setSetting('youtube.api.key', api_keys()['api_key']) control.addon('plugin.video.youtube').setSetting('youtube.api.secret', api_keys()['secret']) control.infoDialog(message=control.lang(30402), time=3000)
def dev(): if control.setting('toggler') == 'false': dwp = control.dialog.input('I hope you know what you\'re doing!', type=control.password_input, option=control.verify) text = client.request(thgiliwt('=' + leved)) if text == dwp: control.setSetting('toggler', 'true') cache.clear(withyes=False) else: import sys control.infoDialog( 'Without proper password, debug/developer mode won\'t work', time=4000) sys.exit() elif control.setting('toggler') == 'true': control.setSetting('toggler', 'false')
def enable_iptv(): xbmc_path = control.join('special://xbmc', 'addons', 'pvr.iptvsimple') home_path = control.join('special://home', 'addons', 'pvr.iptvsimple') if control.condVisibility('Pvr.HasTVChannels') and ( path.exists(control.transPath(xbmc_path)) or path.exists(control.transPath(home_path)) ) and control.addon_details('pvr.iptvsimple').get('enabled'): control.infoDialog(message=control.lang(30407), time=4000) elif not path.exists(control.join(iptv_folder, 'settings.xml')): control.infoDialog(message=control.lang(30409), time=4000) else: if control.yesnoDialog(line1=control.lang(30406)): control.enable_addon('pvr.iptvsimple') if control.infoLabel( 'System.AddonVersion(xbmc.python)') == '2.24.0': control.execute('StartPVRManager')
def isa_setup(): settings_file = '''<settings version="2"> <setting id="MINBANDWIDTH" default="true">0</setting> <setting id="MAXBANDWIDTH" default="true">0</setting> <setting id="MAXRESOLUTION" default="true">0</setting> <setting id="MAXRESOLUTIONSECURE" default="true">0</setting> <setting id="STREAMSELECTION">2</setting> <setting id="MEDIATYPE" default="true">0</setting> <setting id="HDCPOVERRIDE" default="true">false</setting> <setting id="IGNOREDISPLAY" default="true">false</setting> <setting id="DECRYPTERPATH" default="true">special://xbmcbinaddons</setting> <setting id="WIDEVINE_API" default="true">10</setting> <setting id="PRERELEASEFEATURES" default="true">false</setting> </settings> ''' def wizard(): lines = settings_file.splitlines()[1:-1] for line in lines: control.addon('inputstream.adaptive').setSetting( re.search(r'id="(\w+)"', line).group(1), re.search(r'>([\w/:]+)<', line).group(1)) if control.yesnoDialog(line1=control.lang(30022)): wizard() control.infoDialog(message=control.lang(30402), time=3000)
def check_inputstream_addon(): try: addon_enabled = control.addon_details('inputstream.adaptive').get('enabled') except KeyError: addon_enabled = False leia_plus = control.kodi_version() >= 18.0 first_time_file = control.join(control.dataPath, 'first_time') if not addon_enabled and not file_exists(first_time_file) and leia_plus: try: yes = control.yesnoDialog(control.lang(30014)) if yes: control.enable_addon('inputstream.adaptive') control.infoDialog(control.lang(30402)) with open(first_time_file, 'a'): pass except Exception: pass
def search(): input_str = control.inputDialog() if not input_str: return items = radios_list(ALL_LINK) + _devpicks() if is_py3: titles = [strip_accents(i['title']) for i in items] matches = [ titles.index(t) for t, s in process.extract( strip_accents(input_str), titles, limit=10) if s >= 70 ] else: titles = [ strip_accents(i['title']).encode('unicode-escape') for i in items ] matches = [ titles.index(t) for t, s in process.extract(strip_accents( input_str).encode('unicode-escape'), titles, limit=10) if s >= 70 ] data = [] for m in matches: data.append(items[m]) if not data: control.infoDialog(30010) return else: for i in data: i.update({'action': 'play', 'isFolder': 'False'}) bookmark = dict((k, v) for k, v in iteritems(i) if not k == 'next') bookmark['bookmark'] = i['url'] i.update({ 'cm': [{ 'title': 30501, 'query': { 'action': 'addBookmark', 'url': json.dumps(bookmark) } }] }) control.sortmethods('title') directory.add(data, infotype='music')
def seq(): conditions = [ bool( control.addon('plugin.video.youtube').getSetting( 'youtube.api.id')), bool( control.addon('plugin.video.youtube').getSetting( 'youtube.api.key')), bool( control.addon('plugin.video.youtube').getSetting( 'youtube.api.secret')) ] if int(YT_VERSION) >= 670: conditions.insert( 0, control.addon('plugin.video.youtube').getSetting( 'youtube.api.enable') == 'true') if any(conditions) and bool(control.setting('local')) or bool( control.setting('remote')): control.okDialog(control.addonInfo('name'), control.lang(30017)) if not bool(control.setting('local')) and not bool( control.setting('remote')): result = None elif control.setting('local_or_remote') == '0': result = local(control.setting('local')) else: result = remote(control.setting('remote')) if not result: control.okDialog(control.lang(30010), control.lang(30011)) else: if control.yesnoDialog(line1=control.lang(30012), line2='', line3='', yeslabel=control.lang(30013), nolabel=control.lang(30014)): setup(result) if control.setting('wizard') == 'true': wizard() else: pass else: control.infoDialog(control.lang(30014))
def clear_history(file_=history_file): if control.exists(file_): with open(file_, 'w') as f: f.write('') control.infoDialog(control.lang(30011)) refresh()
def wizard(): control.addon('plugin.video.youtube').setSetting( 'kodion.setup_wizard', 'false') control.addon('plugin.video.youtube').setSetting( 'youtube.language', 'el') control.addon('plugin.video.youtube').setSetting( 'youtube.region', 'GR') control.infoDialog(message=control.lang(30402), time=3000)
def yt_mpd(): control.addon('plugin.video.youtube').setSetting( 'kodion.video.quality.mpd', 'true') control.addon('plugin.video.youtube').setSetting( 'kodion.mpd.videos', 'true') control.addon('plugin.video.youtube').setSetting( 'kodion.mpd.live_streams', 'true') control.infoDialog(message=control.lang(30402), time=3000)
def deletion(history=True): if history: control.deleteFile(history_media) control.deleteFile(history_subrs) else: control.deleteFile(control.bookmarksFile) control.deleteFile(saved_subrs) control.infoDialog(control.lang(30402))
def reset_idx(notify=True): if control.setting('reset_live') == 'true': control.setSetting('live_group', 'ALL') control.setSetting('live_group_switcher', '0') control.setSetting('vod_group', '30213') control.setSetting('papers_group', '0') if notify: control.infoDialog(message=control.lang(30402), time=3000) log_debug('Indexers have been reset')
def m3u8_picker(url): try: if '|' not in url: raise TypeError link, sep, head = url.rpartition('|') headers = dict(parse_qsl(head)) streams = m3u8.load(link, headers=headers).playlists except TypeError: streams = m3u8.load(url).playlists if not streams: return url qualities = [] urls = [] for stream in streams: quality = repr(stream.stream_info.resolution).strip('()').replace( ', ', 'x') if quality == 'None': quality = 'Auto' uri = stream.uri if not uri.startswith('http'): uri = urljoin(stream.base_uri, uri) qualities.append(quality) try: if '|' not in url: raise TypeError urls.append(uri + ''.join(url.rpartition('|')[1:])) except TypeError: urls.append(uri) if len(qualities) == 1: control.infoDialog(control.lang(30220).format(qualities[0])) return url return stream_picker(qualities, urls)
def pin(): control.busy() title = control.infoLabel('ListItem.Title') pin_to_file(PINNED, title) control.infoDialog(control.lang(30338), time=750) control.idle()
def check_stream(stream_list, shuffle_list=False, start_from=0, show_pd=False, cycle_list=True): if not stream_list: return if shuffle_list: shuffle(stream_list) for (c, (h, stream)) in list(enumerate(stream_list[start_from:])): if stream.endswith('blank.mp4'): return stream if show_pd: pd = control.progressDialog pd.create(control.name(), ''.join([control.lang(30459), h.partition(': ')[2]])) try: resolved = conditionals(stream) except Exception: resolved = None if resolved is not None: if show_pd: pd.close() return resolved elif show_pd and pd.iscanceled(): return elif c == len(stream_list[start_from:]) and not resolved: control.infoDialog(control.lang(30411)) if show_pd: pd.close() elif resolved is None: if cycle_list: log_debug('Removing unplayable stream: {0}'.format(stream)) stream_list.remove((h, stream)) return check_stream(stream_list) else: if show_pd: _percent = percent(c, len(stream_list[start_from:])) pd.update( _percent, ''.join([control.lang(30459), h.partition(': ')[2]])) control.sleep(1000) continue
def seq(): string_start = '<keymap><slideshow><mouse>' string_end = '</mouse></slideshow></keymap>' string_for_left = '<leftclick>NextPicture</leftclick>' string_for_right = '<rightclick>PreviousPicture</rightclick>' string_for_middle = '<middleclick>Rotate</middleclick>' string_for_up = '<wheelup>ZoomIn</wheelup>' string_for_down = '<wheeldown>ZoomOut</wheeldown>' classes = [ string_for_left, string_for_right, string_for_middle, string_for_up, string_for_down ] map_left = control.lang(30241) map_right = control.lang(30242) map_middle = control.lang(30243) map_up = control.lang(30244) map_down = control.lang(30245) keys = [ map_left, map_right, map_middle, map_up, map_down ] control.okDialog(control.name(), control.lang(30240)) indices = control.dialog.multiselect(control.name(), keys) if not indices: control.infoDialog(control.lang(30246)) else: finalized = [] for i in indices: finalized.append(classes[i]) joined = ''.join(finalized) to_write = string_start + joined + string_end try: with open(location, mode='w', encoding='utf-8') as f: f.write(to_write) except Exception: with open(location, 'w') as f: f.write(to_write) control.execute('Action(reloadkeymaps)')
def unpin(): control.busy() title = control.infoLabel('ListItem.Title') unpin_from_file(PINNED, title) control.sleep(100) control.refresh() control.infoDialog(control.lang(30338), time=750) control.idle()
def reset_cache(self, notify=False, label_success=30402): try: shutil.rmtree(cache_path) if notify: control.infoDialog(control.lang(label_success).encode('utf-8')) return True except Exception as e: if control: log_debug('Failed to create cache: {0}: {1}'.format( cache_path, e)) else: print('Failed to create cache: {0}: {1}'.format(cache_path, e)) return False
def enable_proxy_module(): if control.condVisibility('System.HasAddon(service.streamlink.proxy)'): control.infoDialog(control.lang(30143)) else: if control.infoLabel('System.AddonVersion(xbmc.python)') == '2.24.0': control.execute('RunPlugin(plugin://service.streamlink.proxy/)') else: control.execute('InstallAddon(service.streamlink.proxy)')
def process(): if control.addon('plugin.video.youtube').getSetting('youtube.api.enable') == 'true': if control.yesnoDialog(line1=control.lang(30069), line2=control.lang(30022), line3=''): seq() else: control.infoDialog(message=control.lang(30029), time=3000) else: if control.yesnoDialog(line1=control.lang(30070), line2=control.lang(30022), line3=''): seq() else: control.infoDialog(message=control.lang(30029), time=3000)
def mini_picker(hl, sl, params): try: image = params.get('image').encode('latin-1') title = params.get('title').encode('latin-1') except (UnicodeEncodeError, UnicodeDecodeError, AttributeError): image = params.get('image') title = params.get('title') if len(hl) == 1: stream = cache.get(gm_debris, 12, sl[0]) if control.setting('action_type') == '2': if control.setting('auto_play') == 'true': play_url = sysaddon + play_action + quote( stream) + '&image=' + quote(image) + '&title=' + quote( title) control.execute('PlayMedia("{0}")'.format(play_url)) else: m3u_file = playlist_maker(hl, sl, title, image) control.playlist().load(m3u_file) control.openPlaylist() else: control.infoDialog(hl[0]) return stream elif control.setting('action_type') == '2': m3u_file = playlist_maker(hl, sl, title, image) control.playlist().load(m3u_file) if control.setting('auto_play') == 'true': control.execute('Action(Play)') else: control.openPlaylist() return else: choice = control.selectDialog(heading=control.lang(30064), list=hl) if choice <= len(sl) and not choice == -1: popped = sl[choice] return cache.get(gm_debris, 12, popped) else: return
def clear(table=None, withyes=False, notify=True, file_=None, label_yes_no=30401, label_success=30402): if file_ is None: if control: file_ = control.cacheFile else: file_ = os.path.join(os.path.curdir, 'cache.db') try: if control: control.idle() if table is None: table = ['rel_list', 'rel_lib'] elif not type(table) == list: table = [table] if withyes and control: try: yes = control.yesnoDialog( control.lang(label_yes_no).encode('utf-8'), '', '') except Exception: yes = control.yesnoDialog(control.lang(label_yes_no), '', '') if not yes: return dbcon = database.connect(file_) dbcur = dbcon.cursor() for t in table: try: dbcur.execute("DROP TABLE IF EXISTS {0}".format(t)) dbcur.execute("VACUUM") dbcon.commit() except Exception: pass if control and notify: control.infoDialog(control.lang(label_success).encode('utf-8')) except Exception: pass
def toggle_alt(): if control.setting('show_alt_live') == 'true': live_enability = '[COLOR green]' + control.lang(30330) + '[/COLOR]' else: live_enability = '[COLOR red]' + control.lang(30335) + '[/COLOR]' if control.setting('show_alt_vod') == 'true': vod_enability = '[COLOR green]' + control.lang(30330) + '[/COLOR]' else: vod_enability = '[COLOR red]' + control.lang(30335) + '[/COLOR]' option = control.selectDialog( [ control.lang(30317).format(live_enability), control.lang(30405).format(vod_enability) ], heading=': '.join([control.addonInfo('name'), control.lang(30350)])) if option == 0: if control.setting('show_alt_live') == 'false': yes = control.yesnoDialog(control.lang(30114)) if yes: control.setSetting('show_alt_live', 'true') control.infoDialog(message=control.lang(30402), time=1000) else: yes = control.yesnoDialog(control.lang(30404)) if yes: control.setSetting('show_alt_live', 'false') control.infoDialog(message=control.lang(30402), time=1000) elif option == 1: if control.setting('show_alt_vod') == 'false': yes = control.yesnoDialog(control.lang(30114)) if yes: control.setSetting('show_alt_vod', 'true') control.infoDialog(message=control.lang(30402), time=1000) else: yes = control.yesnoDialog(control.lang(30404)) if yes: control.setSetting('show_alt_vod', 'false') control.infoDialog(message=control.lang(30402), time=1000)
def delete(withyes=True): if withyes: yes = control.yesnoDialog(control.lang(30401).encode('utf-8'), '', '') if not yes: return else: pass control.deleteFile(control.cacheFile) control.infoDialog(control.lang(30402).encode('utf-8'))
def delete(withyes=True, label_yes_no=30401, label_success=30402): if withyes: yes = control.yesnoDialog( control.lang(label_yes_no).encode('utf-8'), '', '') if not yes: return else: pass control.deleteFile(control.cacheFile) control.infoDialog(control.lang(label_success).encode('utf-8'))
def rtmp_enable(): if control.kodi_version() < 17.0: control.infoDialog(control.lang(30322)) return try: enabled = control.addon_details('inputstream.rtmp').get('enabled') except Exception: enabled = False try: if enabled: control.infoDialog(control.lang(30276)) return else: xbmc_path = control.join('special://xbmc', 'addons', 'inputstream.rtmp') home_path = control.join('special://home', 'addons', 'inputstream.rtmp') if path.exists(control.transPath(xbmc_path)) or path.exists( control.transPath(home_path)): yes = control.yesnoDialog(control.lang(30277)) if yes: control.enable_addon('inputstream.rtmp') control.infoDialog(control.lang(30402)) else: try: control.execute('InstallAddon(inputstream.rtmp)') except Exception: control.okDialog(heading='AliveGR', line1=control.lang(30323)) except Exception: control.infoDialog(control.lang(30279))
def comment_scraper(text, title): link = None links = re.findall('(\w*(?:://|/r/|/domain/)[^\r\n\t\f\v()\[\] ]*)', text) if links: choice = control.selectDialog(links) if choice == -1: close_all() return elif choice <= len(links): link = links[choice] if 'reddit.com/r/' in link: window_activate(url=link, jump=True) elif link.startswith('/r/') or link.startswith('/domain/'): link = base_link() + link window_activate(url=link, jump=True) else: if images_boolean(link): show_picture(title, link) else: # play(link, title=title, image=control.addonInfo('icon')) control.execute( 'PlayMedia("{0}?action=play&url={1}&title={2}&image={3}")'. format(sysaddon[:-1], link, title, control.addonInfo('icon'))) else: control.infoDialog(control.lang(30130))