예제 #1
0
 def getdata(_from):
     if _from == 'content':
         if content[0] == -1:
             if response.headers and isinstance(response.headers,
                                                HTTPHeaders):
                 content[0] = utils.decode(response.body,
                                           headers=response.headers)
             else:
                 content[0] = utils.decode(response.body)
         if ('content-type' in response.headers):
             if 'image' in response.headers.get('content-type'):
                 return base64.b64encode(response.body).decode('utf8')
         return content[0]
     elif _from == 'status':
         return '%s' % response.code
     elif _from.startswith('header-'):
         _from = _from[7:]
         return response.headers.get(_from, '')
     elif _from == 'header':
         try:
             return str(response.headers._dict).replace('\'', '')
         except Exception as e:
             traceback.print_exc()
         try:
             return json.dumps(response.headers._dict)
         except Exception as e:
             traceback.print_exc()
     else:
         return ''
예제 #2
0
파일: fetcher.py 프로젝트: ysice/qiandao
        def build_response(response):
            cookies = cookie_utils.CookieSession()
            cookies.extract_cookies_to_jar(response.request, response)

            encoding = utils.find_encoding(response.body, response.headers)
            if not response.headers.get('content-type'):
                response.headers['content-type'] = 'text/plain'
            if 'charset=' not in response.headers.get('content-type', ''):
                response.headers['content-type'] += '; charset='+encoding

            return dict(
                    status = response.code,
                    statusText = response.reason,
                    headers = build_headers(response.headers),
                    cookies = cookies.to_json(),
                    content = dict(
                        size = len(response.body),
                        mimeType = response.headers.get('content-type'),
                        text = base64.b64encode(response.body),
                        decoded = utils.decode(response.body, response.headers),
                        ),
                    redirectURL = response.headers.get('Location'),
                    headersSize = -1,
                    bodySize = -1,
                    )
예제 #3
0
        def build_response(response):
            cookies = cookie_utils.CookieSession()
            cookies.extract_cookies_to_jar(response.request, response)

            encoding = utils.find_encoding(response.body, response.headers)
            if not response.headers.get('content-type'):
                response.headers['content-type'] = 'text/plain'
            if 'charset=' not in response.headers.get('content-type', ''):
                response.headers['content-type'] += '; charset='+encoding

            return dict(
                    status = response.code,
                    statusText = response.reason,
                    headers = build_headers(response.headers),
                    cookies = cookies.to_json(),
                    content = dict(
                        size = len(response.body),
                        mimeType = response.headers.get('content-type'),
                        text = base64.b64encode(response.body),
                        decoded = utils.decode(response.body, response.headers),
                        ),
                    redirectURL = response.headers.get('Location'),
                    headersSize = -1,
                    bodySize = -1,
                    )
예제 #4
0
 def getdata(_from):
     if _from == 'content':
         if content[0] == -1:
             content[0] = utils.decode(response.body)
         return content[0]
     elif _from == 'status':
         return '%s' % response.code
     elif _from.startswith('header-'):
         _from = _from[7:]
         return response.headers.get(_from, '')
     else:
         return ''
예제 #5
0
 def getdata(_from):
     if _from == 'content':
         if content[0] == -1:
             content[0] = utils.decode(response.body)
         if 'image' in response.headers.get('content-type'):
             return base64.b64encode(response.body)
         return content[0]
     elif _from == 'status':
         return '%s' % response.code
     elif _from.startswith('header-'):
         _from = _from[7:]
         return response.headers.get(_from, '')
     elif _from == 'header':
         return unicode(response.headers)
     else:
         return ''
예제 #6
0
파일: fetcher.py 프로젝트: touya922/qiandao
        def build_response(response):
            cookies = cookie_utils.CookieSession()
            cookies.extract_cookies_to_jar(response.request, response)

            return dict(
                status=response.code,
                statusText=response.reason,
                headers=build_headers(response.headers),
                cookies=cookies.to_json(),
                content=dict(
                    size=len(response.body),
                    mimeType=response.headers.get('content-type'),
                    text=base64.b64encode(response.body),
                    decoded=utils.decode(response.body, response.headers),
                ),
                redirectURL=response.headers.get('Location'),
                headersSize=-1,
                bodySize=-1,
            )
예제 #7
0
        def build_response(response):
            cookies = cookie_utils.CookieSession()
            cookies.extract_cookies_to_jar(response.request, response)

            return dict(
                    status = response.code,
                    statusText = response.reason,
                    headers = build_headers(response.headers),
                    cookies = cookies.to_json(),
                    content = dict(
                        size = len(response.body),
                        mimeType = response.headers.get('content-type'),
                        text = base64.b64encode(response.body),
                        decoded = utils.decode(response.body, response.headers),
                        ),
                    redirectURL = response.headers.get('Location'),
                    headersSize = -1,
                    bodySize = -1,
                    )
예제 #8
0
def list_favourites(label, others=0):
    xbmcplugin.setPluginCategory(_handle, label)
    favourites = get_favourites(int(others))
    favourites_ordered = {}

    for key in favourites:
        favourites_ordered.update({key: favourites[key]["title"]})
    for showId in sorted(favourites_ordered, key=favourites_ordered.get):
        show = favourites[showId]
        if addon.getSetting(
                "hide_unlistened_favourites") == "false" and others == 0:
            unlistened = get_unlistened_count(showId)
            if unlistened > 0:
                list_item = xbmcgui.ListItem(label=show["title"] + " (" +
                                             str(unlistened) +
                                             decode(" nových)"))
            elif unlistened == 0:
                list_item = xbmcgui.ListItem(label=show["title"])
            else:
                list_item = xbmcgui.ListItem(label=show["title"] +
                                             ' (nenalezený pořad)')
        else:
            list_item = xbmcgui.ListItem(label=show["title"])
        list_item.setArt({"thumb": show["img"], "icon": show["img"]})
        list_item.setInfo(
            "video", {
                "title": show["title"],
                "director": [show["director"]],
                "plot": show["description"],
                "studio": show["station"]
            })
        if len(show["cast"]) > 0:
            list_item.setInfo("video", {"cast": show["cast"]})

        menus = [(
            "Odstranit z oblíbených",
            "RunPlugin(plugin://plugin.audio.cro?action=delete_favourites&showId="
            + str(show["id"]) + ")")]
        if others == 0:
            menus.append((
                "Přesunout do ostatních",
                "RunPlugin(plugin://plugin.audio.cro?action=set_others&showId="
                + str(show["id"]) + "&val=1" + ")"))
        else:
            menus.append((
                "Přesunout z ostatních",
                "RunPlugin(plugin://plugin.audio.cro?action=set_others&showId="
                + str(show["id"]) + "&val=0" + ")"))
        if addon.getSetting(
                "hide_unlistened_favourites") == "false" and others == 0:
            menus.append((
                "Označit epizody jako poslechnuté",
                "RunPlugin(plugin://plugin.audio.cro?action=set_listened_all&showId="
                + str(show["id"]) + ")"))
        list_item.addContextMenuItems(menus)
        if addon.getSetting(
                "hide_unlistened_favourites") == "false" and others == 0:
            url = get_url(action='list_show',
                          showId=show["id"],
                          page=1,
                          label=encode(show["title"]),
                          mark_new=1)
        else:
            url = get_url(action='list_show',
                          showId=show["id"],
                          page=1,
                          label=encode(show["title"]),
                          mark_new=0)
        list_item.setContentLookup(False)
        xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)