Fixes #11572 Use cfscrape to avoid Crunchyroll error 503

This commit is contained in:
kidburglar 2017-01-15 17:00:29 +01:00
parent dcae7b3fdc
commit 72cb991f90

View File

@ -5,6 +5,7 @@ import re
import json
import base64
import zlib
import cfscrape
from hashlib import sha1
from math import pow, sqrt, floor
@ -43,6 +44,12 @@ class CrunchyrollBaseIE(InfoExtractor):
if username is None:
return
# Scrape cookie from cloudfront and insert them
scraper = cfscrape.create_scraper()
tokens = scraper.get_tokens(self._LOGIN_URL, 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20150101 Firefox/47.0 (Chrome)')
self._set_crunchyroll_cookie('cf_clearance', tokens[0]['cf_clearance'])
self._set_crunchyroll_cookie('__cfduid', tokens[0]['__cfduid'])
login_page = self._download_webpage(
self._LOGIN_URL, None, 'Downloading login page')
@ -103,6 +110,9 @@ class CrunchyrollBaseIE(InfoExtractor):
request.add_header('Accept-Language', '*')
return super(CrunchyrollBaseIE, self)._download_webpage(request, *args, **kwargs)
def _set_crunchyroll_cookie(self, name, value):
self._set_cookie('crunchyroll.com', name, value)
@staticmethod
def _add_skip_wall(url):
parsed_url = compat_urlparse.urlparse(url)