def list_folders(url, query=None, result=None):
    try:
        list = []
        items = []
        headers = {
            'Accept': '*/*',
            'Accept-Encoding': 'gzip,deflate',
            'Connection': 'keep-alive',
            'X-Requested-With': 'XMLHttpRequest'
        }
        if result == None:
            result = requester.request(url, headers=urllib.urlencode(headers))
        result = result.decode('iso-8859-1').encode('utf-8')
        result = requester.parseDOM(
            result,
            'div',
            attrs={'class': 'collections_list responsive_width'})[0]
        items = requester.parseDOM(result, 'li')
        for indiv in items:
            if re.search('name', indiv):
                name = requester.replaceHTMLCodes(
                    requester.parseDOM(indiv, 'a',
                                       attrs={'class':
                                              'name'})[0].encode('utf-8'))
                length = re.compile('(\d+)').findall(
                    requester.parseDOM(indiv, 'p',
                                       attrs={'class':
                                              'info'})[0].encode('utf-8'))[0]
                pageurl = SiteURL + requester.parseDOM(
                    indiv, 'a', attrs={'class': 'name'}, ret='href')[0]
                thumb = requester.parseDOM(indiv, 'img', ret='src')[0].replace(
                    '/thumbnail', '')
            list.append({
                'type': 'folder',
                'name': name,
                'length': length,
                'thumb': thumb,
                'pageurl': pageurl
            })
        list = sorted(
            list, key=lambda k: re.sub('(^the |^a )', '', k['name'].lower()))
        return list
    except:
        return []
Beispiel #2
0
def list_items(url, query=None, result=None, content_type=None):
    list = []
    try:
        if result == None:
            headers = {
                'Accept': '*/*',
                'Accept-Encoding': 'gzip,deflate',
                'Connection': 'keep-alive',
                'X-Requested-With': 'XMLHttpRequest'
            }
            if query:
                post = {
                    'Mode': 'List',
                    'Type': content_type,
                    'Phrase': query,
                    'SizeFrom': '0',
                    'SizeTo': '0',
                    'Extension': '',
                    'ref': 'pager',
                    'pageNumber': '1'
                }
                result = requester.request(url,
                                           post=urllib.urlencode(post),
                                           headers=urllib.urlencode(headers))
            else:
                result = requester.request(url,
                                           headers=urllib.urlencode(headers))
    except:
        pass

    result = result.decode('iso-8859-1').encode('utf-8')
    items = requester.parseDOM(result, 'div', attrs={'class': 'list_row'})
    try:
        thumb = requester.parseDOM(result,
                                   'meta',
                                   ret='content',
                                   attrs={'property': 'og:image'})[0]
    except:
        thumb = None

    for indiv in items:
        name = requester.replaceHTMLCodes(
            requester.parseDOM(
                requester.parseDOM(indiv, 'div', attrs={'class': 'name'}),
                'a')[0].encode('utf-8'))
        size = requester.parseDOM(
            requester.parseDOM(indiv, 'div', attrs={'class': 'size'}),
            'p')[0].encode('utf-8')
        pageurl = CopiaPopURL + requester.parseDOM(requester.parseDOM(
            indiv, 'div', attrs={'class': 'name'}),
                                                   'a',
                                                   ret='href')[0]

        temp = requester.parseDOM(
            requester.parseDOM(indiv, 'div', attrs={'class': 'date'})[0],
            'div')[0]

        fileid = requester.parseDOM(temp,
                                    'input',
                                    ret='value',
                                    attrs={'name': 'fileId'})[0]

        list.append({
            'type': 'content',
            'name': name,
            'size': size,
            'fileid': fileid,
            'thumb': thumb,
            'pageurl': pageurl
        })
    return list