예제 #1
0
    def build_details(self):
        self.item['id'] = self.tmdb_id
        self.item['tmdb'] = self.tmdb_id
        self.item['imdb'] = self.details.get('infolabels', {}).get('imdbnumber')
        self.item['name'] = u'{0} ({1})'.format(self.item.get('title'), self.item.get('year'))
        self.item['premiered'] = self.item['firstaired'] = self.item['released'] = self.details.get('infolabels', {}).get('premiered')
        self.item['plot'] = self.details.get('infolabels', {}).get('plot')
        self.item['cast'] = self.item['actors'] = " / ".join([i.get('name') for i in self.details.get('cast', []) if i.get('name')])
        self.item['showname'] = self.item['clearname'] = self.item['tvshowtitle'] = self.item['title'] = self.item.get('title')
        self.item['thumbnail'] = self.details.get('thumb')
        self.item['poster'] = self.details.get('poster')
        self.item['fanart'] = self.details.get('fanart')
        self.item['now'] = datetime.datetime.now().strftime('%Y%m%d%H%M%S%f')

        if self.traktapi:
            slug_type = utils.type_convert(self.tmdbtype, 'trakt')
            trakt_details = self.traktapi.get_details(slug_type, self.traktapi.get_traktslug(slug_type, 'tmdb', self.tmdb_id))
            self.item['trakt'] = trakt_details.get('ids', {}).get('trakt')
            self.item['imdb'] = self.details.get('infoproperties', {}).get('tvshow.imdb_id') or trakt_details.get('ids', {}).get('imdb')
            self.item['tvdb'] = self.details.get('infoproperties', {}).get('tvshow.tvdb_id') or trakt_details.get('ids', {}).get('tvdb')
            self.item['slug'] = trakt_details.get('ids', {}).get('slug')

        if self.itemtype == 'episode':  # Do some special episode stuff
            self.item['id'] = self.item.get('tvdb')
            self.item['title'] = self.details.get('infolabels', {}).get('title')  # Set Episode Title
            self.item['name'] = u'{0} S{1:02d}E{2:02d}'.format(self.item.get('showname'), int(utils.try_parse_int(self.season)), int(utils.try_parse_int(self.episode)))
            self.item['season'] = self.season
            self.item['episode'] = self.episode
            self.item['showpremiered'] = self.details.get('infoproperties', {}).get('tvshow.premiered')
            self.item['showyear'] = self.details.get('infoproperties', {}).get('tvshow.year')

        if self.traktapi and self.itemtype == 'episode':
            trakt_details = self.traktapi.get_details(slug_type, self.item.get('slug'), season=self.season, episode=self.episode)
            self.item['epid'] = self.details.get('infoproperties', {}).get('tvdb_id') or trakt_details.get('ids', {}).get('tvdb')
            self.item['epimdb'] = trakt_details.get('ids', {}).get('imdb')
            self.item['eptmdb'] = self.details.get('infoproperties', {}).get('tmdb_id') or trakt_details.get('ids', {}).get('tmdb')
            self.item['eptrakt'] = trakt_details.get('ids', {}).get('trakt')

        utils.kodi_log(u'Player Details - Item:\n{}'.format(self.item), 2)

        for k, v in self.item.copy().items():
            if k not in constants.PLAYER_URLENCODE:
                continue
            v = u'{0}'.format(v)
            for key, value in {k: v, '{}_meta'.format(k): dumps(v)}.items():
                self.item[key] = value.replace(',', '')
                self.item[key + '_+'] = value.replace(',', '').replace(' ', '+')
                self.item[key + '_-'] = value.replace(',', '').replace(' ', '-')
                self.item[key + '_escaped'] = quote(quote(utils.try_encode_string(value)))
                self.item[key + '_escaped+'] = quote(quote_plus(utils.try_encode_string(value)))
                self.item[key + '_url'] = quote(utils.try_encode_string(value))
                self.item[key + '_url+'] = quote_plus(utils.try_encode_string(value))
def library_createfile(filename, content, *args, **kwargs):
    """
    Create the file and folder structure: filename=.strm file, content= content of file.
    *args = folders to create.
    """
    file_ext = kwargs.pop('file_ext', 'strm')
    clean_url = kwargs.pop('clean_url', True)
    path = kwargs.pop('basedir', '')
    path = path.replace('\\', '/')
    if not path:
        utils.kodi_log(u'ADD LIBRARY -- No basedir specified!', 2)
        return
    content = library_cleancontent(content) if clean_url else content
    for folder in args:
        folder = utils.validify_filename(folder)
        path = '{}{}/'.format(path, folder)
    if not content:
        utils.kodi_log(u'ADD LIBRARY -- No content specified!', 2)
        return
    if not filename:
        utils.kodi_log(u'ADD LIBRARY -- No filename specified!', 2)
        return
    if not library_createpath(path):
        xbmcgui.Dialog().ok(
            xbmc.getLocalizedString(20444),
            _addon.getLocalizedString(32122) + ' [B]{}[/B]'.format(path),
            _addon.getLocalizedString(32123))
        utils.kodi_log(u'ADD LIBRARY -- XBMCVFS unable to create path:\n{}'.format(path), 2)
        return
    filepath = '{}{}.{}'.format(path, utils.validify_filename(filename), file_ext)
    f = xbmcvfs.File(filepath, 'w')
    f.write(utils.try_encode_string(content))
    f.close()
    utils.kodi_log(u'ADD LIBRARY -- Successfully added:\n{}\n{}'.format(filepath, content), 2)
    return filepath
    def play_external(self, playerindex=-1, force_dialog=False):
        playerindex = self.player_getnewindex(playerindex, force_dialog=force_dialog)

        # User cancelled dialog
        if not playerindex > -1:
            utils.kodi_log(u'Player -- User cancelled', 2)
            return False

        # Run through player actions
        player = self.player_resolveurl(self.actions[playerindex])

        # Previous player failed so ask user to select a new one
        if player == -1:
            return self.play_external(playerindex, force_dialog=force_dialog)

        # Play/Search found item
        if player and player[1]:
            action = string_format_map(player[1], self.item)
            if player[0] and (action.endswith('.strm') or self.identifierlist[playerindex] == 'play_kodi'):  # Action is play and is a strm/local so PlayMedia
                utils.kodi_log(u'Player -- Found strm or local.\nAttempting PLAYMEDIA({})'.format(action), 1)
                xbmc.executebuiltin(utils.try_decode_string(u'PlayMedia(\"{0}\")'.format(action)))
            elif player[0]:  # Action is play and not a strm so play with player
                utils.kodi_log(u'Player -- Found file.\nAttempting to PLAY: {}'.format(action), 2)
                xbmcgui.Window(10000).setProperty('TMDbHelper.PlayerInfoString', self.playerstring) if self.playerstring else None
                xbmc.Player().play(action, ListItem(library='video', **self.details).set_listitem())
            else:
                action = u'Container.Update({0})'.format(action) if xbmc.getCondVisibility("Window.IsMedia") else u'ActivateWindow(videos,{0},return)'.format(action)
                utils.kodi_log(u'Player -- Found folder.\nAttempting to OPEN: {}'.format(action), 2)
                xbmc.executebuiltin(utils.try_encode_string(utils.try_decode_string(action)))
            return action
예제 #4
0
def create_file(filename, content, *args, **kwargs):
    """
    Create the file and folder structure: filename=.strm file, content= content of file.
    *args = folders to create.
    """

    # Validify and build path
    path = kwargs.get('basedir', '').replace('\\', '/')  # Convert MS-DOS style paths to UNIX style
    if not path:  # Make sure we actually have a basedir
        return
    for folder in args:
        folder = utils.validify_filename(folder)
        path = '{}{}/'.format(path, folder)

    # Validify content of file
    if kwargs.get('clean_url', True):
        content = clean_content(content)
    if not content:
        return
    if not filename:
        return

    # Check that we can actually make the path and warn user about potential xbmcvfs false negative override
    if not utils.makepath(path):
        xbmcgui.Dialog().ok(
            xbmc.getLocalizedString(20444),
            '{} [B]{}[/B]\n{}'.format(_addon.getLocalizedString(32122), path, _addon.getLocalizedString(32123)))
        utils.kodi_log(u'XBMCVFS unable to create path:\n{}'.format(path), 2)
        return

    # Write out our file
    filepath = '{}{}.{}'.format(path, utils.validify_filename(filename), kwargs.get('file_ext', 'strm'))
    f = xbmcvfs.File(filepath, 'w')
    f.write(utils.try_encode_string(content))
    f.close()

    utils.kodi_log(u'ADD LIBRARY -- Successfully added:\n{}\n{}'.format(filepath, content), 2)
    return filepath
    def build_details(self):
        self.item['id'] = self.tmdb_id
        self.item['tmdb'] = self.tmdb_id
        self.item['imdb'] = self.details.get('infolabels',
                                             {}).get('imdbnumber')
        self.item['name'] = u'{0} ({1})'.format(self.item.get('title'),
                                                self.item.get('year'))
        self.item['firstaired'] = self.details.get('infolabels',
                                                   {}).get('premiered')
        self.item['premiered'] = self.details.get('infolabels',
                                                  {}).get('premiered')
        self.item['released'] = self.details.get('infolabels',
                                                 {}).get('premiered')
        self.item['showname'] = self.item.get('title')
        self.item['clearname'] = self.item.get('title')
        self.item['tvshowtitle'] = self.item.get('title')
        self.item['title'] = self.item.get('title')
        self.item['thumbnail'] = self.details.get('thumb')
        self.item['poster'] = self.details.get('poster')
        self.item['fanart'] = self.details.get('fanart')
        self.item['now'] = datetime.datetime.now().strftime('%Y%m%d%H%M%S%f')

        if self.traktapi:
            slug_type = utils.type_convert(self.tmdbtype, 'trakt')
            trakt_details = self.traktapi.get_details(
                slug_type,
                self.traktapi.get_traktslug(slug_type, 'tmdb', self.tmdb_id))
            self.item['trakt'] = trakt_details.get('ids', {}).get('trakt')
            self.item['imdb'] = trakt_details.get('ids', {}).get('imdb')
            self.item['tvdb'] = trakt_details.get('ids', {}).get('tvdb')
            self.item['slug'] = trakt_details.get('ids', {}).get('slug')

        if self.itemtype == 'episode':  # Do some special episode stuff
            self.item['id'] = self.item.get('tvdb')
            self.item['title'] = self.details.get('infolabels', {}).get(
                'title')  # Set Episode Title
            self.item['name'] = u'{0} S{1:02d}E{2:02d}'.format(
                self.item.get('showname'),
                int(utils.try_parse_int(self.season)),
                int(utils.try_parse_int(self.episode)))
            self.item['season'] = self.season
            self.item['episode'] = self.episode

        if self.traktapi and self.itemtype == 'episode':
            trakt_details = self.traktapi.get_details(slug_type,
                                                      self.item.get('slug'),
                                                      season=self.season,
                                                      episode=self.episode)
            self.item['epid'] = trakt_details.get('ids', {}).get('tvdb')
            self.item['epimdb'] = trakt_details.get('ids', {}).get('imdb')
            self.item['eptmdb'] = trakt_details.get('ids', {}).get('tmdb')
            self.item['eptrakt'] = trakt_details.get('ids', {}).get('trakt')

        for k, v in self.item.copy().items():
            v = u'{0}'.format(v)
            self.item[k] = v.replace(',', '')
            self.item[k + '_+'] = v.replace(' ', '+')
            self.item[k + '_-'] = v.replace(' ', '-')
            self.item[k + '_escaped'] = v.replace(' ', '%2520')
            self.item[k + '_escaped+'] = v.replace(' ', '%252B')
            self.item[k + '_url'] = quote_plus(utils.try_encode_string(v))
예제 #6
0
    def make_variables(self):
        p_dialog = xbmcgui.DialogProgressBG()
        p_dialog.create('Skin Variables', 'Constructing Variables...')
        try:
            vfs_file = xbmcvfs.File(
                'special://skin/shortcuts/skinvariables.json')
            content = vfs_file.read()
            meta = loads(content) or []
        finally:
            vfs_file.close()

        if not self.params.get('force'):  # Allow overriding over built check
            this_version = len(content)
            last_version = utils.try_parse_int(
                xbmc.getInfoLabel('Skin.String(script-skinvariables-hash)'))
            if this_version and last_version and this_version == last_version:
                p_dialog.close()
                return  # Already updated

        if not meta:
            p_dialog.close()
            return

        i_total = 0
        for variable in meta:
            if not variable.get('name'):
                continue
            i_total += len(variable.get('containers', [])) + 1

        i_count = 0
        txt = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<includes>'
        for variable in meta:
            v_name = variable.get('name')
            values = variable.get('values', [])
            expression = variable.get('expression') if not values else None
            tag_name = 'expression' if expression else 'variable'
            if not v_name:
                continue  # Skip items without names
            containers = variable.get('containers', [])
            containers.append('')
            li_a = variable.get('listitems', {}).get('start', 0)
            li_z = variable.get('listitems', {}).get('end')
            listitems = [i for i in range(li_a, int(li_z) + 1)] if li_z else []
            listitems.append('')
            for container in containers:
                i_count += 1
                p_dialog.update((i_count * 100) // i_total,
                                message=u'{}_C{}'.format(v_name, container))
                for listitem in listitems:
                    txt_name = v_name
                    txt_name += '_C{}'.format(container) if container else ''
                    txt_name += '_{}'.format(
                        listitem) if listitem or listitem == 0 else ''
                    txt += '\n    <{} name=\"{}'.format(tag_name, txt_name)
                    txt += '\">'
                    li_name = 'Container({}).ListItem'.format(
                        container) if container else 'ListItem'
                    li_name += '({})'.format(listitem) if listitem else ''
                    f_dict = {
                        'listitem':
                        li_name,
                        'listitemabsolute':
                        li_name.replace('ListItem(', 'ListItemAbsolute('),
                        'listitemnowrap':
                        li_name.replace('ListItem(', 'ListItemNoWrap('),
                        'listitemposition':
                        li_name.replace('ListItem(', 'ListItemPosition(')
                    }
                    if expression:
                        txt += expression.format(**f_dict)
                    for value in values:
                        for k, v in value.items():
                            if not k or not v:
                                continue
                            cond = k.format(**f_dict)
                            valu = v.format(**f_dict)
                            txt += '\n        <value condition=\"{}\">{}</value>'.format(
                                cond, valu)
                    txt += '</{}>'.format(
                        tag_name) if expression else '\n    </{}>'.format(
                            tag_name)
        txt += '\n</includes>'

        folders = [self.params.get('folder')
                   ] if self.params.get('folder') else []
        if not folders:  # Get skin folders from addon
            try:
                addonfile = xbmcvfs.File('special://skin/addon.xml')
                content = addonfile.read()
                xmltree = ET.ElementTree(ET.fromstring(content))
                for child in xmltree.getroot():
                    if child.attrib.get('point') == 'xbmc.gui.skin':
                        for grandchild in child:
                            if grandchild.tag == 'res' and grandchild.attrib.get(
                                    'folder'):
                                folders.append(grandchild.attrib.get('folder'))
            finally:
                addonfile.close()

        if not folders:
            p_dialog.close()
            return

        for folder in folders:
            filepath = 'special://skin/{}/script-skinvariables-includes.xml'.format(
                folder)
            f = xbmcvfs.File(filepath, 'w')
            f.write(utils.try_encode_string(txt))
            f.close()
        xbmc.executebuiltin(
            'Skin.SetString(script-skinvariables-hash,{})'.format(
                len(content)))
        xbmc.executebuiltin('ReloadSkin()')
        p_dialog.close()