Skip to content

Commit

Permalink
Merge pull request #78 from DarkSupremo/master
Browse files Browse the repository at this point in the history
Fix for crunchyroll issue #77 - Could not extract the language from the URL
  • Loading branch information
Xonshiz authored Feb 23, 2019
2 parents 3c13f25 + 3d4362a commit 1766c1a
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions anime_dl/sites/crunchyroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ def __init__(self, url, password, username, resolution, language, skipper, logge
encoding="utf-8")

# Extract the language from the input URL
Crunchy_Language = re.search(r'.+/([a-z]{2})/.+', url)
Crunchy_Language = re.search(r'.+\/([a-z]{2}|[a-z]{2}-[a-z]{2})\/.+', url)
if not Crunchy_Language:
print("Could not extract the language from the URL")
return

Crunchy_Language = Crunchy_Language.group(1)
Crunchy_Language = "/"
else:
Crunchy_Language = Crunchy_Language.group(1) + "/"


Crunchy_Show_regex = r'https?://(?:(?P<prefix>www|m)\.)?(?P<url>crunchyroll\.com/[a-z]{2}/(?!(?:news|anime-news|library|forum|launchcalendar|lineup|store|comics|freetrial|login))(?P<id>[\w\-]+))/?(?:\?|$)'
Crunchy_Video_regex = r'https?:\/\/(?:(?P<prefix>www|m)\.)?(?P<url>crunchyroll\.(?:com|fr)/[a-z]{2}/(?:media(?:-|/\?id=)|[^/]*/[^/?&]*?)(?P<video_id>[0-9]+))(?:[/?&]|$)'
Crunchy_Show_regex = r'https?:\/\/(?:(?P<prefix>www|m)\.)?(?P<url>crunchyroll\.com(\/[a-z]{2}|\/[a-z]{2}-[a-z]{2})?\/(?!(?:news|anime-news|library|forum|launchcalendar|lineup|store|comics|freetrial|login))(?P<id>[\w\-]+))\/?(?:\?|$)'
Crunchy_Video_regex = r'https?:\/\/(?:(?P<prefix>www|m)\.)?(?P<url>crunchyroll\.(?:com|fr)(\/[a-z]{2}|\/[a-z]{2}-[a-z]{2})?\/(?:media(?:-|\/\?id=)|[^\/]*\/[^\/?&]*?)(?P<video_id>[0-9]+))(?:[\/?&]|$)'

Crunchy_Show = re.match(Crunchy_Show_regex, url)
Crunchy_Video = re.match(Crunchy_Video_regex, url)
Expand Down Expand Up @@ -80,20 +79,20 @@ def login_check(self, htmlsource):
# return False
return True

def webpagedownloader(self, url, username, password, country='fr'):
def webpagedownloader(self, url, username, password, country):

headers = {
'User-Agent':
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'Referer':
'https://www.crunchyroll.com/' + country + '/login'
'https://www.crunchyroll.com/' + country + 'login'
}

sess = requests.session()
sess = cfscrape.create_scraper(sess)
print("Trying to login...")

initial_page_fetch = sess.get(url='https://www.crunchyroll.com/' + country + '/login', headers=headers)
initial_page_fetch = sess.get(url='https://www.crunchyroll.com/' + country + 'login', headers=headers)

if initial_page_fetch.status_code == 200:
initial_page_source = initial_page_fetch.text.encode("utf-8")
Expand All @@ -109,7 +108,7 @@ def webpagedownloader(self, url, username, password, country='fr'):
}

login_post = sess.post(
url='https://www.crunchyroll.com/' + country + '/login',
url='https://www.crunchyroll.com/' + country + 'login',
data=payload,
headers=headers,
cookies=initial_cookies)
Expand Down

0 comments on commit 1766c1a

Please sign in to comment.