Skip to content

Commit

Permalink
Fix Fastani (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullahM0hamed committed Oct 14, 2020
1 parent 84c9d9e commit 021785e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions anime_downloader/sites/fastani.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class FastAni(Anime, sitename="fastani"):

@classmethod
def getToken(cls):
site_text = helpers.get("https://fastani.net").text
resp = helpers.get("https://fastani.net")
site_text = resp.text
cookies = resp.cookies

# Path to js file, e.g /static/js/main.f450dd1c.chunk.js - which contains the token
js_location = "https://fastani.net" + re.search(r"src=\"(\/static\/js\/main.*?)\"", site_text).group(1)
Expand All @@ -21,12 +23,12 @@ def getToken(cls):
# Get authorization token, e.g: {authorization:"Bearer h8X2exbErErNSxRnr6sSXAE2ycUSyrbU"}
key, token = re.search("method:\"GET\".*?\"(.*?)\".*?\"(.*?)\"", js).group(1,2)

return {key: token}
return ({key: token}, cookies)

@classmethod
def search(cls, query):
headers = cls.getToken()
results = helpers.get(f"https://fastani.net/api/data?page=1&search={query}&tags=&years=", headers=headers).json()
headers, cookies = cls.getToken()
results = helpers.get(f"https://fastani.net/api/data?page=1&search={query}&tags=&years=", headers=headers, cookies=cookies).json()

return [
SearchResult(
Expand All @@ -38,11 +40,10 @@ def search(cls, query):
]

def _scrape_episodes(self):
cls = type(self)
headers = cls.getToken()
headers, cookies = self.getToken()
split = self.url.split("/")
query, selected = split[-1], int(split[-2])
anime = helpers.get(f"https://fastani.net/api/data?page=1&search={query}&tags=&years=", headers=headers).json()
anime = helpers.get(f"https://fastani.net/api/data?page=1&search={query}&tags=&years=", headers=headers, cookies=cookies).json()

cdnData = anime["animeData"]["cards"][selected]["cdnData"]

Expand All @@ -67,11 +68,10 @@ def _scrape_episodes(self):
return episodes

def _scrape_metadata(self):
cls = type(self)
headers = cls.getToken()
headers, cookies = self.getToken()
split = self.url.split("/")
query, selected = split[-1], int(split[-2])
anime = helpers.get(f"https://fastani.net/api/data?page=1&search={query}&tags=&years=", headers=headers).json()
anime = helpers.get(f"https://fastani.net/api/data?page=1&search={query}&tags=&years=", headers=headers, cookies=cookies).json()
self.title = anime["animeData"]["cards"][selected]["title"]["english"]


Expand Down

0 comments on commit 021785e

Please sign in to comment.