2
0

ket.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3. from kscore.ket import getKetClient
  4. import time
  5. import json
  6. if __name__ == "__main__":
  7. client = getKetClient("ket", "cn-beijing-6",use_ssl=False)
  8. uniqname = 'xxxx'
  9. presetname = 'xxxx'
  10. appname = 'xxxx'
  11. description = 'xxxx'
  12. presettype = 4
  13. streamid = 'xxxx'
  14. taskid = 'xxxx'
  15. outpull = 1
  16. srcurl = "xxxx"
  17. # 删除模板
  18. #res = client.DelPreset(App=appname, UniqName=uniqname, Preset=presetname)
  19. #print json.dumps(res)
  20. # 创建模板
  21. param = {
  22. "UniqName": uniqname,
  23. "Preset": presetname,
  24. "PresetType": presettype,
  25. "Description": description,
  26. "App": appname,
  27. "Output": [
  28. {
  29. "Idx": 0,
  30. "Overlay":[
  31. {
  32. "inputIdx": 0,
  33. }
  34. ],
  35. "Amix":[
  36. {
  37. "inputIdx": 0,
  38. }
  39. ]
  40. },
  41. {
  42. "Idx": 1,
  43. "Overlay":
  44. {
  45. "inputIdx": 0,
  46. },
  47. "Amix":
  48. {
  49. "inputIdx": 0,
  50. }
  51. },
  52. {
  53. "Idx": 2,
  54. "Video":
  55. {
  56. "codec": "copy",
  57. },
  58. "Audio":
  59. {
  60. "codec": "copy",
  61. }
  62. }
  63. ]
  64. }
  65. res = client.Preset(param)
  66. print json.dumps(res)
  67. # 更新模板
  68. res = client.UpdatePreset(param)
  69. print json.dumps(res)
  70. # 获取模板详情
  71. res = client.GetPresetDetail(App=appname, UniqName=uniqname, Preset=presetname)
  72. print json.dumps(res)
  73. # 获取用户模板列表
  74. res = client.GetPresetList(App=appname, UniqName=uniqname)
  75. print json.dumps(res)
  76. # 启动外网拉流
  77. param1 = {
  78. "UniqName": uniqname,
  79. "StreamID": streamid,
  80. "SrcUrl": srcurl,
  81. "App": appname,
  82. "Params": "a",
  83. }
  84. res = client.StartStreamPull(param1)
  85. print json.dumps(res)
  86. # 停止外网拉流
  87. param2 = {
  88. "UniqName": uniqname,
  89. "StreamID": streamid,
  90. "App": appname,
  91. }
  92. res = client.StopStreamPull(param2)
  93. print json.dumps(res)
  94. # 获取转码任务列表
  95. res = client.GetStreamTranList(App=appname, UniqName=uniqname, StreamID=streamid, OutPull=outpull)
  96. print json.dumps(res)
  97. # 获取用户已占用配额
  98. res = client.GetQuotaUsed(UniqName=uniqname)
  99. print json.dumps(res)
  100. # 发起轮播任务
  101. param3 = {
  102. "UniqName": uniqname,
  103. "App": appname,
  104. "StreamID": streamid,
  105. "Preset": presetname,
  106. "PubDomain": "xxxx",
  107. "DurationHour":168,
  108. "SrcInfo": [
  109. {
  110. "Path": "xxxx",
  111. "Index": 0
  112. }
  113. ]
  114. }
  115. res = client.StartLoop(param3)
  116. print json.dumps(res)
  117. # 更新轮播时长
  118. param5 = {
  119. "UniqName": uniqname,
  120. "App": appname,
  121. "StreamID": streamid,
  122. "DurationHour":100,
  123. }
  124. res = client.UpdateLoop(param5)
  125. print json.dumps(res)
  126. # 查询轮播列表
  127. res = client.GetLoopList(App=appname, UniqName=uniqname, StreamID=streamid)
  128. print json.dumps(res)
  129. # 停止轮播任务
  130. param4 = {
  131. "UniqName": uniqname,
  132. "App": appname,
  133. "StreamID": streamid,
  134. }
  135. res = client.StopLoop(param4)
  136. print json.dumps(res)
  137. #查询直播转码时长统计数据接口调用示例 : GetLiveTransDuration
  138. #参数
  139. # StartUnixTime:查询起始时间戳秒数
  140. # EndUnixTime:查询截止时间戳秒数
  141. # Granularity:统计时间粒度
  142. # ResultType:返回结果类型
  143. start = "2017-06-16 00:00:00"
  144. end = "2017-06-20 00:00:00"
  145. t0 = time.strptime(start, "%Y-%m-%d %H:%M:%S")
  146. t1 = time.strptime(end, "%Y-%m-%d %H:%M:%S")
  147. startunixtime = int(time.mktime(t0))
  148. endunixtime = int(time.mktime(t1))
  149. granularity = 5
  150. resulttype = 1
  151. res = client.GetLiveTransDuration(startunixtime, endunixtime, uniqname, granularity, resulttype)
  152. print json.dumps(res)
  153. # 创建选流任务
  154. param4 = {
  155. "UniqName": uniqname,
  156. "App": appname,
  157. "Preset": presetname,
  158. "SrcInfo": [
  159. {
  160. "Url": "rtmp://host/app/outernetStreamForSwitch",
  161. "Idx": 0
  162. },
  163. {
  164. "Streamid": "streamForSwitch",
  165. "Idx": 1
  166. }
  167. ],
  168. "DstInfo": [
  169. {
  170. "Streamid":"stream0ForMonitor",
  171. "Idx": 0
  172. },
  173. {
  174. "Streamid": "stream1ForSwitch",
  175. "Idx": 1
  176. },
  177. {
  178. "Streamid": "stream2ForSwitch",
  179. "Idx": 2
  180. }
  181. ]
  182. }
  183. res = client.CreateDirectorTask(param4)
  184. print json.dumps(res)
  185. #更新选流任务
  186. param4["TaskID"] = taskid
  187. res = client.UpdateDirectorTask(param4)
  188. print json.dumps(res)
  189. #查询选流任务
  190. res = client.QueryDirectorTask(App=appname, UniqName=uniqname, TaskID=taskid)
  191. print json.dumps(res)
  192. #删除选流任务
  193. res = client.DelDirectorTask(App=appname, UniqName=uniqname, TaskID=taskid)
  194. print json.dumps(res)