Advertisement
Guest User

Untitled

a guest
Mar 21st, 2016
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1.  
  2.  
  3. Hello Guys,
  4.  
  5. In this tutorial we are going to show how our Player API Works. With this API you can integrate any 3rd party app with IPTV Panel Professional Edition and you can make your own apps.
  6.  
  7. The API Provides the user with information such as the available playlist (channels), user information (expire date, max connections), channel icons (including movies) and the EPG information for both live & vod.
  8.  
  9. In general it provides everything you need to cover 100% the panel features.
  10.  
  11. Let's see how it works first and how you can call it.
  12.  
  13. How to Call API
  14.  
  15. You can call the API Simply with the following format
  16.  
  17. http://your-dns:port/panel_api.php?username={username}&password={password}
  18.  
  19. You need to replace {username} & {password} with the username and the password of a simple user created under "Add New Line" section and listed on "Manage Lines"
  20.  
  21. Result
  22.  
  23. API Returns every result in JSON format so you will need to parse the JSON output in your application and in your desired language.
  24.  
  25. If you parse the JSON you will get a list of arrays which will result in something like the below
  26.  
  27. Array
  28. (
  29. [user_info] => Array
  30. (
  31. [username] => a
  32. [password] => b
  33. [auth] => 1
  34. [status] => Active
  35. [exp_date] =>
  36. [is_trial] => 0
  37. [active_cons] => 0
  38. [created_at] => 1441373291
  39. [max_connections] => 0
  40. [allowed_output_formats] => Array
  41. (
  42. [0] => m3u8
  43. [1] => ts
  44. )
  45.  
  46. )
  47.  
  48. [server_info] => Array
  49. (
  50. [url] => ip....
  51. [port] => 8080
  52. )
  53.  
  54. [categories] => Array
  55. (
  56. [live] => Array
  57. (
  58. [0] => Array
  59. (
  60. [category_id] => 1
  61. [category_name] => General Streams
  62. [parent_id] => 0
  63. )
  64.  
  65. )
  66.  
  67. [movie] => Array
  68. (
  69. [0] => Array
  70. (
  71. [category_id] => 2
  72. [category_name] => General Movies
  73. [parent_id] => 0
  74. )
  75.  
  76. [1] => Array
  77. (
  78. [category_id] => 3
  79. [category_name] => Sub Category For General Movies
  80. [parent_id] => 2
  81. )
  82.  
  83. )
  84.  
  85. )
  86.  
  87. [available_channels] => Array
  88. (
  89. [16] => Array
  90. (
  91. [num] => 1
  92. [name] => test
  93. [stream_type] => live
  94. [type_name] => Live Streams
  95. [stream_id] => 1
  96. [stream_icon] =>
  97. [epg_channel_id] => test.gr
  98. [added] => 0
  99. [category_id] => 11
  100. [series_no] =>
  101. [live] => 1
  102. [container_extension] =>
  103. [custom_sid] => :0:1:13f:157c:13e:820000:0:0:0:
  104. [tv_archive] => 1
  105. [tv_archive_duration] => 2
  106. )
  107.  
  108. [4] => Array
  109. (
  110. [num] => 1
  111. [name] => Test Movie
  112. [stream_type] => movie
  113. [type_name] => Movies
  114. [stream_id] => 1390
  115. [stream_icon] => http://test:5050/images/1431045.jpg
  116. [epg_channel_id] =>
  117. [added] => 1456333546
  118. [category_id] => 2
  119. [series_no] =>
  120. [live] => 0
  121. [container_extension] => mkv
  122. [custom_sid] =>
  123. [tv_archive] => 0
  124. [tv_archive_duration] => 0
  125. )
  126.  
  127. )
  128.  
  129. )
  130.  
  131.  
  132.  
  133. If the Username/Password combination is invalid you will get
  134.  
  135.  
  136.  
  137. Array
  138. (
  139. [user_info] => Array
  140. (
  141. [auth] => 0
  142. )
  143. )
  144.  
  145.  
  146.  
  147. Making the authentication
  148.  
  149. To make the authentication in your application simply check if the user_info element and auth key is 1.
  150.  
  151. Secondly you need to check if user_info element and status is Active
  152.  
  153. The status key indicates if the line is Expired/Blocked/Disabled or Enabled. So if the key is Active that means our user can see all the available channels and use the API correctly.
  154.  
  155. If the status isn't active you should print a message to the user and do not continue with the API.
  156.  
  157. status key may return the following:
  158.  
  159. Banned = Admin has disabled the line under Manage Lines
  160. Disabled = Reseller or admin has disabled the line under Manage Lines
  161. Active = Everything is ok and line can is working
  162. Expired = Line has expired.
  163.  
  164.  
  165.  
  166. Grab Channel URLs
  167.  
  168. API Does not provide ready-to-use URLs, so you will need to build them in your application.
  169.  
  170. Every Available Stream has 3 important keys to build the URL.
  171.  
  172. stream_id (The Stream ID that the channel is assigned in)
  173. live (Tells if the stream is live channel or no. 1 means live, and 0 means it's vod )
  174. container_extension (This is only for VOD. It tells in which container our movie is in).
  175.  
  176. So when you will parse the available_channels element, you can do something like in pseudo code:
  177.  
  178. if live = 1 then url = http://dns:port/live/{username}/{password}/{stream_id}.ts
  179. if live = 0 then url = http://dns:port/movie/{username}/{password}/{stream_id}.{container_extension}
  180.  
  181. In exactly the same you can split the streams in categories using the category_name or category_id.
  182.  
  183. TV Archive
  184.  
  185. The TV Archive is available only for Live Channels and you can see if it is enabled by checking the element key "tv_archive" key. If it is 1 , it's enabled and 0 means it's disabled.
  186.  
  187. Below that you can get the tv_archive_duration that shows the days that the admin has set to keep the tv archive for.
  188.  
  189. Here is the request for TV Archive/Timeshift, that you can also implement it in your own Players ( Android etc )
  190.  
  191.  
  192. http://ip:port/streaming/timeshift.php?username=X&password=X&stream=X&start=2016-03-19:16-00&duration=120
  193.  
  194. After replacing the username, password with a simple user line and the stream with the Stream ID , you will get a TV Archive from 16:00 pm 2016-03-19 and with the duration of 120 Minutes ( 2 Hours )
  195.  
  196.  
  197. Getting EPG
  198.  
  199. To get the EPG Info for any channel or vod you have to call a url in the below format
  200.  
  201. http://your-dns:port/panel_api.php?username={username}&password={password}&action=get_epg&stream_id={stream_id}
  202.  
  203. You will need to replace the {stream_id} with the stream_id based on the available_channels element.
  204.  
  205.  
  206. Again the result will be in JSON , if you do a json parsing, you will get an array with all the available EPG.
  207.  
  208.  
  209.  
  210. Simple PHP Sample Code
  211.  
  212. Here is simple PHP Sample code that will make you understand how all the above works in action.
  213.  
  214. <?php
  215.  
  216.  
  217. $host = 'http://dns:port/';
  218. $username = 'a';
  219. $password = 'b';
  220. ########################################################
  221. $api_source = json_decode( file_get_contents( $host . "panel_api.php?username=$username&password=$password" ), true );
  222.  
  223. if ( !is_array( $api_source ) || empty( $api_source['user_info']['auth'] ) )
  224. {
  225. echo 'API Error';
  226. exit();
  227. }
  228.  
  229.  
  230. $output_format = getOutputFormat();
  231. $server_url = "http://{$api_source['server_info']['url']}:{$api_source['server_info']['port']}/";
  232.  
  233.  
  234. foreach ( $api_source['available_channels'] as $stream_id => $stream_info )
  235. {
  236. $epg_source = json_decode( file_get_contents( $host . "panel_api.php?username=$username&password=$password&action=get_epg&stream_id=" . $stream_id ), true );
  237.  
  238. if ( $stream_info['live'] == 1 )
  239. {
  240. $url = $server_url . "live/$username/$password/$stream_id." . $output_format;
  241.  
  242. echo "Stream Name: {$stream_info['name']} | URL: {$url}\n";
  243.  
  244. //do something with $epg_source
  245. }
  246. else
  247. {
  248. $url = $server_url . "movie/$username/$password/$stream_id." . $stream_info['container_extension'];
  249. echo "Movie Name: {$stream_info['name']} | URL: {$url}\n";
  250.  
  251. //do something with $epg_source
  252. }
  253. }
  254.  
  255. function getOutputFormat()
  256. {
  257. global $api_source;
  258.  
  259. if ( !empty( $api_source['user_info']['allowed_output_formats'] ) )
  260. {
  261. return ( in_array( 'ts', $api_source['user_info']['allowed_output_formats'] ) ) ? 'ts' : 'm3u8';
  262. }
  263.  
  264. return false;
  265. }
  266.  
  267. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement