-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-structured code and Fixed Login Issue
Re-structured code and Fixed Login Issue.
- Loading branch information
Showing
25 changed files
with
809 additions
and
951 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
import common | ||
import external | ||
import sites | ||
import external | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import browser_instance | ||
import downloader | ||
import misc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from cfscrape import create_scraper | ||
from requests import session | ||
from bs4 import BeautifulSoup | ||
import re | ||
|
||
|
||
def page_downloader(url, scrapper_delay=5, **kwargs): | ||
headers = kwargs.get("headers") | ||
if not headers: | ||
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', | ||
'Accept-Encoding': 'gzip, deflate' | ||
} | ||
|
||
sess = session() | ||
sess = create_scraper(sess, delay=scrapper_delay) | ||
|
||
connection = sess.get(url, headers=headers, cookies=kwargs.get("cookies")) | ||
|
||
if connection.status_code != 200: | ||
print("Whoops! Seems like I can't connect to website.") | ||
print("It's showing : %s" % connection) | ||
print("Run this script with the --verbose argument and report the issue along with log file on Github.") | ||
# raise Warning("can't connect to website %s" % manga_url) | ||
return False, None, None | ||
else: | ||
page_source = BeautifulSoup(connection.text.encode("utf-8"), "html.parser") | ||
connection_cookies = sess.cookies | ||
|
||
return True, page_source, connection_cookies | ||
|
||
|
||
def login_crunchyroll(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' | ||
} | ||
|
||
sess = session() | ||
sess = create_scraper(sess) | ||
print("Trying to login...") | ||
|
||
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") | ||
initial_cookies = sess.cookies | ||
csrf_token = re.search(r'login_form\[\_token\]\"\ value\=\"(.*?)\"', | ||
str(initial_page_source)).group(1) | ||
|
||
payload = { | ||
'login_form[name]': '%s' % username, | ||
'login_form[password]': '%s' % password, | ||
'login_form[redirect_url]': '/', | ||
'login_form[_token]': '%s' % csrf_token | ||
} | ||
|
||
login_post = sess.post( | ||
url='https://www.crunchyroll.com/' + country + 'login', | ||
data=payload, | ||
headers=headers, | ||
cookies=initial_cookies) | ||
|
||
login_check_response, login_cookies = login_check(html_source=login_post.text.encode('utf-8'), cookies=login_post.cookies) | ||
if login_check_response: | ||
print("Logged in successfully...") | ||
return True, login_cookies, csrf_token | ||
else: | ||
print("Unable to Log you in. Check credentials again.") | ||
return False, None, None | ||
else: | ||
# print("Couldn't connect to the login page...") | ||
# print("Website returned : %s" % str(initial_page_fetch.status_code)) | ||
return False, None, None | ||
|
||
|
||
def login_check(html_source, cookies=None): | ||
# Open the page and check the title. CrunchyRoll redirects the user and the title has the text "Redirecting...". | ||
# If this is not found, you're probably not logged in and you'll just get 360p or 480p. | ||
if "href=\"/logout\"" in html_source: | ||
return True, cookies | ||
else: | ||
print("Let me check again...") | ||
second_try_response, html_source, cookies = page_downloader(url="https://www.crunchyroll.com/", cookies=cookies) | ||
if second_try_response: | ||
if "href=\"/logout\"" in html_source: | ||
return True, cookies | ||
else: | ||
return False, cookies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
|
||
def duplicate_remover(seq): | ||
# https://stackoverflow.com/a/480227 | ||
seen = set() | ||
seen_add = seen.add | ||
return [x for x in seq if not (x in seen or seen_add(x))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import external.aes | ||
import external.compat | ||
import external.socks | ||
import external.utils | ||
import aes | ||
import compat | ||
import socks | ||
import utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
import sites.crunchyroll | ||
import sites.funimation | ||
import sites.vrv | ||
import crunchyroll |
Oops, something went wrong.