Project

General

Profile

Mass adding channels

Added by brak brak about 6 years ago

Good morning ladies & gentelmans.

I have issue. How to add all channels from one network? I wrote script in PHP which doing get requeset, but not all channels have name. I am wondering what is wrong in my script. Could you help me ?

public function addChannel($uuid,$name){
$url = '/api/channel/create?';
$url .= "conf=%7B%22enabled%22%3Atrue%2C%22name%22%3A%22%$name22%2C%22number%22%3A%220%22%2C%22services%22%3A%5B%22$uuid%22%5D%2C%22tags%22%3A%22%22%2C%22autoname%22%3Afalse%2C%22icon%22%3A%22%22%2C%22epgauto%22%3Atrue%2C%22epglimit%22%3A1%2C%22epggrab%22%3A%22%22%2C%22dvr_pre_time%22%3A0%2C%22dvr_pst_time%22%3A0%2C%22epg_running%22%3A0%2C%22epg_parent%22%3A%22%22%7D";
$this->request($url);
}

As you see, I put $name into name parameter and with this few channels are added but now all. What is wrong here ?


Replies (2)

RE: Mass adding channels - Added by Dave Pickles about 6 years ago

URLdecoding your create string I get:
conf={"enabled":true,"name":"%$name22,"number":"0","services":["$uuid"],"tags":"","autoname":false,"icon":"","epgauto":true,"epglimit":1,"epggrab":"","dvr_pre_time":0,"dvr_pst_time":0,"epg_running":0,"epg_parent":""}

Your "name" parameter is missing its closing double-quote, because the % is missing. Also I suspect that the "epggrab" value should be a null array rather than an empty string - that's how it appears in the output of api/channel/grid.

RE: Mass adding channels - Added by brak brak about 6 years ago

probably you have got right. there is working code, I changed way to generate parameters to more clear version
@
public function request($url, $debug=false){
$options = array(
CURLOPT_URL => $this->url.$url,
CURLOPT_HEADER => false,
CURLOPT_VERBOSE => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => false, // for https
CURLOPT_USERPWD => $this->login . ":" . $this->password,
CURLOPT_HTTPAUTH => CURLAUTH_DIGEST,
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$raw_response = curl_exec($ch);
if($debug){
var_dump($raw_response);
die($this->url.$url);
}
return $raw_response;
}

public function addChannel($uuid,$name){
$url = '/api/channel/create?conf=';
$options = [
'enabled' => true,
'name' => $name,
'number' => '',
'services' => [$uuid],
'tags' => '',
'autoname' => true,
'icon' => '',
'epgauto' => true,
'epglimit' => 1,
'epggrab' => '',
'dvr_pre_time' => 0,
'dvr_pst_time' => 0,
'epg_running' => 0,
'epg_parent' => '',
];
$url .= urlencode(json_encode($options));
return $this->request($url);
}
@

    (1-2/2)