@@ -10588,6 +10588,131 @@ def ci_get_ai_queue(self, Bucket, State='All', QueueIds='', PageNumber='', PageS
1058810588 PageNumber = PageNumber , PageSize = PageSize ,
1058910589 UrlPath = "/ai_queue" , ** kwargs )
1059010590
10591+ def ci_get_hls_play_key (self , Bucket , ** kwargs ):
10592+ """ 获取 HLS 播放密钥 https://cloud.tencent.com/document/product/436/104292
10593+
10594+ :param Bucket(string) 存储桶名称.
10595+ :param kwargs:(dict) 设置上传的headers.
10596+ :return(dict): response header.
10597+ :return(dict): 请求成功返回的结果,dict类型.
10598+
10599+ .. code-block:: python
10600+
10601+ config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
10602+ client = CosS3Client(config)
10603+ # 获取 HLS 播放密钥
10604+ response, data = client.ci_get_hls_play_key(
10605+ Bucket='bucket',
10606+ ObjectKey='',
10607+ Body={}
10608+ )
10609+ print data
10610+ print response
10611+ """
10612+ headers = mapped (kwargs )
10613+ final_headers = {}
10614+ params = {}
10615+ for key in headers :
10616+ if key .startswith ("response" ):
10617+ params [key ] = headers [key ]
10618+ else :
10619+ final_headers [key ] = headers [key ]
10620+ headers = final_headers
10621+
10622+ params = format_values (params )
10623+ path = "/playKey"
10624+ url = self ._conf .uri (bucket = Bucket , path = path , endpoint = self ._conf ._endpoint_ci )
10625+
10626+ logger .info (
10627+ "ci_get_hls_play_key result, url=:{url} ,headers=:{headers}, params=:{params}" .format (
10628+ url = url ,
10629+ headers = headers ,
10630+ params = params ))
10631+ rt = self .send_request (
10632+ method = 'GET' ,
10633+ url = url ,
10634+ auth = CosS3Auth (self ._conf , path , params = params ),
10635+ params = params ,
10636+ headers = headers ,
10637+ ci_request = True )
10638+
10639+ data = rt .content
10640+ response = dict (** rt .headers )
10641+ if 'Content-Type' in response :
10642+ if response ['Content-Type' ] == 'application/xml' and 'Content-Length' in response and \
10643+ response ['Content-Length' ] != 0 :
10644+ data = xml_to_dict (rt .content )
10645+ format_dict (data , ['Response' ])
10646+ elif response ['Content-Type' ].startswith ('application/json' ):
10647+ data = rt .json ()
10648+
10649+ return response , data
10650+
10651+ def ci_update_hls_play_key (self , Bucket , MasterPlayKey = None , BackupPlayKey = None , ** kwargs ):
10652+ """ 更新 HLS 播放密钥 https://cloud.tencent.com/document/product/436/104291
10653+
10654+ :param Bucket(string) 存储桶名称.
10655+ :param MasterPlayKey(string) 主播放密钥.
10656+ :param BackupPlayKey(string) 备播放密钥.
10657+ :param kwargs:(dict) 设置上传的headers.
10658+ :return(dict): response header.
10659+ :return(dict): 请求成功返回的结果,dict类型.
10660+
10661+ .. code-block:: python
10662+
10663+ config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
10664+ client = CosS3Client(config)
10665+ # 获取 HLS 播放密钥
10666+ response, data = client.ci_get_hls_play_key(
10667+ Bucket='bucket',
10668+ ObjectKey='',
10669+ Body={}
10670+ )
10671+ print data
10672+ print response
10673+ """
10674+ headers = mapped (kwargs )
10675+ final_headers = {}
10676+ params = {}
10677+ for key in headers :
10678+ if key .startswith ("response" ):
10679+ params [key ] = headers [key ]
10680+ else :
10681+ final_headers [key ] = headers [key ]
10682+ headers = final_headers
10683+
10684+ if MasterPlayKey is not None :
10685+ params ['masterPlayKey' ] = MasterPlayKey
10686+ if BackupPlayKey is not None :
10687+ params ['backupPlayKey' ] = BackupPlayKey
10688+ params = format_values (params )
10689+ path = "/playKey"
10690+ url = self ._conf .uri (bucket = Bucket , path = path , endpoint = self ._conf ._endpoint_ci )
10691+ logger .info ("ci_update_hls_play_key result, url=:{url} ,headers=:{headers}, params=:{params}" .format (
10692+ url = url ,
10693+ headers = headers ,
10694+ params = params ))
10695+ rt = self .send_request (
10696+ method = 'PUT' ,
10697+ url = url ,
10698+ bucket = Bucket ,
10699+ auth = CosS3Auth (self ._conf , path , params = params ),
10700+ params = params ,
10701+ headers = headers ,
10702+ ci_request = True )
10703+
10704+ data = rt .content
10705+ response = dict (** rt .headers )
10706+ if 'Content-Type' in response :
10707+ if response ['Content-Type' ] == 'application/xml' and 'Content-Length' in response and \
10708+ response ['Content-Length' ] != 0 :
10709+ data = xml_to_dict (rt .content )
10710+ format_dict (data , ['Response' ])
10711+ elif response ['Content-Type' ].startswith ('application/json' ):
10712+ data = rt .json ()
10713+
10714+ return response , data
10715+
1059110716
1059210717if __name__ == "__main__" :
1059310718 pass
0 commit comments