Example #1
0
    def _createListFromJson(self, requestURL, skipdescript=False):
        """
        Create and return the list from json data
        Returns list and name of the list
        
        Json data:
            u'rating'
            u'script_language'
            u'image'
            u'totalitems'
            u'id'
            u'title'
            u'version'
            u'filesize'
            u'totaldownloads'
            u'type'
            u'filetype'
            u'description'
            u'views'
            u'createdate'
            u'orginalfilename'
            u'description_en'
            u'xbmc_type'
            u'commenttotal'
            u'date'
            u'fileurl'
            u'ID_TOPIC'
            u'author'
            u'idparent'        
        """
        list = []

        # Retrieve json data
        jsondata = self._retrieve_json(requestURL, skipdescript)

        dicdata = json.loads(jsondata)

        # List the main categories at the root level
        for entry in dicdata:
            if Item.isSupported(categories[entry['xbmc_type']]):
                item = {}
                item['id'] = int(entry['id'])
                item['name'] = entry['title']  #.encode( "utf8" )
                item['parent'] = int(entry['idparent'])
                item['downloadurl'] = entry['fileurl']
                item['type'] = entry['type']  #'CAT'
                item['totaldownloads'] = entry['totaldownloads']
                item['xbmc_type'] = categories[entry['xbmc_type']]
                #item['cattype']           = entry
                if LANGUAGE_IS_FRENCH:
                    item['description'] = self.strip_off_passionCDT(
                        unescape(urllib.unquote(
                            entry['description'])))  #.encode("cp1252").
                else:
                    item['description'] = self.strip_off_passionCDT(
                        unescape(urllib.unquote(entry['description_en']))
                    )  #.encode("cp1252").decode('string_escape')
                if item['description'] == 'None':
                    item['description'] = _(604)
                item['language'] = entry['script_language']
                item['version'] = entry['version']
                item['author'] = entry['author']
                item['date'] = entry['createdate']
                if entry['date'] != '':
                    item['added'] = strftime('%d-%m-%Y',
                                             localtime(int(entry['date'])))
                else:
                    item['added'] = entry['date']
                if entry['filesize'] != '':
                    item['filesize'] = int(entry['filesize'])
                else:
                    item['filesize'] = 0  # ''
                item['thumbnail'] = Item.get_thumb(item['xbmc_type'])
                item['previewpictureurl'] = entry['image']
                item['previewpicture'] = ""  #Item.get_thumb( entry )
                item[
                    'image2retrieve'] = False  # Temporary patch for reseting the flag after downlaad (would be better in the thread in charge of the download)

                item['orginalfilename'] = entry['orginalfilename']
                #TODO: deprecated??? Check server side
                item['fileexternurl'] = "None"
                self._setDefaultImages(item)
                list.append(item)
                print item
            else:
                print "Type not supported by the installer:"
                print entry

        return list
    def _createListFromJson( self, requestURL, skipdescript=False ):
        """
        Create and return the list from json data
        Returns list and name of the list
        
        Json data:
            u'rating'
            u'script_language'
            u'image'
            u'totalitems'
            u'id'
            u'title'
            u'version'
            u'filesize'
            u'totaldownloads'
            u'type'
            u'filetype'
            u'description'
            u'views'
            u'createdate'
            u'orginalfilename'
            u'description_en'
            u'xbmc_type'
            u'commenttotal'
            u'date'
            u'fileurl'
            u'ID_TOPIC'
            u'author'
            u'idparent'        
        """
        list = []

        # Retrieve json data
        jsondata = self._retrieve_json( requestURL, skipdescript )
        
        dicdata = json.loads( jsondata )
        
        # List the main categories at the root level
        for entry in dicdata:
            if Item.isSupported( categories[ entry['xbmc_type'] ] ):
                item = {}
                item['id']                = int( entry['id'] )
                item['name']              = entry['title']#.encode( "utf8" )
                item['parent']            = int( entry['idparent'] )
                item['downloadurl']       = entry['fileurl']
                item['type']              = entry['type']#'CAT'
                item['totaldownloads']    = entry['totaldownloads']
                item['xbmc_type']         = categories[ entry['xbmc_type'] ]
                #item['cattype']           = entry
                if LANGUAGE_IS_FRENCH:
                    item['description']       = self.strip_off_passionCDT( unescape( urllib.unquote( entry['description'] ) ) )#.encode("cp1252").
                else:
                    item['description']       = self.strip_off_passionCDT( unescape( urllib.unquote( entry['description_en'] ) ) )#.encode("cp1252").decode('string_escape')
                if item['description'] == 'None':
                    item['description'] = _( 604 ) 
                item['language']          = entry['script_language']
                item['version']           = entry['version']
                item['author']            = entry['author']
                item['date']              = entry['createdate']
                if entry['date'] != '':
                    item['added'] = strftime( '%d-%m-%Y', localtime( int (entry['date'] ) ) )
                else:
                    item['added'] = entry['date']
                if entry['filesize'] != '':
                    item['filesize'] = int( entry['filesize'] )
                else:
                    item['filesize'] = 0 # ''
                item['thumbnail']         = Item.get_thumb( item['xbmc_type'] )
                item['previewpictureurl'] = entry['image']
                item['previewpicture']    = ""#Item.get_thumb( entry )
                item['image2retrieve']    = False # Temporary patch for reseting the flag after downlaad (would be better in the thread in charge of the download)
                
                item['orginalfilename']     = entry['orginalfilename']
                #TODO: deprecated??? Check server side
                item['fileexternurl']     = "None"
                self._setDefaultImages( item )
                list.append(item)
                print item
            else:
                print "Type not supported by the installer:"
                print entry
            
        return list