-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathapi.py
43 lines (33 loc) · 1.01 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import requests
import base64
import time
import json
class YacineTV:
api_url = "http://ver3.yacinelive.com"
key = "c!xZj+N9&G@Ev@vw"
def __init__(self):
pass
def decrypt(self, enc, key=key):
enc = base64.b64decode(enc.encode("ascii")).decode("ascii")
result = ""
for i in range(len(enc)):
result = result + chr(ord(enc[i]) ^ ord(key[i % len(key)]))
return result
def req(self, path):
r = requests.get(self.api_url + path)
timestamp = str(int(time.time()))
if "t" in r.headers:
timestamp = r.headers["t"]
try:
return json.loads(self.decrypt(r.text, key=self.key + timestamp))
except Exception:
return {
"success": False,
"error": "can't parse json."
}
def get_categories(self):
return self.req("/api/categories")
def get_category_channels(self, category_id):
return self.req(f"/api/categories/{str(category_id)}/channels")
def get_channel(self, channel_id):
return self.req(f"/api/channel/{str(channel_id)}")