Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env php
- <?php
- // Source instance settings
- $sourceAddress = 'sourceip';
- $sourcePort = 9981;
- $sourceUsername = 'user';
- $sourcePassword = 'pass';
- // Target instance settings
- $targetAddress = 'destinationuip';
- $targetPort = 9981;
- $targetUsername = 'user';
- $targetPassword = 'pass';
- $targetNetworkUuid = 'abccd06cc02a770e3804c6d4fed1e5ac';
- // Format for the stream URLs
- $streamUrlFormat = 'http://%s:%s@%s:%d/stream/channel/%s';
- // Construct the API url
- $targetUrl = sprintf('http://%s:%s@%s:%d/api/mpegts/network/mux_create',
- $targetUsername,
- $targetPassword,
- $targetAddress,
- $targetPort);
- // Read the channel entries from the data file
- $channelData = json_decode(file_get_contents(__DIR__.'/../data/channels.json'));
- // Start looping through them
- foreach($channelData->entries as $channel)
- {
- // Construct the configuration object
- $config = new stdClass();
- $config->enabled = true;
- // Disable EPG scanning on the source, it usually doesn't work anyway
- $config->epg = 0;
- $config->scan_state = 0;
- $config->iptv_url = sprintf($streamUrlFormat, $sourceUsername,
- $sourcePassword, $sourceAddress, $sourcePort, $channel->uuid);
- $config->iptv_interface = '';
- $config->iptv_atsc = '';
- // Use channel name for the mux and service as well
- $config->iptv_muxname = $channel->name;
- $config->iptv_sname = $channel->name;
- $config->charset = '';
- $config->pmt_06_ac3 = false;
- $config->priority = 0;
- $config->spriority = 0;
- // Construct POST data to send
- $postData = array(
- 'uuid'=>$targetNetworkUuid,
- 'conf'=>urlencode(json_encode($config)),
- );
- // Perform the request
- echo 'Adding channel "'.$channel->name.'" ...'.PHP_EOL;
- $ch = curl_init();
- curl_setopt_array($ch, array(
- CURLOPT_URL=>$targetUrl,
- CURLOPT_RETURNTRANSFER=>true,
- CURLOPT_POST=>count($postData),
- CURLOPT_POSTFIELDS=>generatePostString($postData)
- ));
- $output = curl_exec($ch);
- curl_close($ch);
- // Wait before adding the next one. Make sure "Max simultaneous streams"
- // is not set to unlimited in the tvheadend network configuration
- sleep(2);
- }
- /**
- *
- * Functions
- *
- */
- function generatePostString($postData)
- {
- $postDataString = '';
- foreach ($postData as $key=> $value)
- $postDataString .= $key . '=' . $value . '&';
- return rtrim($postDataString, '&');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement