예제 #1
0
 def add_item(self, title, url, fmtd_title='', section_title='Misc.', section_addon_title='', sub_section_title='', sub_section_addon_title='', infolabels='', img='', fanart='', is_playable=False, is_folder=False):
     
     if not fmtd_title: fmtd_title = title
     if not section_addon_title: section_addon_title = section_title
     if not sub_section_addon_title: sub_section_addon_title = sub_section_title
     
     uni_fav = {
         'uni_fav_addon_id': self.addon_id,
         'uni_fav_mode': 'add',
         'uni_fav_title': title,
         'uni_fav_fmtd_title': fmtd_title,
         'uni_fav_url': url,
         'uni_fav_section_title': section_title,
         'uni_fav_section_addon_title': section_addon_title,
         'uni_fav_sub_section_title': sub_section_title,
         'uni_fav_sub_section_addon_title': sub_section_addon_title,
         'uni_fav_img': img,
         'uni_fav_fanart': fanart,
         'uni_fav_is_playable': common.bool2str(is_playable),
         'uni_fav_is_folder': common.bool2str(is_folder)            
         }
     
     uni_fav_add_script = 'XBMC.RunScript(%s, %s, %s, "%s")' % (self._get_script_path(), self.sys_argv[1], self._build_params(uni_fav, infolabels), 'plugin.video.couchtuner.favorites')
     
     return uni_fav_add_script
예제 #2
0
    def add_item_to_db(self, title, fmtd_title, url, section_title,
                       section_addon_title, sub_section_title,
                       sub_section_addon_title, infolabels, img, fanart,
                       is_playable, is_folder):
        if url.find('&favorite=true'):
            url = url.replace('&favorite=true', '')
        elif url.find('?favorite=true&'):
            url = url.replace('?favorite=true&', '?')

        hash_title = hashlib.md5(title).hexdigest()

        sql_insert = ''
        if self.is_already_in_favorites(section_title, section_addon_title,
                                        sub_section_title,
                                        sub_section_addon_title,
                                        title) == True:
            #common.notify(self.addon_id, 'small', '', 'Item: ' + fmtd_title + ' - already exists in Favorites.', '8000')
            common.notify(self.addon_id, 'small', '[B]' + fmtd_title + '[/B]',
                          '[B]Already exists in Favorites.[/B]', '8000')
        else:
            if DB == 'mysql':
                sql_insert = "INSERT INTO favorites(addon_id, hash_title, title, fmtd_title, url, section_title, section_addon_title, sub_section_title, sub_section_addon_title, infolabels, image_url, fanart_url, isfolder, isplayable ) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
            else:
                sql_insert = "INSERT INTO favorites(addon_id, hash_title, title, fmtd_title, url, section_title, section_addon_title, sub_section_title, sub_section_addon_title, infolabels, image_url, fanart_url, isfolder, isplayable ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

            if infolabels:
                infolabels = common.encode_dict(infolabels)

            common.addon.log(
                '-' + HELPER + '- -' +
                '%s: %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s' %
                (sql_insert, self.addon_id, hash_title, title, fmtd_title, url,
                 section_title, section_addon_title, sub_section_title,
                 sub_section_addon_title, str(infolabels), img, fanart,
                 common.bool2str(is_folder), common.bool2str(is_playable)), 2)

            try:
                self.dbcur.execute(
                    sql_insert,
                    (self.addon_id, hash_title, title, fmtd_title, url,
                     section_title, section_addon_title, sub_section_title,
                     sub_section_addon_title, str(infolabels), img, fanart,
                     common.bool2str(is_folder), common.bool2str(is_playable)))
                self.dbcon.commit()
                #common.notify(self.addon_id, 'small', '', 'Item: ' + fmtd_title + ' - added successfully to Favorites.', '8000')
                common.notify(self.addon_id, 'small',
                              '[B]' + fmtd_title + '[/B]',
                              '[B]Added to Favorites.[/B]', '8000')
            except:
                #common.notify(self.addon_id, 'small', '', 'Item: ' + fmtd_title + ' - unable to add to Favorites.', '8000')
                common.notify(self.addon_id, 'small',
                              '[B]' + fmtd_title + '[/B]',
                              '[B]Unable to add to Favorites.[/B]', '8000')
                pass
예제 #3
0
 def add_item_to_db(self, title, fmtd_title, url, section_title, section_addon_title, sub_section_title, sub_section_addon_title, infolabels, img, fanart, is_playable, is_folder):
     if url.find('&favorite=true'):
         url = url.replace('&favorite=true', '')
     elif url.find('?favorite=true&'):
         url = url.replace('?favorite=true&', '?')
         
     hash_title = hashlib.md5(title).hexdigest()
                    
     sql_insert = ''
     if self.is_already_in_favorites(section_title, section_addon_title, sub_section_title, sub_section_addon_title, title) == True:
         #common.notify(self.addon_id, 'small', '', 'Item: ' + fmtd_title + ' - already exists in Favorites.', '8000')
         common.notify(self.addon_id, 'small', '[B]' + fmtd_title + '[/B]', '[B]Already exists in Favorites.[/B]', '8000')
     else:
         if DB == 'mysql':
             sql_insert = "INSERT INTO favorites(addon_id, hash_title, title, fmtd_title, url, section_title, section_addon_title, sub_section_title, sub_section_addon_title, infolabels, image_url, fanart_url, isfolder, isplayable ) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
         else:
             sql_insert = "INSERT INTO favorites(addon_id, hash_title, title, fmtd_title, url, section_title, section_addon_title, sub_section_title, sub_section_addon_title, infolabels, image_url, fanart_url, isfolder, isplayable ) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"            
             
         if infolabels:
             infolabels = common.encode_dict(infolabels)
             
         common.addon.log('-' + HELPER + '- -' +'%s: %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s' % (sql_insert, self.addon_id, hash_title, title, fmtd_title, url, section_title, section_addon_title, sub_section_title, sub_section_addon_title, str(infolabels), img, fanart, common.bool2str(is_folder), common.bool2str(is_playable)), 2)
         
         try:
             self.dbcur.execute(sql_insert, (self.addon_id, hash_title, title, fmtd_title, url, section_title, section_addon_title, sub_section_title, sub_section_addon_title, str(infolabels), img, fanart, common.bool2str(is_folder), common.bool2str(is_playable) ))            
             self.dbcon.commit()
             #common.notify(self.addon_id, 'small', '', 'Item: ' + fmtd_title + ' - added successfully to Favorites.', '8000')
             common.notify(self.addon_id, 'small', '[B]' + fmtd_title + '[/B]', '[B]Added to Favorites.[/B]', '8000')
         except:
             #common.notify(self.addon_id, 'small', '', 'Item: ' + fmtd_title + ' - unable to add to Favorites.', '8000')                
             common.notify(self.addon_id, 'small', '[B]' + fmtd_title + '[/B]', '[B]Unable to add to Favorites.[/B]', '8000')
             pass
예제 #4
0
    def add_item(self, title, url, fmtd_title = '', level='0', parent_title='', indent_title='', infolabels='', img='', fanart='', is_playable=False, is_folder=False):
        '''
            Add an item to watch history.
            
            Args:
                title (str): title of the item; used to generate title-hash and sorting
                
                url (str): the compelte plugin url that would be called when this item is selected
                
            Kwargs:
                fmtd_title (str): title of the item as it will be displayed in the list. 
                        if fmtd_title is None:
                            fmtd_title = title
                            
                level (str): item level in the hierarchy. Used if playable-item's parent is also being added to the favorites.
                        Non-parent's level is '0'
                        Parent's level starts with '1'
                        Should be covnertiable to integer
                        
                parent_title (str): If the item has a parent, then the title used to identify the parent
                
                indent_title (str): Title to be used in parent-indent mode (WIP)
                        If indent_title is None:
                            indent_title = fmtd_title
                            
                info_labels (hash): Any information that the calling plugin might need when the item is being retreived goes here.
                        This is also used to set support for metadata for the item with watch history.
                        infolabels = { 'supports_meta' : 'true', 'video_type':video_type, 'name':title, 'imdb_id':imdb_id, 
                            'season':season, 'episode':episode, 'year':year 
                        }
                        
                img (str): url or path of the image to be used as thumbnail and icon of the item
                
                fanart (str): url or path of the image to be used as fanart of the item
                
                is_playable (bool): set the item isPlayable property
                
                is_folder (bool): set the item isFolder property
        '''
        if url.find('&watchhistory=true'):
            url = url.replace('&watchhistory=true', '')
        elif url.find('?watchhistory=true&'):
            url = url.replace('?watchhistory=true&', '?')
            
        title = common.str_conv(title)                
            
        if not fmtd_title:
            fmtd_title = title
        else:
            fmtd_title = common.str_conv(fmtd_title)
            
        if not indent_title:
            indent_title = fmtd_title
        else:
            indent_title = common.str_conv(indent_title)
            
        hash_title = hashlib.md5(title).hexdigest()

        if parent_title:
            parent_title = common.str_conv(parent_title)

        if parent_title:
            parent_title = hashlib.md5(parent_title).hexdigest()
                       
        row_exists = True
        try:
            if DB == 'mysql':
                sql_select = "SELECT * FROM watch_history WHERE addon_id = %s AND hash_title = %s"
            else:
                sql_select = "SELECT * FROM watch_history WHERE addon_id = ? AND hash_title = ?"
            common.addon.log('-' + HELPER + '- -' + '%s : %s, %s' %(sql_select, self.addon_id, hash_title), 2 )
            self.dbcur.execute(sql_select, (self.addon_id, hash_title))
            common.addon.log('-' + HELPER + '- -' + str(self.dbcur.fetchall()[0]), 2)
        except:
            row_exists = False
                
        sql_update_or_insert = ''
        if row_exists == True:
            if DB == 'mysql':
                sql_update_or_insert = "UPDATE watch_history SET lastwatched = %s WHERE addon_id = %s AND hash_title = %s" 
            else:
                sql_update_or_insert = "UPDATE watch_history SET lastwatched = ? WHERE addon_id = ? AND hash_title = ?" 
            common.addon.log('-' + HELPER + '- -' + '%s : %s, %s, %s' %(sql_update_or_insert, 'datetime.datetime.now()', self.addon_id, hash_title), 2 )
            self.dbcur.execute(sql_update_or_insert, (datetime.datetime.now(), self.addon_id, hash_title))
        else:        
            if DB == 'mysql':
                sql_update_or_insert = "INSERT INTO watch_history(addon_id, hash_title, title, fmtd_title, url, infolabels, image_url, fanart_url, isplayable, isfolder, lastwatched, level, parent_title, indent_title) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
            else:
                sql_update_or_insert = "INSERT INTO watch_history(addon_id, hash_title, title, fmtd_title, url, infolabels, image_url, fanart_url, isplayable, isfolder, lastwatched, level, parent_title, indent_title) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
                
            if infolabels:
                infolabels = common.encode_dict(infolabels)
                
            is_playable = common.bool2str(is_playable)
            is_folder = common.bool2str(is_folder)
            infolabels = str(infolabels)
            
            common.addon.log('-' + HELPER + '- -' + '%s : %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s' %(sql_update_or_insert, self.addon_id, hash_title, title, fmtd_title, common.str_conv(url), infolabels, img, fanart, is_playable, is_folder, 'datetime.datetime.now()', level, parent_title, indent_title), 2 )
            self.dbcur.execute(sql_update_or_insert, (self.addon_id, hash_title, title, fmtd_title, url, infolabels, img, fanart, is_playable, is_folder, datetime.datetime.now(), level, parent_title, indent_title))
        self.dbcon.commit()
예제 #5
0
    def add_item(self,
                 title,
                 url,
                 fmtd_title='',
                 level='0',
                 parent_title='',
                 indent_title='',
                 infolabels='',
                 img='',
                 fanart='',
                 is_playable=False,
                 is_folder=False):
        '''
            Add an item to watch history.
            
            Args:
                title (str): title of the item; used to generate title-hash and sorting
                
                url (str): the compelte plugin url that would be called when this item is selected
                
            Kwargs:
                fmtd_title (str): title of the item as it will be displayed in the list. 
                        if fmtd_title is None:
                            fmtd_title = title
                            
                level (str): item level in the hierarchy. Used if playable-item's parent is also being added to the favorites.
                        Non-parent's level is '0'
                        Parent's level starts with '1'
                        Should be covnertiable to integer
                        
                parent_title (str): If the item has a parent, then the title used to identify the parent
                
                indent_title (str): Title to be used in parent-indent mode (WIP)
                        If indent_title is None:
                            indent_title = fmtd_title
                            
                info_labels (hash): Any information that the calling plugin might need when the item is being retreived goes here.
                        This is also used to set support for metadata for the item with watch history.
                        infolabels = { 'supports_meta' : 'true', 'video_type':video_type, 'name':title, 'imdb_id':imdb_id, 
                            'season':season, 'episode':episode, 'year':year 
                        }
                        
                img (str): url or path of the image to be used as thumbnail and icon of the item
                
                fanart (str): url or path of the image to be used as fanart of the item
                
                is_playable (bool): set the item isPlayable property
                
                is_folder (bool): set the item isFolder property
        '''
        if url.find('&watchhistory=true'):
            url = url.replace('&watchhistory=true', '')
        elif url.find('?watchhistory=true&'):
            url = url.replace('?watchhistory=true&', '?')

        title = common.str_conv(title)

        if not fmtd_title:
            fmtd_title = title
        else:
            fmtd_title = common.str_conv(fmtd_title)

        if not indent_title:
            indent_title = fmtd_title
        else:
            indent_title = common.str_conv(indent_title)

        hash_title = hashlib.md5(title).hexdigest()

        if parent_title:
            parent_title = common.str_conv(parent_title)

        if parent_title:
            parent_title = hashlib.md5(parent_title).hexdigest()

        row_exists = True
        try:
            if DB == 'mysql':
                sql_select = "SELECT * FROM watch_history WHERE addon_id = %s AND hash_title = %s"
            else:
                sql_select = "SELECT * FROM watch_history WHERE addon_id = ? AND hash_title = ?"
            common.addon.log(
                '-' + HELPER + '- -' + '%s : %s, %s' %
                (sql_select, self.addon_id, hash_title), 2)
            self.dbcur.execute(sql_select, (self.addon_id, hash_title))
            common.addon.log(
                '-' + HELPER + '- -' + str(self.dbcur.fetchall()[0]), 2)
        except:
            row_exists = False

        sql_update_or_insert = ''
        if row_exists == True:
            if DB == 'mysql':
                sql_update_or_insert = "UPDATE watch_history SET lastwatched = %s WHERE addon_id = %s AND hash_title = %s"
            else:
                sql_update_or_insert = "UPDATE watch_history SET lastwatched = ? WHERE addon_id = ? AND hash_title = ?"
            common.addon.log(
                '-' + HELPER + '- -' + '%s : %s, %s, %s' %
                (sql_update_or_insert, 'datetime.datetime.now()',
                 self.addon_id, hash_title), 2)
            self.dbcur.execute(
                sql_update_or_insert,
                (datetime.datetime.now(), self.addon_id, hash_title))
        else:
            if DB == 'mysql':
                sql_update_or_insert = "INSERT INTO watch_history(addon_id, hash_title, title, fmtd_title, url, infolabels, image_url, fanart_url, isplayable, isfolder, lastwatched, level, parent_title, indent_title) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
            else:
                sql_update_or_insert = "INSERT INTO watch_history(addon_id, hash_title, title, fmtd_title, url, infolabels, image_url, fanart_url, isplayable, isfolder, lastwatched, level, parent_title, indent_title) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

            if infolabels:
                infolabels = common.encode_dict(infolabels)

            is_playable = common.bool2str(is_playable)
            is_folder = common.bool2str(is_folder)
            infolabels = str(infolabels)

            common.addon.log(
                '-' + HELPER + '- -' +
                '%s : %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s' %
                (sql_update_or_insert, self.addon_id, hash_title, title,
                 fmtd_title, common.str_conv(url), infolabels, img, fanart,
                 is_playable, is_folder, 'datetime.datetime.now()', level,
                 parent_title, indent_title), 2)
            self.dbcur.execute(
                sql_update_or_insert,
                (self.addon_id, hash_title, title, fmtd_title, url,
                 infolabels, img, fanart, is_playable, is_folder,
                 datetime.datetime.now(), level, parent_title, indent_title))
        self.dbcon.commit()