def action_csearch(self):
     self.succeeded = True
     self.end_of_directory()
     _id = self.args.get(SC.ITEM_ID)
     home_win.setProperty('SC.search', '{}'.format(_id))
     search = dinput('', '', xbmcgui.INPUT_TYPE_TEXT)
     home_win.clearProperty('SC.search')
     info('search string: {}'.format(search))
     if search == '':
         exec_build_in('Action(Back)')
         return
     query = {'search': search, SC.ITEM_ID: _id}
     if _id.startswith('search-people'):
         query.update({'ms': '1'})
     st = List(_id)
     st.add(search)
     debug('SEARCH: _ID "{}" search for "{}" people "{}"'.format(
         _id, search, 1 if 'ms' in query else 0))
     url = '/Search/{}?{}'.format(_id, urlencode(query))
     info('search url: {}'.format(url))
     self.url = url
     self.call_url()
     if 'msgERROR' in self.response.get('system', {}):
         self.msg_error()
         exec_build_in('Action(Back)')
         return
     plugin_url = create_plugin_url({'url': url})
     container_update(plugin_url)
     return
 def action_cmd(self):
     url = self.args.get('url')
     if url.startswith('cmd://'):
         cmd = url[6:]
         info('CMD: {}'.format(cmd))
         exec_build_in(cmd)
         self.send_end = True
 def run(self):
     path = get_setting('androidtv.path')
     cur = int(time())
     if path and self.last_run + 3600 < cur:
         self.last_run = time()
         items = self.list.get()
         for i in items:
             path_name = make_legal_filename('{}/{}/'.format(
                 path, i.get(SC.ITEM_ID)))
             debug('android: {} {}'.format(i, path_name))
             mkdir(path_name)
             files = xbmcvfs.listdir(path_name)
             debug('files {}'.format(files))
             for f in files:
                 if len(f):
                     debug('file: {}'.format(f))
                     xbmcvfs.delete(f[0])
             res = Sc.get(i.get('url'))
             menu = res.get('menu', {})
             if len(menu):
                 debug('Mame menu polozky')
                 for pos, s in enumerate(menu):
                     if pos < 30:
                         url = create_plugin_url({
                             SC.ITEM_ID:
                             '{}'.format(s.get('id', 0)),
                             SC.ITEM_URL:
                             s.get('url', '')
                         })
                         base_name = '{}{:04d}'.format(path_name, pos)
                         fn = make_legal_filename(
                             '{}.strm'.format(base_name))
                         # debug('{} -> {} {} {}'.format(pos, fn, url, s.get(SC.ITEM_UIDS)))
                         fs = xbmcvfs.File(fn, 'w')
                         fs.write('{}'.format(url))
                         fs.close()
                         nfo = SCNFO(s)
                         # debug('NFO: {}'.format(encode(nfo.xml())))
                         fs = xbmcvfs.File(
                             make_legal_filename(
                                 '{}.nfo'.format(base_name)), 'w')
                         fs.write('{}'.format(encode(nfo.xml())))
                         fs.close()
             playlist_base = make_legal_filename(
                 'special://profile/playlists/video/')
             xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>' \
                   '<smartplaylist type="movies">' \
                   ' <name>{}</name>' \
                   ' <match>all</match>' \
                   ' <rule field="path" operator="contains"><value>{}</value></rule>' \
                   '</smartplaylist>'
             xbmcvfs.mkdirs(playlist_base)
             filename = make_legal_filename('{}{}.xsp'.format(
                 playlist_base, i.get(SC.ITEM_ID)))
             fs = xbmcvfs.File(filename, 'w')
             fs.write(xml.format(i.get(SC.ITEM_ID), path_name))
             fs.close()
         self.cleanup_library_path(path)
         exec_build_in('UpdateLibrary(video,{})'.format(path))
    def system_after(self):
        data = self.response.get(SC.ITEM_SYSTEM, {})
        if 'setContent' in data:  # and settings.get_setting_bool('gui.views.enabled'):
            xbmcplugin.setContent(params.handle, data['setContent'])
            # view_mode = data["setContent"].lower()
            # view_code = settings.get_setting_int('gui.views.{0}'.format(view_mode))
            # if view_code > 0:
            #     xbmc.executebuiltin("Container.SetViewMode(%d)" % view_code)

        if 'SetSortMethod' in data:
            #method = SORT_METHODS[int(data.get('SetSortMethod'))]
            #xbmc.executebuiltin('Container.SetSortMethod(%d)' % method)
            pass

        if SC.ITEM_FOCUS in data:
            try:
                control = cur_win.getControl(cur_win.getFocusId())
                control.selectItem(int(data[SC.ITEM_FOCUS]))
            except:
                pass

        check_last_key = '{}.last_series'.format(ADDON_ID)
        if 'checkLast' in data and get_setting_as_bool(
                'stream.autoplay.episode'):
            check_last = data['checkLast']
            stop = home_win.getProperty('{}.stop'.format(ADDON_ID))
            debug('Mame check last data: {} / {}'.format(stop, check_last))
            item_id = int(check_last.get('id', 0))
            ki = SCKODIItem(int(item_id))
            last_ep = ki.get_last_ep()
            if item_id > 0 and last_ep:
                win_last_series = home_win.getProperty(check_last_key)
                home_win.setProperty(check_last_key, str(item_id))
                debug('last {} cur {}'.format(win_last_series, item_id))
                if win_last_series == '' or win_last_series != str(item_id):
                    debug('last ep: {}'.format(last_ep))
                    try:
                        data = Sc.up_next(item_id, last_ep[0], last_ep[1])
                        d = SCUpNext(data)
                        debug('NEXT EP: {}'.format(d.get().get('play_info')))
                        cmd = 'PlayMedia({})'.format(
                            create_plugin_url(d.get().get('play_info')))
                        if stop is None or stop == '':
                            debug('play: {}'.format(cmd))
                            exec_build_in(cmd)
                    except:
                        debug('chyba: {}'.format(traceback.format_exc()))
                        pass
        else:
            home_win.clearProperty(check_last_key)
        # upraceme po sebe
        home_win.clearProperty('{}.stop'.format(ADDON_ID))
 def onNotification(self, sender, method, data):
     debug('monitor onNotification {} {} {}'.format(decode(sender), decode(method), decode(data)))
     if method in self.callback:
         debug('callback for {}'.format(method))
         self.callback[method](data)
     # if sender == 'xbmc' and method == 'Player.OnAVStart':
         # debug('monitor Player.OnAVChange, set item to: {}'.format(loads(data).get('item')))
         # player.set_item(loads(data).get('item'))
     if sender == 'xbmc' and method == 'System.OnSleep':
         self.is_DPMS = True
     if sender == 'xbmc' and method == 'System.OnWake':
         self.is_DPMS = False
     if sender == 'upnextprovider.SIGNAL' and method == 'Other.{}_play_action'.format(ADDON_ID):
         from base64 import b64decode
         exec_build_in('PlayMedia({})'.format(create_plugin_url(loads(b64decode(data)))))
         pass
    def run(self):
        debug(
            'START SERVICE....................................................................'
        )
        last_changelog = get_setting('system.changelog')

        update_addon()

        if last_changelog != ADDON.getAddonInfo('version'):
            debug('SYSTEM.CHANGELOG: {}'.format(
                ADDON.getAddonInfo('changelog')))
            set_setting('system.changelog',
                        '{}'.format(ADDON.getAddonInfo('version')))
            dtextviewer('', ADDON.getAddonInfo('changelog'))

        if get_setting_as_bool('system.autoexec'):
            try:
                exec_build_in(
                    'ActivateWindow(videos,plugin://{})'.format(ADDON_ID))
            except:
                pass

        if get_setting('kraska.user'):
            kra = Kraska()
            kra.check_user()

        if get_setting_as_bool('system.ws.remote.enable'):
            ws = websocket.WS()
            ws.reconnect()

        self.next_ep = NextEp()

        clean_textures()
        from threading import Thread
        w = Thread(target=player.run)
        w.start()

        while not monitor.abortRequested():
            try:
                self.periodical_check()
            except:
                debug('error: {}'.format(traceback.format_exc()))
                pass
            sleep(1000 * 5)