Example #1
0
    img = addon_pbe.queries.pop("pbe_img", "")
    fanart = addon_pbe.queries.pop("pbe_fanart", "")
    infolabels = addon_pbe.queries.pop("pbe_infolabels", "")
    if infolabels:
        import re

        try:
            import json
        except:
            import simplejson as json
        infolabels = json.loads(
            re.sub(r",\s*(\w+)", r", '\1'", re.sub(r"\{(\w+)", r"{'\1'", infolabels.replace("\\", "\\\\"))).replace(
                "'", '"'
            )
        )
        infolabels = common.decode_dict(infolabels)

    if pbe_mode == "queueitem":
        try:
            playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)

            item_already_in_PL = False
            playlist_item_count = len(playlist)
            playlist_item_loop = playlist_item_count
            for x in range(0, playlist_item_loop):
                if playlist[x].getfilename() == url:
                    item_already_in_PL = True
                    common.notify(addon_id_tmp, "small", "", "Item: " + title + " - already in Queue.", "8000")
                    break
            if item_already_in_PL == False:
Example #2
0
    def get_watch_history(self, addon_id):
        '''
            Get the watch history for the addon with provided addon_id
            If addon_id == 'all': get the entire watch history
            
            Args:
                addon_id (str): addon id of the plugin requesting its watch history
        '''
        history_items = []

        try:
            import json
        except:
            import simplejson as json

        sql_select = "SELECT * FROM watch_history"

        whereadded = False
        if addon_id != 'all':
            sql_select = sql_select + ' WHERE addon_id = \'' + addon_id + '\''
            whereadded = True

        if self._settings_add_as_dir() == 'true':
            sql_select = sql_select + " ORDER BY lastwatched DESC, title ASC, level DESC"
        else:
            if whereadded == False:
                sql_select = sql_select + ' WHERE '
                whereadded = True
            else:
                sql_select = sql_select + ' AND '

            sql_select = sql_select + " level = '0' ORDER BY lastwatched DESC, title ASC"

        common.addon.log('-' + HELPER + '- -' + sql_select, 2)

        self.dbcur.execute(sql_select)

        parent_items = {}
        parent_items_legacy = []

        for matchedrow in self.dbcur.fetchall():

            match = dict(matchedrow)

            item_level = match['level']
            match_hash_title = match['hash_title']
            item_parent = match['parent_title']
            if item_parent:
                item_parent = match['addon_id'] + '-' + item_parent
            match_title = match['title']

            if self._settings_add_as_dir(
            ) == 'true' and item_level == '0' and (
                (item_parent != ''
                 and parent_items.get(item_parent, None) != None) or
                (match_title[0:match_title.find(' - ')]
                 in parent_items_legacy)):
                continue

            infolabels = {}
            if match['infolabels']:
                infolabels = json.loads(
                    re.sub(
                        r",\s*(\w+)", r", '\1'",
                        re.sub(r"\{(\w+)",
                               r"{'\1'", match['infolabels'].replace(
                                   '\\', '\\\\'))).replace("'", '"'))
            infolabels['title'] = match['fmtd_title']

            item = {
                'title_trunc': match['title'],
                'title': match['fmtd_title'],
                'url': match['url'],
                'infolabels': common.decode_dict(infolabels),
                'image_url': match['image_url'],
                'fanart_url': match['fanart_url'],
                'isplayable': match['isplayable'],
                'isfolder': match['isfolder']
            }

            history_items.append(item)

            if int(item_level) > 0:
                parent_items[match['addon_id'] + '-' +
                             match_hash_title] = match
                parent_items_legacy.append(match_title)

        return history_items
Example #3
0
    def get_watch_history(self, addon_id):
        '''
            Get the watch history for the addon with provided addon_id
            If addon_id == 'all': get the entire watch history
            
            Args:
                addon_id (str): addon id of the plugin requesting its watch history
        '''
        history_items = []
        
        try:
            import json
        except:
            import simplejson as json

        sql_select = "SELECT * FROM watch_history"
        
        whereadded = False
        if addon_id != 'all':
            sql_select = sql_select + ' WHERE addon_id = \'' + addon_id + '\''
            whereadded = True
        
        if self._settings_add_as_dir() == 'true':
            sql_select = sql_select + " ORDER BY lastwatched DESC, title ASC, level DESC"
        else:
            if whereadded == False:
                sql_select = sql_select + ' WHERE '
                whereadded = True
            else:
                sql_select = sql_select + ' AND '
                
            sql_select = sql_select + " level = '0' ORDER BY lastwatched DESC, title ASC"
                
        common.addon.log('-' + HELPER + '- -' +sql_select, 2)

        self.dbcur.execute(sql_select)
        
        parent_items = {}
        parent_items_legacy = []
        
        for matchedrow in self.dbcur.fetchall():
        
            match = dict(matchedrow)
            
            item_level = match['level']
            match_hash_title = match['hash_title']
            item_parent = match['parent_title']
            if item_parent:
                item_parent = match['addon_id'] + '-' + item_parent
            match_title = match['title']
            
            if self._settings_add_as_dir() == 'true' and item_level == '0' and ( 
                (item_parent != '' and parent_items.get(item_parent, None) != None) or 
                (match_title[0:match_title.find(' - ')] in parent_items_legacy)
                ):
                continue
            
            infolabels = {}
            if match['infolabels']:
                infolabels = json.loads(re.sub(r",\s*(\w+)", r", '\1'", re.sub(r"\{(\w+)", r"{'\1'", match['infolabels'].replace('\\','\\\\'))).replace("'", '"'))
            infolabels['title'] = match['fmtd_title']

            item = {'title_trunc':match['title'] ,'title':match['fmtd_title'], 'url' : match['url'], 'infolabels': common.decode_dict(infolabels), 'image_url':match['image_url'], 'fanart_url':match['fanart_url'], 'isplayable':match['isplayable'], 'isfolder':match['isfolder']}
            
            history_items.append(item)
            
            if int(item_level) > 0: 
                parent_items[ match['addon_id'] + '-' + match_hash_title] = match
                parent_items_legacy.append(match_title)
            
        return history_items
Example #4
0
    def get_favorites(self, section_title='all', sub_section_title='all', addon_id='all', item_mode='main'):
        
        favorites = []
        
        item_column_section = ''
        item_column_sub_section = ''
        if item_mode == 'main':
            item_column_section = 'section_title'
            item_column_sub_section = 'sub_section_title'
        elif item_mode == 'addon':
            item_column_section = 'section_addon_title'
            item_column_sub_section = 'sub_section_addon_title'
            
        if DB == 'mysql':
            params_var = "%s"
        else:
            params_var = "?"
        
        try:
            import json
        except:
            import simplejson as json
            
        params = []

        sql_select = "SELECT * FROM favorites"
                
        
        whereadded = False
        if addon_id != 'all':
            params.append(addon_id)
            sql_select = sql_select + ' WHERE addon_id = ' + params_var
            whereadded = True
        
        if section_title != 'all':
            params.append(section_title)
            if whereadded == False:
                sql_select = sql_select + ' WHERE '
                whereadded = True
            else:
                sql_select = sql_select + ' AND '        
            sql_select = sql_select + item_column_section + " = " + params_var             
            
            if sub_section_title != 'all':
                params.append(sub_section_title)
                sql_select = sql_select + " AND " + item_column_sub_section + " = " + params_var 
        
        
        sql_select = sql_select + " ORDER BY title ASC"
        
        params = tuple(params)
            
        common.addon.log('-' + HELPER + '- -' + sql_select + ":" + (" %s," * len(params)) % params, 2)

        self.dbcur.execute(sql_select, params)
        
        for matchedrow in self.dbcur.fetchall():
        
            match = dict(matchedrow)
                        
            infolabels = {}
            if match['infolabels']:
                infolabels = json.loads(re.sub(r",\s*(\w+)", r", '\1'", re.sub(r"\{(\w+)", r"{'\1'", match['infolabels'].replace('\\','\\\\'))).replace("'", '"'))
            infolabels['title'] = match['fmtd_title']

            item = {'addon_id' : match['addon_id'], 'section_title':match['section_title'], 'sub_section_title':match['sub_section_title'], 'section_addon_title' :match['section_addon_title'], 'sub_section_addon_title':match['sub_section_addon_title'], 'title':match['title'], 'fmtd_title':match['fmtd_title'], 'url' : match['url'], 'infolabels': common.decode_dict(infolabels), 'image_url':match['image_url'], 'fanart_url':match['fanart_url'], 'isplayable' : match['isplayable'], 'isfolder':match['isfolder']}
            
            favorites.append(item)
            
        return favorites
Example #5
0
    def get_favorites(self,
                      section_title='all',
                      sub_section_title='all',
                      addon_id='all',
                      item_mode='main'):

        favorites = []

        item_column_section = ''
        item_column_sub_section = ''
        if item_mode == 'main':
            item_column_section = 'section_title'
            item_column_sub_section = 'sub_section_title'
        elif item_mode == 'addon':
            item_column_section = 'section_addon_title'
            item_column_sub_section = 'sub_section_addon_title'

        if DB == 'mysql':
            params_var = "%s"
        else:
            params_var = "?"

        try:
            import json
        except:
            import simplejson as json

        params = []

        sql_select = "SELECT * FROM favorites"

        whereadded = False
        if addon_id != 'all':
            params.append(addon_id)
            sql_select = sql_select + ' WHERE addon_id = ' + params_var
            whereadded = True

        if section_title != 'all':
            params.append(section_title)
            if whereadded == False:
                sql_select = sql_select + ' WHERE '
                whereadded = True
            else:
                sql_select = sql_select + ' AND '
            sql_select = sql_select + item_column_section + " = " + params_var

            if sub_section_title != 'all':
                params.append(sub_section_title)
                sql_select = sql_select + " AND " + item_column_sub_section + " = " + params_var

        sql_select = sql_select + " ORDER BY title ASC"

        params = tuple(params)

        common.addon.log(
            '-' + HELPER + '- -' + sql_select + ":" +
            (" %s," * len(params)) % params, 2)

        self.dbcur.execute(sql_select, params)

        for matchedrow in self.dbcur.fetchall():

            match = dict(matchedrow)

            infolabels = {}
            if match['infolabels']:
                infolabels = json.loads(
                    re.sub(
                        r",\s*(\w+)", r", '\1'",
                        re.sub(r"\{(\w+)",
                               r"{'\1'", match['infolabels'].replace(
                                   '\\', '\\\\'))).replace("'", '"'))
            infolabels['title'] = match['fmtd_title']

            item = {
                'addon_id': match['addon_id'],
                'section_title': match['section_title'],
                'sub_section_title': match['sub_section_title'],
                'section_addon_title': match['section_addon_title'],
                'sub_section_addon_title': match['sub_section_addon_title'],
                'title': match['title'],
                'fmtd_title': match['fmtd_title'],
                'url': match['url'],
                'infolabels': common.decode_dict(infolabels),
                'image_url': match['image_url'],
                'fanart_url': match['fanart_url'],
                'isplayable': match['isplayable'],
                'isfolder': match['isfolder']
            }

            favorites.append(item)

        return favorites
Example #6
0
 
 pbe_mode = addon_pbe.queries.pop('pbe_mode')
 addon_id_tmp = addon_pbe.queries.pop('pbe_addon_id')
 title = addon_pbe.queries.pop('pbe_title')
 url = addon_pbe.queries.pop('pbe_url')
 img = addon_pbe.queries.pop('pbe_img', '')
 fanart = addon_pbe.queries.pop('pbe_fanart', '')
 infolabels = addon_pbe.queries.pop('pbe_infolabels', '')
 if infolabels:
     import re
     try:
         import json
     except:
         import simplejson as json
     infolabels = json.loads(re.sub(r",\s*(\w+)", r", '\1'", re.sub(r"\{(\w+)", r"{'\1'", infolabels.replace('\\','\\\\'))).replace("'", '"'))
     infolabels = common.decode_dict(infolabels)
 
 if pbe_mode == 'queueitem':
     try:
         playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
         
         item_already_in_PL = False
         playlist_item_count = len(playlist)
         playlist_item_loop = playlist_item_count
         for x in range(0, playlist_item_loop):
             if playlist[x].getfilename() == url:
                 item_already_in_PL = True
                 common.notify(addon_id_tmp, 'small', '', 'Item: ' + title + ' - already in Queue.', '8000')
                 break
         if item_already_in_PL == False: