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

Method getMediaSlice

plugin/py_ali.py:211–266  ·  view source on GitHub ↗
(self,shareId,token,fileId)

Source from the content-addressed store, hash-verified

209 return resultJo['download_url']
210
211 def getMediaSlice(self,shareId,token,fileId):
212 params = {
213 "share_id": shareId,
214 "category": "live_transcoding",
215 "file_id": fileId,
216 "template_id": ""
217 }
218 customHeader = self.header.copy()
219 customHeader['x-share-token'] = token
220 customHeader['authorization'] = self.authorization
221 url = 'https://api.aliyundrive.com/v2/file/get_share_link_video_preview_play_info'
222
223 rsp = requests.post(url,json = params,headers=customHeader)
224 rspJo = json.loads(rsp.text)
225
226 quality = ['FHD','HD','SD']
227 videoList = rspJo['video_preview_play_info']['live_transcoding_task_list']
228 highUrl = ''
229 for q in quality:
230 if len(highUrl) > 0:
231 break
232 for video in videoList:
233 if(video['template_id'] == q):
234 highUrl = video['url']
235 break
236 if len(highUrl) == 0:
237 highUrl = videoList[0]['url']
238
239 noRsp = requests.get(highUrl,headers=self.header, allow_redirects=False,verify = False)
240 m3u8Url = ''
241 if 'Location' in noRsp.headers:
242 m3u8Url = noRsp.headers['Location']
243 if 'location' in noRsp.headers and len(m3u8Url) == 0 :
244 m3u8Url = noRsp.headers['location']
245 m3u8Rsp = requests.get(m3u8Url,headers=self.header)
246 m3u8Content = m3u8Rsp.text
247
248 tmpArray = m3u8Url.split('/')[0:-1]
249 host = '/'.join(tmpArray) + '/'
250
251 m3u8List = []
252 mediaMap = {}
253 slices = m3u8Content.split("\n")
254 count = 0
255 for slice in slices:
256 tmpSlice = slice
257 if 'x-oss-expires' in tmpSlice:
258 count = count + 1
259 mediaMap[str(count)] = host+tmpSlice
260
261 tmpSlice = "{0}?do=push_agent&api=python&type=media&share_id={1}&file_id={2}&media_id={3}".format(self.localProxyUrl,shareId,fileId,count)
262 m3u8List.append(tmpSlice)
263
264 self.localMedia[fileId] = mediaMap
265
266 return '\n'.join(m3u8List)
267
268 def proxyMedia(self,map):

Callers 2

proxyMediaMethod · 0.95
proxyM3U8Method · 0.95

Calls 1

postMethod · 0.45

Tested by

no test coverage detected