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