Add fastani (#500)

* fastani

* Add fastani to readme

* PEP fixes
master
AbdullahM0hamed 2020-09-16 14:42:56 +01:00 committed by GitHub
parent ee0dec0f0a
commit 80ac3fcca3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 1 deletions

View File

@ -70,7 +70,8 @@ Yeah. Me too! That's why this tool exists.
- Animixplay
- Anistream
- Darkanime
- Dbanimes
- Dbanimes
- FastAni
- Gogoanime
- GurminderBoparai (AnimeChameleon)
- HorribleSubs

View File

@ -0,0 +1,80 @@
from anime_downloader.sites.anime import Anime, AnimeEpisode, SearchResult
from anime_downloader.sites import helpers
import re
import logging
logger = logging.getLogger(__name__)
class FastAni(Anime, sitename="fastani"):
sitename = 'fastani'
@classmethod
def getToken(cls):
site_text = helpers.get("https://fastani.net").text
# 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)
js = helpers.get(js_location).text
# Get authorization token, e.g: {authorization:"Bearer h8X2exbErErNSxRnr6sSXAE2ycUSyrbU"}
token = re.search("authorization:.*?\"(.*?)\"", js).group(1)
return {"authorization": token}
@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()
return [
SearchResult(
title=x.get('title').get("english"),
# Need to know selected anime and original query for _scrape_episodes
url=f"https://fastani.net/{selected}/{query}"
)
for selected, x in zip(range(len(results["animeData"]["cards"])), results["animeData"]["cards"])
]
def _scrape_episodes(self):
cls = type(self)
headers = cls.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()
cdnData = anime["animeData"]["cards"][selected]["cdnData"]
# Get all episodes from all seasons of the anime
# JSON Example:
"""
{
'seasons': [{
'episodes': [{
'file': 'https://private.fastani.net/Naruto/Season 1/Naruto S01E001.mp4',
'directory': 'https://private.fastani.net/Naruto/Season 1',
'timestamp': '2020-09-11T16:22:48.744Z',
'thumb': 'https://private.fastani.net/Naruto/Season 1/thumbs/20_thumbnail_001.jpg',
'title': 'Enter: Naruto Uzumaki!'
}
...
]
}
"""
episodes = [j["file"] for i in [x["episodes"] for x in cdnData["seasons"]] for j in i]
return episodes
def _scrape_metadata(self):
cls = type(self)
headers = cls.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()
self.title = anime["animeData"]["cards"][selected]["title"]["english"]
class FastAniEpisode(AnimeEpisode, sitename='fastani'):
def _get_sources(self):
return [("no_extractor", self.url)]

View File

@ -22,6 +22,7 @@ ALL_ANIME_SITES = [
('darkanime', 'darkanime', 'DarkAnime'),
('dbanimes', 'dbanimes', 'DBAnimes'),
# ('erairaws', 'erai-raws', 'EraiRaws'),
('fastani', 'fastani', 'FastAni'),
('gogoanime', 'gogoanime', 'GogoAnime'),
('horriblesubs', 'horriblesubs', 'HorribleSubs'),
('itsaturday', 'itsaturday', 'Itsaturday'),