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
Exemple #2
0
 def search(self):
     input = self.args.get('name', [''])[0]
     cont = get_info_label('Container.PluginName')
     debug('autocomplet input: {} / {}'.format(cont, input))
     if input == '':
         xbmcplugin.endOfDirectory(args.handle)
         return
     filter = self.args.get('f', [])[0]
     data = Sc.post('/FSug', data={'q': input, 'f': filter})
     debug('data: {}'.format(data))
     items = []
     for (count, result) in enumerate(data):
         debug('{} / {}'.format(count, result))
         listitem = xbmcgui.ListItem(result)
         param = {
             SC.ITEM_ACTION: 'autocomplet',
             SC.ITEM_ID: 'type',
             SC.ITEM_TITLE: result
         }
         url = create_plugin_url(param)
         listitem.setPath(url)
         listitem.setProperty('path', url)
         listitem.setProperty("index", str(count))
         listitem.setProperty("isPlayable", "false")
         items.append(listitem)
     xbmcplugin.addDirectoryItems(handle=args.handle,
                                  items=[(i.getProperty("path"), i, False)
                                         for i in items],
                                  totalItems=len(items))
     xbmcplugin.endOfDirectory(args.handle)
    def __init__(self, data, debug=False):
        self.item = list_item()
        self.data = data
        self.info_set = False
        self.info = {}
        self.debug = debug

        if SC.ITEM_TITLE in data:
            self.item.setLabel(data.get(SC.ITEM_TITLE))

        if SC.ITEM_URL in data:
            url = create_plugin_url(data)
            self.item.setPath(url)

        if SC.ITEM_ART in data:
            self.set_art()
        elif SC.ITEM_I18N_ART in data:
            self.set_i18n_art()

        if SC.ITEM_INFO in data:
            self.set_info()
        elif SC.ITEM_I18N_INFO in data:
            self._set_info(self.i18n_info({}))

        if 'cast' in data:
            self.set_cast()

        if 'unique_ids' in data:
            self.set_unique_ids()

        if 'stream_info' in data:
            self.set_stream_info()
 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 make_ctx(self):
        context_menu = [('Remove custom item', 'RunPlugin({})'.format(
            create_plugin_url({
                SC.ITEM_ACTION: SC.ACTION_DEL_CUSTOM_FILTER,
                SC.ITEM_URL: self.data.get(SC.ITEM_URL),
                SC.ITEM_TITLE: self.item.getLabel(),
                SC.ITEM_PAGE: self.data.get('self_url')
            })))]

        self.item.addContextMenuItems(context_menu)
    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 make_ctx(self):
        context_menu = [(Strings.txt(Strings.CONTEXT_REMOVE),
                         'RunPlugin({})'.format(
                             create_plugin_url({
                                 SC.ITEM_ACTION:
                                 SC.ACTION_DEL2HP,
                                 SC.ITEM_URL:
                                 self.data.get(SC.ITEM_URL),
                                 SC.ITEM_ID:
                                 self.item.getLabel()
                             })))]

        self.item.addContextMenuItems(context_menu)
    def __init__(self, data):
        SCBaseItem.__init__(self, data)
        self.lib = List(SC.ITEM_LIBRARY)
        item_id = self.data.get(SC.ITEM_ID)
        if item_id and item_id in self.lib.get():
            label = "[COLOR red]*[/COLOR] {0}".format(self.item.getLabel())
            self.item.setLabel(label)

        if SC.ITEM_URL in data:
            url = create_plugin_url(data)
            self.item.setPath(url)
        if self.build_ctx:
            self.make_ctx()
 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 __init__(self, data):
     SCBaseItem.__init__(self, data)
     self.item.setPath(create_plugin_url(data))
    def gen_context(self):
        menu = []

        if 'listType' in params.args:
            menu.append([
                Strings.txt(Strings.CONTEXT_REMOVE), 'RunPlugin({})'.format(
                    create_plugin_url({
                        SC.ACTION:
                        SC.ACTION_REMOVE_FROM_LIST,
                        SC.ITEM_ID:
                        self.data.get(SC.ITEM_ID),
                        SC.ITEM_PAGE:
                        get_history_item_name(self.data.get('lid'))
                    }))
            ])

        if get_setting('download.path'):
            menu.append([
                Strings.txt(Strings.CONTEXT_DOWNLOAD), 'RunPlugin({})'.format(
                    create_plugin_url({
                        SC.ACTION:
                        SC.ACTION_DOWNLOAD,
                        SC.ACTION_DOWNLOAD:
                        self.data.get(SC.ITEM_URL),
                    }))
            ])

        menu.append([
            Strings.txt(Strings.CONTEXT_SELECT_STREAM), 'PlayMedia({})'.format(
                create_plugin_url({
                    SC.ACTION_SELECT_STREAM: '1',
                    SC.ITEM_URL: self.data.get(SC.ITEM_URL),
                }))
        ])

        if get_setting_as_bool('stream.autoselect'):
            mediatype = self.data.get(SC.ITEM_INFO, {}).get('mediatype')
            if mediatype == 'tvshow' or mediatype == 'movie':
                item_id = self.data.get(SC.ITEM_ID)
                st = preferred_lang_list
                if st.get(item_id) is not None:
                    menu.append(
                        (Strings.txt(Strings.CONTEXT_DEL_PREF_LANG).format(
                            st[item_id]), 'RunPlugin({})'.format(
                                create_plugin_url({
                                    SC.ITEM_ACTION:
                                    SC.ACTION_DEL_PREFERRED_LANGUAGE,
                                    SC.ITEM_ID:
                                    self.data.get(SC.ITEM_ID)
                                }))))
                else:
                    menu.append((Strings.txt(Strings.CONTEXT_ADD_PREF_LANG),
                                 'RunPlugin({})'.format(
                                     create_plugin_url({
                                         SC.ITEM_ACTION:
                                         SC.ACTION_SET_PREFERRED_LANGUAGE,
                                         SC.ITEM_ID:
                                         self.data.get(SC.ITEM_ID)
                                     }))))

        if self.data.get(SC.ITEM_INFO, {}).get('trailer'):
            menu.append([
                'Trailer', 'PlayMedia({})'.format(
                    self.data.get(SC.ITEM_INFO, {}).get('trailer'))
            ])

        self.item.addContextMenuItems(items=menu)
    def make_ctx(self):
        context_menu = []

        if 'listType' in params.args:
            context_menu.append([
                Strings.txt(Strings.CONTEXT_REMOVE), 'RunPlugin({})'.format(
                    create_plugin_url({
                        SC.ACTION:
                        SC.ACTION_REMOVE_FROM_LIST,
                        SC.ITEM_ID:
                        self.data.get(SC.ITEM_ID),
                        SC.ITEM_PAGE:
                        get_history_item_name(self.data.get('lid'))
                    }))
            ])

        item_id = self.data.get(SC.ITEM_URL)
        # debug('ITEM: {}'.format(item_id))
        if 0 and item_id and settings.get_setting('tvshow.library.path'):

            if item_id and item_id in self.lib.get():
                debug('Uz je v kniznici s odberom')
                context_menu.append(
                    (Strings.txt(Strings.CONTEXT_REMOVE_FROM_SUB),
                     'RunPlugin({})'.format(
                         create_plugin_url({
                             SC.ITEM_ACTION:
                             SC.ACTION_REMOVE_FROM_SUBSCRIPTION,
                             SC.ITEM_ID: item_id
                         }))))
            else:
                debug('Este nieje v odbere')
                context_menu.append(
                    (Strings.txt(Strings.CONTEXT_ADD_TO_LIBRARY_WITH_SUB),
                     'RunPlugin({})'.format(
                         create_plugin_url({
                             SC.ITEM_ACTION:
                             SC.ACTION_ADD_TO_LIBRARY_WITH_SUBSCRIPTION,
                             SC.ITEM_ID: item_id
                         }))))

            context_menu.append((Strings.txt(Strings.CONTEXT_ADD_TO_LIBRARY),
                                 'RunPlugin({})'.format(
                                     create_plugin_url({
                                         SC.ITEM_ACTION:
                                         SC.ACTION_ADD_TO_LIBRARY,
                                         SC.ITEM_ID:
                                         self.data.get(item_id)
                                     }))))

        if params.args.get('url'):
            context_menu.append((Strings.txt(Strings.CONTEXT_PIN_UNPIN),
                                 'RunPlugin({})'.format(
                                     create_plugin_url({
                                         SC.ITEM_ACTION:
                                         SC.ACTION_PIN,
                                         SC.ITEM_URL:
                                         params.args.get(SC.ITEM_URL),
                                         SC.ITEM_ID:
                                         self.data.get(SC.ITEM_URL)
                                     }))))

            if get_system_platform() == 'android':
                context_menu.append(
                    (Strings.txt(Strings.CONTEXT_ADD_TO_ANDROID_TV),
                     'RunPlugin({})'.format(
                         create_plugin_url({
                             SC.ITEM_ACTION:
                             SC.ACTION_ANDROID,
                             SC.ITEM_URL:
                             self.data.get(SC.ITEM_URL),
                             SC.ITEM_ID:
                             self.item.getLabel()
                         }))))

            context_menu.append((Strings.txt(Strings.CONTEXT_PIN_TO_HP),
                                 'RunPlugin({})'.format(
                                     create_plugin_url({
                                         SC.ITEM_ACTION:
                                         SC.ACTION_ADD2HP,
                                         SC.ITEM_URL:
                                         self.data.get(SC.ITEM_URL),
                                         SC.ITEM_ID:
                                         self.item.getLabel()
                                     }))))

        if get_setting_as_bool('stream.autoselect'):
            # debug('data: {}'.format(self.data))
            mediatype = self.data.get(SC.ITEM_INFO, {}).get('mediatype')
            if mediatype == 'tvshow' or mediatype == 'movie':
                item_id = self.data.get(SC.ITEM_ID)
                st = preferred_lang_list
                if st.get(item_id) is not None:
                    context_menu.append(
                        (Strings.txt(Strings.CONTEXT_DEL_PREF_LANG).format(
                            st[item_id]), 'RunPlugin({})'.format(
                                create_plugin_url({
                                    SC.ITEM_ACTION:
                                    SC.ACTION_DEL_PREFERRED_LANGUAGE,
                                    SC.ITEM_ID:
                                    self.data.get(SC.ITEM_ID)
                                }))))
                else:
                    context_menu.append(
                        (Strings.txt(Strings.CONTEXT_ADD_PREF_LANG),
                         'RunPlugin({})'.format(
                             create_plugin_url({
                                 SC.ITEM_ACTION:
                                 SC.ACTION_SET_PREFERRED_LANGUAGE,
                                 SC.ITEM_ID:
                                 self.data.get(SC.ITEM_ID)
                             }))))

        if context_menu:
            self.item.addContextMenuItems(context_menu)