petite modif pour enregistrer en donnant un nom
Exemple pour enregistrer la RTS1, une ligne dans la crontab avec une commande
/usr/bin/php /home/gg/watch_teleboy_v3_batch.php 76 9000 master_of_sex_s03e01-02
à une date donnée
va créer un fichier du type
RTS1HD_20160103172428_master_of_sex_s03e01-02.ts
Le code
<?php
/*
Filename: WatchTeleboy.php.
Copyright 2013/2015.
Author: Darby_Crash.
Email: kihol@inwind.it
This Program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This Program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$version = "2.6.2";
$username = "k3c";
$password = "aizuwa617";
error_reporting(0);
strncasecmp(php_uname('s'), "Win", 3) == 0 ? $windows = true : $windows = false;
if ($windows) {
if (file_exists("C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe")) {
$vlc = "C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe";
} else if (file_exists("C:\\Program Files\\VideoLAN\\VLC\\vlc.exe")) {
$vlc = "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe";
} else {
$vlc = "C:\\Programmi\\VideoLAN\\VLC\\vlc.exe";
}
} else {
$vlc = "vlc";
$out = "2>/dev/null";
}
$ip = "85.".rand(0,7).".".rand(0,255).".".rand(0,255);
$api_key = 'f0e7bdfb822fa88c0c7a13f752a7e8d5c3757a13f757a13f9c0c7a13f7dfb822';
function get($url,$referer,$h){
global $api_key, $ssid, $ip;
if ( $h == '1' ) {
unset($headers);
$headers[] = "x-teleboy-apikey: $api_key";
$headers[] = "x-teleboy-session: $ssid";
$headers[] = "X-Forwarded-For: $ip";
}
$ch = curl_init ($url);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16');
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_REFERER, $referer);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec ($ch);
curl_close($ch);
return $res;
}
function post($url,$data,$referer){
$ch = curl_init ($url);
curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16');
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_REFERER, $referer);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded;charset=UTF-8","Connection: Keep-Alive","Content-Length: ".strlen($data)));
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
echo "\r\n\r\nWatchTeleboy by Darby_Crash\r\n\r\n";
get('http://t.teleboy.ch/en/tv/live_tv.php','');
post('http://t.teleboy.ch/login_check',"login=$username&password=$password&x=14&y=7&keep_login=1",'http://t.teleboy.ch/en/tv/live_tv.php');
$data = get('http://t.teleboy.ch/en/tv/live_tv.php','http://t.teleboy.ch/en/tv/live_tv.php');
$check = file_get_contents("cookies.txt");
if (preg_match("/cinergy_auth/", $check)) {
preg_match("/cinergy_s\t(.*?)\s/", $check, $ssid);
$ssid = $ssid[1];
preg_match("/\s+id:\s*(.*?),/s", $data, $uid);
$uid = $uid[1];
} else {
unlink('cookies.txt');
die("\r\nLogin failed! Check your account data!\r\n\r\n");
}
preg_match_all('|<td\sclass="station">.*?title="(.*?)".*?data-play-live="\d+/\d+".*?data-stationid="(\d+)"|s', $data, $names);
$lista = array();
for ($i=0;$i<count($names[1]);$i++) {
$lista[] = $names[1][$i]."^".$names[2][$i];
}
natcasesort($lista);
$list = array_values($lista);
echo "\r\nChannels list:\r\n\r\n";
for ($i=0;$i<count($list);$i++){
$tmp = explode("^", $list[$i]);
echo "$i) ".$tmp[0].((($i + 1)% 4 == 0) ? "\r\n" : str_repeat(' ', 17 - strlen($tmp[0].$i)));
}
echo "\r\nChoose a channel (x=exit): ";
$inp = $argv[1];
if ($inp >= count($list) || !preg_match("/[0-9xX]/", $inp)){
echo "\r\nInvalid choice!\r\n";
sleep(2);
continue;
} elseif ($inp == "x" || $inp == "X"){
unlink("cookies.txt");
die("\r\nKilled!\r\n\r\n");
}
$tmp = explode("^", $list[$inp]);
$data = json_decode(get("http://tv.api.teleboy.ch/users/".$uid."/stream/live/".$tmp[1]."?alternative=false",'','1'), true);
$url = $data["data"]["stream"]["url"];
echo "\r\nPlaying ".$tmp[0]."...\r\n";
# $cmd = 'livestreamer -o \''.$tmp[0].'_'.date("YmdHis").'\'.ts --player "\''.$vlc.'\' --meta-title=\''.$tmp[0].'\' --file-caching=10000" --http-header "X-Forwarded-For='.$ip.'" "hlsvariant://'.$url.'" best';
$cmd = 'livestreamer -o \''.$tmp[0].'_'.date("YmdHis").'_'.$argv[3].'\'.ts --player "\''.$vlc.'\' --meta-title=\''.$tmp[0].'\' --file-caching=10000" --http-header "X-Forwarded-For='.$ip.'" "hlsvariant://'.$url.'" best';
shell_exec($cmd." > /dev/null 2>/dev/null &");
sleep($argv[2]);
shell_exec('killall livestreamer');
?>