Update script and add some new features

- Replace get with info
- Added storyboards
- Added download (STILL NOT WORKING)
This commit is contained in:
Moe Poi ~ 2019-07-04 23:56:24 +07:00
parent 34e654d3ae
commit 6fb05b4adf

View file

@ -13,7 +13,7 @@ License MIT
class HanimeTV:
def __init__(self, email=None, password=None):
self.host = "https://hanime.tv"
self.host = "https://members.hanime.tv"
if email is None and password is None:
self.session = ''
else:
@ -24,10 +24,25 @@ class HanimeTV:
print ("Invalid Credential")
sys.exit()
def login(self, email, password):
url = "{}/api/v3/sessions".format(self.host)
def pre_session(captcha_token):
url = self.host + "/api/v1/pre-session"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
}
data = {
"captcha_token": captcha_token
}
req = requests.post(url, headers=headers, json=data)
return json.loads(req.text)
def login(self, email, password):
url = self.host + "/api/v3/sessions"
captcha_token = "???" # NEED CAPTCHA TOKEN
pre_session = self.pre_session(captcha_token)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
'Referer': '{}/'.format(self.host),
@ -38,82 +53,42 @@ class HanimeTV:
}
data = {
"email": str(email),
"password": str(password)
"password": str(password),
"now": pre_session["now"],
"sign_in_token": pre_session["sign_in_token"]
}
req = requests.post(url, headers=headers, json=data)
return json.loads(req.text)
def search(self, query):
url = "https://thorin-us-east-1.searchly.com/hentai_videos/hentai_video/_search?from=0&size=48"
token = "cHVibGljOmlscXd3a2s3Znpxb3Bzand3MXVkcm1yZHQwdDlnb2Mz"
url = "https://search.hanime.tv/"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0',
'Accept': '*/*',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
'Referer': '{}/search?q={}'.format(self.host, str(query)),
'Authorization': 'Basic {}'.format(str(token)),
'content-type': 'application/json',
'Origin': self.host,
'Connection': 'keep-alive',
'TE': 'Trailers'
}
data = {
"query": {
"bool": {
"filter": {
"bool": {
"minimum_should_match": 0,
"must": [
{
"bool": {
"must": []
}
}
],
"must_not": None,
"should": []
}
},
"minimum_should_match": 1,
"should": [
{
"wildcard": {
"name": {
"boost": 10,
"wildcard": "*{}*".format(str(query))
}
}
},
{
"match": {
"titles": "{}".format(str(query))
}
},
{
"wildcard": {
"tags_string": "{}*".format(str(query))
}
}
]
}
},
"sort": [
"_score",
{
"created_at_unix": {
"order": "desc"
}
}
]
"search_text": str(query),
"tags": [],
"tags_mode": "OR",
"brands": [],
"blacklist": [],
"order_by": "created_at_unix",
"ordering": "desc",
"page": 0
}
req = requests.post(url, headers=headers, json=data)
return json.loads(req.text)
def get(self, url):
query = url.replace("https://hanime.tv/hentai-videos/","")
url = "https://hanime.tv/api/v5/videos_manifests/" + query
def info(self, url):
query = url.split("/")[4]
url = self.host + "/api/v5/hentai-videos/" + query
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
'Referer': '{}/hentai-videos/{}'.format(self.host, query),
@ -124,3 +99,36 @@ class HanimeTV:
}
req = requests.get(url, headers=headers)
return json.loads(req.text)
def storyboards(self, url):
hid = self.info(url)["hentai_video"]["id"]
url = self.host + "/api/v1/hentai_video_storyboards?hv_id={}".format(str(hid))
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
'X-Session-Token': self.session,
'Connection': 'keep-alive',
'TE': 'Trailers'
}
req = requests.get(url, headers=headers)
return json.loads(req.text)
def download(self, url):
url = self.host + "/api/v1/downloads/" + url.split("/")[4]
captcha_token = "???" # NEED CAPTCHA TOKEN
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0',
'Accept': 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.5',
'X-Directive': 'api',
'X-Session-Token': self.session,
'Connection': 'keep-alive',
'TE': 'Trailers'
}
data = {
"auth_kind": "recaptcha",
"auth": captcha_token
}
req = requests.post(url, headers=headers, json=data)
return json.loads(req.text)