Beispiel #1
0
function ShowChannel($url, $filename)
{
    global $cc, $cli, $format, $password, $PremiumUser, $quality, $username, $vlc, $windows;
    LogInfo("Retrieving info....");
    $cc->headers = $cc->headers();
    $cid = substr($url, strrpos($url, '/') + 1);
    if (!$cid) {
        Close("No channel id found");
    }
    // Retrieve rtmp stream info
    $cc->headers[] = "Referer: http://static.weeb.tv/player.swf";
    $Params = GetApiResponse($cc, "http://weeb.tv/api/setPlayer", "cid=" . $cid . "&watchTime=0&firstConnect=1&ip=NaN");
    if (isset($Params[0]) and $Params[0] <= 0) {
        Close("Server refused to send required parameters.");
    }
    $rtmp = $Params["10"];
    $playpath = $Params["11"];
    $MultiBitrate = $Params["20"];
    $PremiumUser = $Params["5"];
    if ($MultiBitrate) {
        $playpath .= $quality;
    }
    $BlockType = $Params["13"];
    if ($BlockType != 0) {
        switch ($BlockType) {
            case 1:
                $BlockTime = $Params["14"];
                $ReconnectionTime = $Params["16"];
                Close("You have crossed free viewing limit. you have been blocked for {$BlockTime} minutes. try again in {$ReconnectionTime} minutes.");
                break;
            case 11:
                Close("No free slots available");
                break;
            default:
                break;
        }
    }
    // Retrieve authentication token
    if (!isset($Params["73"])) {
        $Params = GetApiResponse($cc, "http://weeb.tv/api/setPlayer", "cid=" . $cid . "&watchTime=0&firstConnect=0&ip=NaN");
    }
    if (isset($Params["73"])) {
        $token = $Params["73"];
    } else {
        Close("Server seems busy, please try after some time.");
    }
    LogInfo(sprintf($format, "RTMP Url", $rtmp));
    LogInfo(sprintf($format, "Playpath", $playpath));
    LogInfo(sprintf($format, "Token", $token));
    LogInfo(sprintf($format, "Premium", $PremiumUser ? "Yes" : "No"));
    if ($username != "" && $password != "") {
        $token = "{$token};{$username};{$password}";
    }
    $filename = SafeFileName($filename);
    if (file_exists($filename . ".flv")) {
        unlink($filename . ".flv");
    }
    $basecmd = 'rtmpdump -r "' . $rtmp . "/" . $playpath . '" -W "http://static.weeb.tv/player.swf" --weeb "' . $token . "\" --live";
    $command = $basecmd . " | \"{$vlc}\" --meta-title \"{$filename}\" -";
    if ($cli->getParam('print')) {
        printf($basecmd);
        exit(0);
    }
    LogInfo(sprintf($format, "Command", $command));
    if ($rtmp && $token) {
        if ($windows) {
            RunAsyncBatch($command, $filename);
        } else {
            exec($command);
        }
    }
}
Beispiel #2
0
function ShowChannel($url, $filename)
{
    global $cc, $cli, $format, $vlc, $windows, $xxtea;
    LogInfo("Retrieving html....");
    $cc->headers = $cc->headers();
    // Retrieve channel id and primary key
    $timestamp = time();
    $player_id = $url;
    $init = $cc->get("http://tvplayer.playtv.fr/js/{$player_id}.js?_={$timestamp}");
    preg_match("/b:[^{]*?({[^}]+})/i", $init, $init);
    $init = json_decode(trim($init[1]));
    if (!$init) {
        Close("Unable to retrieve initialization parameters");
    }
    $a = pack("H*", $init->{'a'});
    $b = pack("H*", $init->{'b'});
    $xxtea->setKey("object");
    $params = json_decode(trim($xxtea->decrypt($b)));
    if (!$params) {
        Close("Unable to decode initialization parameters");
    }
    $key = $xxtea->decrypt(pack("H*", $params->{'k'}));
    $xxtea->setKey($key);
    $params = json_decode(trim($xxtea->decrypt($a)));
    $channel_id = $params->{'i'};
    $api_url = $params->{'u'};
    // Generate parameter request
    $request = json_encode(array('i' => $channel_id, 't' => $timestamp, 'h' => 'playtv.fr', 'a' => 5));
    $request = unpack("H*", $xxtea->encrypt($request));
    $request = $request[1];
    if (substr($request, -1) != '/') {
        $request .= '/';
    }
    $cc->headers[] = "Referer: http://static.playtv.fr/swf/tvplayer.swf?r=22";
    $cc->headers[] = "x-flash-version: 11,6,602,180";
    $response = $cc->get($api_url . $request);
    // Decode server response
    $response = pack("H*", $response);
    $params = json_decode(trim($xxtea->decrypt($response)));
    if (!$params) {
        Close("Unable to decode server response");
    }
    if (isset($params->{'s'}[1])) {
        $streams = $params->{'s'}[0]->{'bitrate'} > $params->{'s'}[1]->{'bitrate'} ? $params->{'s'}[0] : $params->{'s'}[1];
    } else {
        $streams = $params->{'s'}[0];
    }
    $scheme = $streams->{'scheme'};
    $host = $streams->{'host'};
    $port = $streams->{'port'};
    $app = $streams->{'application'};
    $playpath = $streams->{'stream'};
    $token = $streams->{'token'};
    $title = $streams->{'title'};
    // Generate authentication token for rtmp server
    $t = $params->{'j'}->{'t'};
    $k = $params->{'j'}->{'k'};
    $xxtea->setKey("object");
    $key = $xxtea->decrypt(pack("H*", $k));
    $xxtea->setKey($key);
    $auth = unpack("H*", $xxtea->encrypt($t));
    $auth = $auth[1];
    if ($scheme == "http") {
        LogInfo(sprintf($format, "HTTP Url", "{$scheme}://{$host}" . (isset($port) ? ":{$port}" : "") . "/{$playpath}"));
    } else {
        LogInfo(sprintf($format, "RTMP Url", "{$scheme}://{$host}" . (isset($port) ? ":{$port}" : "") . "/{$app}"));
    }
    LogInfo(sprintf($format, "Playpath", $playpath));
    LogInfo(sprintf($format, "Auth", $auth));
    $filename = SafeFileName($filename);
    if (file_exists($filename . ".flv")) {
        unlink($filename . ".flv");
    }
    if ($scheme == "http") {
        $basecmd = "{$scheme}://{$host}" . (isset($port) ? ":{$port}" : "") . "/{$playpath}";
        $command = "\"{$vlc}\" --meta-title \"{$title}\" \"{$basecmd}\"";
    } else {
        $basecmd = "rtmpdump -r \"{$scheme}://{$host}" . (isset($port) ? ":{$port}" : "") . "/{$app}\" -a \"{$app}\" -s \"http://static.playtv.fr/swf/tvplayer.swf\" -p \"http://playtv.fr/television\" -C S:{$auth} " . (isset($token) ? "-T \"{$token}\" " : "") . "--live -y \"{$playpath}\"";
        $command = $basecmd . " | \"{$vlc}\" --meta-title \"{$title}\" -";
    }
    if ($cli->getParam('print')) {
        printf($basecmd);
        exit(0);
    }
    LogInfo(sprintf($format, "Command", $command));
    if ($host && $playpath && $auth) {
        if ($windows) {
            RunAsyncBatch($command, $filename);
        } else {
            exec($command);
        }
    }
}