Comment 4 for bug 1458759

Revision history for this message
PheniX (a-sterbini) wrote :

I hadn't time to pursue the cookielib road and managed the following (too) simple hack in Util.py:

    @staticmethod
    def urlopen(url, data=None, head_request=False):
        if url.startswith('//'):
            url = 'http:' + url
        request = urllib2.Request(url) if not head_request else HeadRequest(url)
        request.add_header('User-Agent', USER_AGENT)
        request.add_header('Cache-Control', 'max-age=0')

        # session cookies for wallhaven
        cookiefile = '~/.config/variety/cookies/cookies.txt'
        if url.find('wallhaven')>0 and os.path.exists(cookiefile):
            cookies = ''
            with open(cookiefile) as CF:
                for line in CF:
                    _, _, _, _, name, value = line.strip().split('\t')
                    cookies += "%s=%s;" % (name,value)
            request.add_header('Cookie', cookies )

        return urllib2.urlopen(request, data=urllib.urlencode(data) if data else None, timeout=20)

Once Util.py is "fixed" as above, to enable session cookies for wallhaven you just log-on with Firefox to wallhaven and save the session cookies to ~/.config/variety/cookies/cookies.txt by using the Firebug extension