forked from byte-capsule/Toffee-Channels-Link-Headers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
99 lines (83 loc) · 3.83 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import base64,requests,urllib,json,os
from urllib.parse import urlparse,urljoin
def data_decrypt(key, ciphertext):
cipher = AES.new(key, AES.MODE_ECB)
ciphertext = base64.b64decode(ciphertext)
padded_plaintext = cipher.decrypt(ciphertext)
plaintext = unpad(padded_plaintext, AES.block_size)
return plaintext.decode()
def update_time():
from datetime import datetime, timedelta
import time
import pytz
IST = pytz.timezone('Asia/Dhaka')
today_date = datetime.now(IST).strftime("%d-%m-%Y") #Current Date
curr_time = datetime.now(IST).strftime("%H:%M:%S") #Current time
#input(type(datetime.now(IST).strftime("%H")))
if int(datetime.now(IST).strftime("%H"))>=5 and int(datetime.now(IST).strftime("%H"))<18:
emoji="🌞"
else:
emoji="🌙"
if datetime.now(IST).strftime("%H")<"12":
curr_time=curr_time+" AM "+emoji
else:
curr_hour=int(datetime.now(IST).strftime("%H"))-12
curr_min=datetime.now(IST).strftime("%M")
curr_sec=datetime.now(IST).strftime("%S")
curr_time=str(curr_hour)+":"+curr_min+":"+curr_sec
curr_time=curr_time+" PM "+emoji
return curr_time,today_date
def load_channel():
headers={
"Host": "mapi.toffeelive.com",
"user-agent": "Toffee/5.1.1 (Linux;Android 7.1.2) AndroidXMedia3/1.1.1/64103898/4d2ec9b8c7534adc",
"client-api-header":"angM1aXCHQLmmSW6cDlpXMD6tLdwnhMoUeaBBFKmd98bX6Vrae5xCMbm4gg0+u33rnxeGQDZNr2GD1tW0cWwKEpWimNlGqXVQGhpiIBz1JFxN+OxXcQqaMPrjwUhCyI5mO1DGyNv18+Z2EpmHtVnLzV9SrGsQWu4oRKjxE8QIMsRs6LrvL6hWGPlOGQke/qb5QxQZNetPzI39jHhX7Zi2XrCMIT4a+gk2Wu1c3wIybwkqknPcTp4Bj1cEF3Q+q1dV05SBhzpEDfoR2BLyQ6dV3LvmY6MNKxbUjby7hMsg35lFl2Df2mZsr7C27309w/qWi8lLXDjB7B1MozIGKn8rw3bXY5YlrPKBKztyiisAjQQi7kc5ISXyGSwRmhciwkciuitsSL0LlqHY7/Qkkh71EtaK3XEgVpLdH8zRCsTwfu1iIVPiDwTycuuBy4XWkcNnd0iLB35yftQpiL8HfpO2jQnrAwzePxszJ7mewVG+M0P/qyTBD52NkPR8uW0AZmDKp5LHTCGf7sqldDzpZvU+gsSdvtsBUcmHzjINGEoyXk=",
"accept-encoding":"gzip"
}
req=requests.get(url=toffee_api,headers=headers, verify=False)
categories=json.loads(data_decrypt(secret_key,req.text))["response"]["categories"]
all_data=[]
for category in categories:
category_name=category["category_name"]
for channel in category["channels"]:
link=channel["plain_hls_url_for_url_type"]
program_name=channel["program_name"]+" VIP"
if link=="":
program_name=channel["program_name"]
link=channel["plain_hls_url"]
if link.endswith("u8")==False:
link=channel["plain_hls_url"]
if link.endswith("u8")==False:
link=channel["hlsLinks"][0]["hls_url_mobile"]
if link.endswith("u8")==False:
link="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4"
data={
"category_name":category_name,
"name":program_name,
"link":link,
#"link":channel["hlsLinks"][0]["hls_url_mobile"], premium tv not working
"headers":{
"Host":urlparse(link).netloc,
#"Host":urlparse(channel["hlsLinks"][0]["hls_url_mobile"]).netloc,
"cookie":channel.get("sign_cookie")
},
"logo":channel["channel_logo"]
}
all_data.append(data)
return all_data
toffee_api=os.environ["TOFFEE_API"]
secret_key=os.environ["TOFFEE_KEY"].encode()
date_time_info=update_time()
date_time=date_time_info[1]+" on "+date_time_info[0]
data_channels=load_channel()
data={
"name":"Toffee App All Channel Link with Headers",
"owner":"Byte Capsule \nTelegram: https://t.me/J_9X_H_9X_N",
"channels_amount":len(data_channels),
"updated_on":date_time,
"channels":data_channels
}
with open("toffee_channel_data.m3u8","w") as w:
json.dump(data,w,indent=2)