-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_hotstar.com_.py
286 lines (245 loc) · 9.27 KB
/
_hotstar.com_.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
from bs4 import BeautifulSoup as bs
import subprocess
import requests
import hashlib
import hmac
import uuid
import json
import time
import sys
AUTO_MODE = True
#Stolen from YTDL
AKAMAI_ENCRYPTION_KEY = None
if not AKAMAI_ENCRYPTION_KEY:
print("No encryption key, can't proceed")
sys.exit(0)
def bruh():
st = int(time.time())
exp = st + 6000
auth = f'st={st}~exp={exp}~acl=/*'
auth += '~hmac=' + hmac.new(AKAMAI_ENCRYPTION_KEY, auth.encode(), hashlib.sha256).hexdigest()
return(auth)
def kek():
st = int(time.time())
exp = st + 6000
auth = f'st={st}~exp={exp}~acl=/um/v3/*'
auth += '~hmac=' + hmac.new(AKAMAI_ENCRYPTION_KEY, auth.encode(), hashlib.sha256).hexdigest()
return(auth)
#End of stolen code
hotstar = requests.Session()
ID = input("Enter ID: ")
#USERTOKEN
USERTOKEN_HEADERS = {
"hotstarauth": kek(),
"x-hs-platform": "web",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36",
"origin": "https://www.hotstar.com",
"referer": "https://www.hotstar.com/"
}
USERTOKEN_PAYLOAD = {
"device_ids": [
{
"id": str(uuid.uuid4()),
"type": "device_id"
}
],
"device_meta": {
"network_operator": "4g - 5.5 - 150",
"os_name": "Windows",
"os_version": "10"
}
}
users_resp = hotstar.post('https://api.hotstar.com/um/v3/users', headers= USERTOKEN_HEADERS, json=USERTOKEN_PAYLOAD).json()
print(json.dumps(users_resp, indent=4))
#API
API_URL = f"https://api.hotstar.com/play/v2/playback/content/{ID}"
API_HEADERS = {
"origin": "https://www.hotstar.com",
"referer": "https://www.hotstar.com/",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36",
"hotstarauth": bruh(),
"x-hs-appversion": "7.26.0",
"x-hs-platform": "web",
"x-hs-usertoken": users_resp["user_identity"]
}
API_QUERY = {
"device-id": uuid.uuid4(),
"desired-config": "audio_channel:stereo|dynamic_range:sdr|encryption:widevine|ladder:tv|package:dash|resolution:hd|video_codec:h264",
"os-name": "Windows",
"os-version": "10"
}
api_resp = hotstar.get(API_URL, headers=API_HEADERS, params=API_QUERY).json()
print(json.dumps(api_resp, indent=4))
#MPD
MPD_HEADERS = {
"origin": "https://www.hotstar.com",
"referer": "https://www.hotstar.com/",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36"
}
mpd_name = "master-tv.mpd"
m3u8_name = "master.m3u8"
mpd_url = None
m3u8_url = None
if AUTO_MODE:
mpd_name = "master-tv.mpd"
m3u8_name = "master.m3u8"
tags = "encryption:plain"
else:
mpd_name = input("MPD Name: ")
m3u8_name = input("M3U8 Name: ")
tags = input("Tag Combination: ")
for i in api_resp["data"]["playBackSets"]:
if mpd_name in i["playbackUrl"] and tags in i["tagsCombination"]:
mpd_url = i["playbackUrl"]
break
if m3u8_name in i["playbackUrl"] and tags in i["tagsCombination"]:
m3u8_url = i["playbackUrl"]
break
if not mpd_url:
playlist_base = m3u8_url.split(m3u8_name)[0]
m3u8 = hotstar.get(m3u8_url, headers=MPD_HEADERS).text
subindex_id = False
stream_ids = []
subindex_ids = re.findall(r'URI="(.*)"', m3u8)
for i in m3u8.split('\n'):
if ".m3u8" in i:
stream_ids.append(i.replace(playlist_base, ""))
if AUTO_MODE:
stream_id = stream_ids[-1]
if subindex_ids:
subindex_id = subindex_ids[-1]
else:
stream_id = input("Stream ID: ")
if subindex_ids:
subindex_id = input("Subtitle Index ID: ")
index_url = playlist_base + stream_id
index = hotstar.get(index_url, headers=MPD_HEADERS).text
print(bs(index, "html.parser").prettify())
segment_ids = []
for i in index.split('\n'):
if ".ts" in i:
segment_ids.append(i.replace(playlist_base, ""))
Subtitle = False
if subindex_id:
subtitle_index = hotstar.get(playlist_base + subindex_id, headers=MPD_HEADERS).text
subtitle_ids = []
for i in subtitle_index.split("\n"):
if not "#EXT" in i:
subtitle_ids.append(i)
print(subtitle_ids)
if AUTO_MODE:
subtitle_id = subtitle_ids[-1]
else:
subindex_id = input("Subtitle ID: ")
subtitle_url = playlist_base + subtitle_id
with open(f'{ID}-sub.vtt', 'wb') as sub:
SUB = hotstar.get(subtitle_url, headers=MPD_HEADERS)
if SUB.status_code == 200:
print(f"OK: {ID}-{subtitle_id}")
sub.write(SUB.content)
Subtitle = True
with open(f"{ID}-strm.ts", "wb") as strm:
for i in segment_ids:
TS = hotstar.get(playlist_base + i, headers=MPD_HEADERS)
if TS.status_code == 200:
print(f"OK: {ID}-{i}")
strm.write(TS.content)
if Subtitle:
ffmpeg_command = ["ffmpeg",
"-i", f"{ID}-strm.ts",
"-i", f"{ID}-sub.vtt",
"-map", "0",
"-map", "1",
"-c", "copy",
f'{ID}.mkv']
else:
ffmpeg_command = ["ffmpeg",
"-i", f"{ID}-strm.ts",
"-map", "0",
"-c", "copy",
f'{ID}.mkv']
subprocess.run(ffmpeg_command)
else:
playlist_base = mpd_url.split(mpd_name)[0]
mpd = hotstar.get(mpd_url, headers=MPD_HEADERS).content
print(bs(mpd, "html.parser").prettify())
subtitle_id = False
video_ids = []
audio_ids = []
subtitle_ids = []
for i in bs(mpd, "lxml").find_all("representation"):
if "video" in i.get("id"):
video_ids.append(i.get("id"))
elif "audio" in i.get("id"):
audio_ids.append(i.get("id"))
elif "subtitle" in i.get("id"):
subtitle_ids.append(i.get("id"))
print(video_ids)
print(audio_ids)
print(subtitle_ids)
if AUTO_MODE:
video_id = video_ids[-1]
audio_id = audio_ids[-1]
if subtitle_ids:
subtitle_id = subtitle_ids[-1]
else:
video_id = input("Video ID: ")
audio_id = input("Audio ID: ")
subtitle_id = input("Subtitle ID: ")
video_base_url = f"{mpd_url.split(mpd_name)[0]}{video_id}/"
audio_base_url = f"{mpd_url.split(mpd_name)[0]}{audio_id}/"
Subtitle = False
#DOWNLOAD
if subtitle_id:
subtitle_url = f"{mpd_url.split(mpd_name)[0]}{subtitle_id}.vtt"
with open(f'{ID}-sub.vtt', 'wb') as sub:
SUB = hotstar.get(subtitle_url, headers=MPD_HEADERS)
if SUB.status_code == 200:
print(f"OK: {ID}-S")
sub.write(SUB.content)
Subtitle = True
with open(f"{ID}-vid.m4s", "wb") as vid:
c = 1
INIT = hotstar.get(video_base_url + "init.mp4", headers=MPD_HEADERS)
print(f"OK: {ID}-INIT-V")
vid.write(INIT.content)
while True:
SEG = hotstar.get(video_base_url + f"seg-{c}.m4s", headers=MPD_HEADERS)
if SEG.status_code == 200:
print(f"OK: {ID}-{c}V")
vid.write(SEG.content)
c += 1
else:
break
with open(f"{ID}-aud.m4s", "wb") as vid:
c = 1
INIT = hotstar.get(audio_base_url + "init.mp4", headers=MPD_HEADERS)
vid.write(INIT.content)
print(f"OK: {ID}-INIT-A")
while True:
SEG = hotstar.get(audio_base_url + f"seg-{c}.m4s", headers=MPD_HEADERS)
if SEG.status_code == 200:
print(f"OK: {ID}-{c}A")
vid.write(SEG.content)
c += 1
else:
break
if Subtitle:
ffmpeg_command = ["ffmpeg",
"-i", f"{ID}-vid.m4s",
"-i", f"{ID}-aud.m4s",
"-i", f"{ID}-sub.vtt",
"-map", "0",
"-map", "1",
"-map", "2",
"-c", "copy",
f'{ID}.mkv']
else:
ffmpeg_command = ["ffmpeg",
"-i", f"{ID}-vid.m4s",
"-i", f"{ID}-aud.m4s",
"-map", "0",
"-map", "1",
"-c", "copy",
f'{ID}.mkv']
subprocess.run(ffmpeg_command)