MCPcopy Create free account
hub / github.com/UndCover/PyramidStore / getMediaSlice

Method getMediaSlice

plugin/py_ali_subtitle.py:240–295  ·  view source on GitHub ↗
(self,shareId,token,fileId)

Source from the content-addressed store, hash-verified

238 return resultJo['download_url']
239
240 def getMediaSlice(self,shareId,token,fileId):
241 params = {
242 "share_id": shareId,
243 "category": "live_transcoding",
244 "file_id": fileId,
245 "template_id": ""
246 }
247 customHeader = self.header.copy()
248 customHeader['x-share-token'] = token
249 customHeader['authorization'] = self.authorization
250 url = 'https://api.aliyundrive.com/v2/file/get_share_link_video_preview_play_info'
251
252 rsp = requests.post(url,json = params,headers=customHeader)
253 rspJo = json.loads(rsp.text)
254
255 quality = ['FHD','HD','SD']
256 videoList = rspJo['video_preview_play_info']['live_transcoding_task_list']
257 highUrl = ''
258 for q in quality:
259 if len(highUrl) > 0:
260 break
261 for video in videoList:
262 if(video['template_id'] == q):
263 highUrl = video['url']
264 break
265 if len(highUrl) == 0:
266 highUrl = videoList[0]['url']
267
268 noRsp = requests.get(highUrl,headers=self.header, allow_redirects=False,verify = False)
269 m3u8Url = ''
270 if 'Location' in noRsp.headers:
271 m3u8Url = noRsp.headers['Location']
272 if 'location' in noRsp.headers and len(m3u8Url) == 0 :
273 m3u8Url = noRsp.headers['location']
274 m3u8Rsp = requests.get(m3u8Url,headers=self.header)
275 m3u8Content = m3u8Rsp.text
276
277 tmpArray = m3u8Url.split('/')[0:-1]
278 host = '/'.join(tmpArray) + '/'
279
280 m3u8List = []
281 mediaMap = {}
282 slices = m3u8Content.split("\n")
283 count = 0
284 for slice in slices:
285 tmpSlice = slice
286 if 'x-oss-expires' in tmpSlice:
287 count = count + 1
288 mediaMap[str(count)] = host+tmpSlice
289
290 tmpSlice = "{0}?do=push_agent&api=python&type=media&share_id={1}&file_id={2}&media_id={3}".format(self.localProxyUrl,shareId,fileId,count)
291 m3u8List.append(tmpSlice)
292
293 self.localMedia[fileId] = mediaMap
294
295 return '\n'.join(m3u8List)
296
297 def proxyMedia(self,map):

Callers 2

proxyMediaMethod · 0.95
proxyM3U8Method · 0.95

Calls 1

postMethod · 0.45

Tested by

no test coverage detected