Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. #!/usr/bin/env php
  2. <?php
  3.  
  4. // Source instance settings
  5. $sourceAddress = 'sourceip';
  6. $sourcePort = 9981;
  7. $sourceUsername = 'user';
  8. $sourcePassword = 'pass';
  9.  
  10. // Target instance settings
  11. $targetAddress = 'destinationuip';
  12. $targetPort = 9981;
  13. $targetUsername = 'user';
  14. $targetPassword = 'pass';
  15. $targetNetworkUuid = 'abccd06cc02a770e3804c6d4fed1e5ac';
  16.  
  17. // Format for the stream URLs
  18. $streamUrlFormat = 'http://%s:%s@%s:%d/stream/channel/%s';
  19.  
  20. // Construct the API url
  21. $targetUrl = sprintf('http://%s:%s@%s:%d/api/mpegts/network/mux_create',
  22.         $targetUsername,
  23.         $targetPassword,
  24.         $targetAddress,
  25.         $targetPort);
  26.  
  27. // Read the channel entries from the data file
  28. $channelData = json_decode(file_get_contents(__DIR__.'/../data/channels.json'));
  29.  
  30. // Start looping through them
  31. foreach($channelData->entries as $channel)
  32. {
  33.     // Construct the configuration object
  34.     $config = new stdClass();
  35.     $config->enabled = true;
  36.    
  37.     // Disable EPG scanning on the source, it usually doesn't work anyway
  38.     $config->epg = 0;
  39.     $config->scan_state = 0;
  40.     $config->iptv_url = sprintf($streamUrlFormat, $sourceUsername,
  41.             $sourcePassword, $sourceAddress, $sourcePort, $channel->uuid);
  42.     $config->iptv_interface = '';
  43.     $config->iptv_atsc = '';
  44.    
  45.     // Use channel name for the mux and service as well
  46.     $config->iptv_muxname = $channel->name;
  47.     $config->iptv_sname = $channel->name;
  48.     $config->charset = '';
  49.     $config->pmt_06_ac3 = false;
  50.     $config->priority = 0;
  51.     $config->spriority = 0;
  52.    
  53.     // Construct POST data to send
  54.     $postData = array(
  55.         'uuid'=>$targetNetworkUuid,
  56.         'conf'=>urlencode(json_encode($config)),
  57.     );
  58.    
  59.     // Perform the request
  60.     echo 'Adding channel "'.$channel->name.'" ...'.PHP_EOL;
  61.  
  62.     $ch = curl_init();
  63.    
  64.     curl_setopt_array($ch, array(
  65.         CURLOPT_URL=>$targetUrl,
  66.         CURLOPT_RETURNTRANSFER=>true,
  67.         CURLOPT_POST=>count($postData),
  68.         CURLOPT_POSTFIELDS=>generatePostString($postData)
  69.     ));
  70.  
  71.     $output = curl_exec($ch);
  72.     curl_close($ch);
  73.    
  74.     // Wait before adding the next one. Make sure "Max simultaneous streams"
  75.     // is not set to unlimited in the tvheadend network configuration
  76.     sleep(2);
  77. }
  78.  
  79. /**
  80.  *
  81.  * Functions
  82.  *
  83.  */
  84. function generatePostString($postData)
  85. {
  86.     $postDataString = '';
  87.    
  88.     foreach ($postData as $key=> $value)
  89.         $postDataString .= $key . '=' . $value . '&';
  90.  
  91.     return rtrim($postDataString, '&');
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement