当前位置: 移动技术网 > IT编程>开发语言>PHP > 56.com视频采集接口程序(PHP)

56.com视频采集接口程序(PHP)

2019年05月13日  | 移动技术网IT编程  | 我要评论
楼下也有一个所谓56站程序的,忽悠到了极致,不喜欢被人忽悠的,还是自己做个站吧!
我给大家个采集接口,你爱自己采集可以用自己的flash播放器直接播放56.com的flv吧!不用帮人家做免费广告那么傻了!

复制代码 代码如下:

<?php
$url = "http://www.56.com/u75/v_mtkwmtiwmjq.html";
$html = @file_get_contents($url);
preg_match_all("/var _oflv_o = '([\s|\s]+)'/isu", $html, $matches);
$o = decode56($matches[1][0]);
include_once "json.php"; //当php没有配置支持json的时候有用
$o = str_replace("'", '"', $o);
$o = json_decode($o);
//print_r($o);
$swf = "http://www.56.com/n_" . str_replace(":88", "", str_replace(".56.com", "", $o->img_host)) .
                "_/" . str_replace(".56.com", "", $o->url_host) .
                "_/" . $o->url_purl .
                "_/" . $o->url_surl .
                "_/" . $o->user_id .
                "_/" . $o->url_urlid .
                "_/" . $o->totaltime .
                "_/" . $o->effectid .
                "_/" . $o->id . ".swf";
$flv = "http://hot-chinacache.56.com/flvdownload/" . $o->url_purl .
                "/" . $o->url_surl .
                "/" . $o->user_id .
                "@56.com_56flv_" . $o->url_urlid . ".flv";
echo "flash文件路径: " . $swf;
echo "<br>";
echo "flv文件路径: " . $flv;

$de = 0;
function decode56($str) {
    global $de;
    $c1 = "";
    $c2 = "";
    $c3 = "";
    $c4 = "";
    $c5 = array(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1);
    $c6 = charcodeat($str, 0);
    $c7 = "";
    $i = "";
    $len = "";
    $out = "";
    if(!$de) {
        $de = 1;
        $c7 = decode56($str);
        $str = substr($c7, $c6);
    }
    $len = strlen($str);
    $i = 1;
    $out = "";
    while ($i < $len) {
        do {
            $c1 = $c5[charcodeat($str, $i++) & 0xff];
        }
        while($i < $len && $c1 == -1);
        if ($c1 == -1) break;
        do {
            $c2 = $c5[charcodeat($str, $i++) & 0xff];
        }
        while ($i < $len && $c2 == -1);
        if($c2 == -1) break;
        $out .= chr(($c1 << 2) | (($c2 & 0x30) >> 4));
        do {
            $c3 = charcodeat($str, $i++) & 0xff;
            if($c3 == 61) return $out;
            $c3 = $c5[$c3];
        }
        while ($i < $len && $c3 == -1);
        if($c3 == -1) break;
        $out .= chr((($c2 & 0xf) << 4) | (($c3 & 0x3c) >> 2));
        do {
            $c4 = charcodeat($str, $i++) & 0xff;
            if($c4 == 61) return $out;
            $c4 = $c5[$c4];
        }
        while ($i < $len && $c4 == -1);
        if ($c4 == -1) break;
        $out .= chr((($c3 & 0x03) << 6) | $c4);
    }
    return $out;
}

function charcodeat($str, $i){
    return ord(substr($str, $i, 1));
}

//该程序仅为技术交流,交流可加qq群: 1714987
?>

json.php
复制代码 代码如下:

<?php
define('html_ajax_json_slice',   1);
define('html_ajax_json_in_str',  2);
define('html_ajax_json_in_arr',  4);
define('html_ajax_json_in_obj',  8);
define('html_ajax_json_in_cmt', 16);
define('html_ajax_json_loose_type', 10);
define('html_ajax_json_strict_type', 11);

class html_ajax_json
{
    function html_ajax_json($use=html_ajax_json_strict_type)
    {
        $this->use = $use;
    }

    function encode($var)
    {
        switch(gettype($var)) {
            case 'boolean':
                return $var ? 'true' : 'false';

            case 'null':
                return 'null';

            case 'integer':
                return sprintf('%d', $var);

            case 'double':
            case 'float':
                return sprintf('%f', $var);

            case 'string': // strings are expected to be in ascii or utf-8 format
                $ascii = '';
                $strlen_var = strlen($var);

                for($c = 0; $c < $strlen_var; $c++) {

                    $ord_var_c = ord($var{$c});

                    if($ord_var_c == 0x08) {
                        $ascii .= '\b';

                    } elseif($ord_var_c == 0x09) {
                        $ascii .= '\t';

                    } elseif($ord_var_c == 0x0a) {
                        $ascii .= '\n';

                    } elseif($ord_var_c == 0x0c) {
                        $ascii .= '\f';

                    } elseif($ord_var_c == 0x0d) {
                        $ascii .= '\r';

                    } elseif(($ord_var_c == 0x22) || ($ord_var_c == 0x2f) || ($ord_var_c == 0x5c)) {
                        $ascii .= '\\'.$var{$c}; // double quote, slash, slosh

                    } elseif(($ord_var_c >= 0x20) && ($ord_var_c <= 0x7f)) {
                        // characters u-00000000 - u-0000007f (same as ascii)
                        $ascii .= $var{$c}; // most normal ascii chars

                    } elseif(($ord_var_c & 0xe0) == 0xc0) {
                        // characters u-00000080 - u-000007ff, mask 110xxxxx, see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                        $char = pack('c*', $ord_var_c, ord($var{$c+1})); $c+=1;
                        $ascii .= sprintf('\u%04s', bin2hex(mb_convert_encoding($char, 'utf-16', 'utf-8')));

                    } elseif(($ord_var_c & 0xf0) == 0xe0) {
                        // characters u-00000800 - u-0000ffff, mask 1110xxxx, see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                        $char = pack('c*', $ord_var_c, ord($var{$c+1}), ord($var{$c+2})); $c+=2;
                        $ascii .= sprintf('\u%04s', bin2hex(mb_convert_encoding($char, 'utf-16', 'utf-8')));

                    } elseif(($ord_var_c & 0xf8) == 0xf0) {
                        // characters u-00010000 - u-001fffff, mask 11110xxx, see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                        $char = pack('c*', $ord_var_c, ord($var{$c+1}), ord($var{$c+2}), ord($var{$c+3})); $c+=3;
                        $ascii .= sprintf('\u%04s', bin2hex(mb_convert_encoding($char, 'utf-16', 'utf-8')));

                    } elseif(($ord_var_c & 0xfc) == 0xf8) {
                        // characters u-00200000 - u-03ffffff, mask 111110xx, see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                        $char = pack('c*', $ord_var_c, ord($var{$c+1}), ord($var{$c+2}), ord($var{$c+3}), ord($var{$c+4})); $c+=4;
                        $ascii .= sprintf('\u%04s', bin2hex(mb_convert_encoding($char, 'utf-16', 'utf-8')));

                    } elseif(($ord_var_c & 0xfe) == 0xfc) {
                        // characters u-04000000 - u-7fffffff, mask 1111110x, see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                        $char = pack('c*', $ord_var_c, ord($var{$c+1}), ord($var{$c+2}), ord($var{$c+3}), ord($var{$c+4}), ord($var{$c+5})); $c+=5;
                        $ascii .= sprintf('\u%04s', bin2hex(mb_convert_encoding($char, 'utf-16', 'utf-8')));
                    }
                }

                return sprintf('"%s"', $ascii);

            case 'array':
                if(is_array($var) && (array_keys($var) !== range(0, sizeof($var) - 1)))
                    return sprintf('{%s}', join(',', array_map(array($this, 'name_value'), array_keys($var), array_values($var))));

                return sprintf('[%s]', join(',', array_map(array($this, 'encode'), $var)));

            case 'object':
                $vars = get_object_vars($var);
                return sprintf('{%s}', join(',', array_map(array($this, 'name_value'), array_keys($vars), array_values($vars))));

            default:
                return '';
        }
    }

    function name_value($name, $value)
    {
        return (sprintf("%s:%s", $this->encode(strval($name)), $this->encode($value)));
    }

    function reduce_string($str)
    {
        $str = preg_replace('#^\s*//(.+)$#m', '', $str); // eliminate single line comments in '// ...' form
        $str = preg_replace('#^\s*/\*(.+)\*/#us', '', $str); // eliminate multi-line comments in '/* ... */' form, at start of string
        $str = preg_replace('#/\*(.+)\*/\s*$#us', '', $str); // eliminate multi-line comments in '/* ... */' form, at end of string
        $str = trim($str); // eliminate extraneous space

        return $str;
    }

    function decode($str)
    {
        $str = $this->reduce_string($str);

        switch(strtolower($str)) {
            case 'true':
                return true;

            case 'false':
                return false;

            case 'null':
                return null;

            default:
                if(is_numeric($str)) {
                    return ((float)$str == (integer)$str)
                        ? (integer)$str
                        : (float)$str;

                } elseif(preg_match('/^".+"$/s', $str) || preg_match('/^\'.+\'$/s', $str)) {
                    $delim = substr($str, 0, 1);
                    $chrs = substr($str, 1, -1);
                    $utf8 = '';
                    $strlen_chrs = strlen($chrs);

                    for($c = 0; $c < $strlen_chrs; $c++) {

                        $substr_chrs_c_2 = substr($chrs, $c, 2);
                        $ord_chrs_c = ord($chrs{$c});

                        if($substr_chrs_c_2 == '\b') {
                            $utf8 .= chr(0x08); $c+=1;

                        } elseif($substr_chrs_c_2 == '\t') {
                            $utf8 .= chr(0x09); $c+=1;

                        } elseif($substr_chrs_c_2 == '\n') {
                            $utf8 .= chr(0x0a); $c+=1;

                        } elseif($substr_chrs_c_2 == '\f') {
                            $utf8 .= chr(0x0c); $c+=1;

                        } elseif($substr_chrs_c_2 == '\r') {
                            $utf8 .= chr(0x0d); $c+=1;

                        } elseif(($delim == '"') && (($substr_chrs_c_2 == '\\"') || ($substr_chrs_c_2 == '\\\\') || ($substr_chrs_c_2 == '\\/'))) {
                            $utf8 .= $chrs{++$c};

                        } elseif(($delim == "'") && (($substr_chrs_c_2 == '\\\'') || ($substr_chrs_c_2 == '\\\\') || ($substr_chrs_c_2 == '\\/'))) {
                            $utf8 .= $chrs{++$c};

                        } elseif(preg_match('/\\\u[0-9a-f]{4}/i', substr($chrs, $c, 6))) { // single, escaped unicode character
                            $utf16 = chr(hexdec(substr($chrs, ($c+2), 2))) . chr(hexdec(substr($chrs, ($c+4), 2)));
                            $utf8 .= mb_convert_encoding($utf16, 'utf-8', 'utf-16');
                            $c+=5;

                        } elseif(($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7f)) {
                            $utf8 .= $chrs{$c};

                        } elseif(($ord_chrs_c & 0xe0) == 0xc0) {
                            $utf8 .= substr($chrs, $c, 2); $c += 1;

                        } elseif(($ord_chrs_c & 0xf0) == 0xe0) {
                            $utf8 .= substr($chrs, $c, 3); $c += 2;

                        } elseif(($ord_chrs_c & 0xf8) == 0xf0) {
                            $utf8 .= substr($chrs, $c, 4); $c += 3;

                        } elseif(($ord_chrs_c & 0xfc) == 0xf8) {
                            $utf8 .= substr($chrs, $c, 5); $c += 4;

                        } elseif(($ord_chrs_c & 0xfe) == 0xfc) {
                            $utf8 .= substr($chrs, $c, 6); $c += 5;
                        }
                    }
                    return $utf8;

                } elseif(preg_match('/^\[.*\]$/s', $str) || preg_match('/^{.*}$/s', $str)) {

                    if($str{0} == '[') {
                        $stk = array(html_ajax_json_in_arr);
                        $arr = array();
                    } else {
                        if($this->use == html_ajax_json_loose_type) {
                            $stk = array(html_ajax_json_in_obj);
                            $obj = array();
                        } else {
                            $stk = array(html_ajax_json_in_obj);
                            $obj = new stdclass();
                        }
                    }

                    array_push($stk, array('what' => html_ajax_json_slice, 'where' => 0, 'delim' => false));
                    $chrs = substr($str, 1, -1);
                    $chrs = $this->reduce_string($chrs);

                    if($chrs == '') {
                        if(reset($stk) == html_ajax_json_in_arr) {
                            return $arr;

                        } else {
                            return $obj;

                        }
                    }

                    $strlen_chrs = strlen($chrs);

                    for($c = 0; $c <= $strlen_chrs; $c++) {

                        $top = end($stk);
                        $substr_chrs_c_2 = substr($chrs, $c, 2);

                        if(($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == html_ajax_json_slice))) {
                            $slice = substr($chrs, $top['where'], ($c - $top['where']));
                            array_push($stk, array('what' => html_ajax_json_slice, 'where' => ($c + 1), 'delim' => false));

                            if(reset($stk) == html_ajax_json_in_arr) { // we are in an array, so just push an element onto the stack
                                array_push($arr, $this->decode($slice));

                            } elseif(reset($stk) == html_ajax_json_in_obj) { // we are in an object, so figure out the property name and set an element in an associative array, for now
                                if(preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\s.*),?$/uis', $slice, $parts)) { // "name":value pair
                                    $key = $this->decode($parts[1]);
                                    $val = $this->decode($parts[2]);

                                    if($this->use == html_ajax_json_loose_type) {
                                        $obj[$key] = $val;
                                    } else {
                                        $obj->$key = $val;
                                    }
                                } elseif(preg_match('/^\s*(\w+)\s*:\s*(\s.*),?$/uis', $slice, $parts)) { // name:value pair, where name is unquoted
                                    $key = $parts[1];
                                    $val = $this->decode($parts[2]);

                                    if($this->use == html_ajax_json_loose_type) {
                                        $obj[$key] = $val;
                                    } else {
                                        $obj->$key = $val;
                                    }
                                }

                            }

                        } elseif((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != html_ajax_json_in_str)) { // found a quote, and we are not inside a string
                            array_push($stk, array('what' => html_ajax_json_in_str, 'where' => $c, 'delim' => $chrs{$c}));
                            //print("found start of string at {$c}\n");

                        } elseif(($chrs{$c} == $top['delim']) && ($top['what'] == html_ajax_json_in_str) && (($chrs{$c - 1} != "\\") || ($chrs{$c - 1} == "\\" && $chrs{$c - 2} == "\\"))) { // found a quote, we're in a string, and it's not escaped
                            array_pop($stk);
                            //print("found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");

                        } elseif(($chrs{$c} == '[') && in_array($top['what'], array(html_ajax_json_slice, html_ajax_json_in_arr, html_ajax_json_in_obj))) { // found a left-bracket, and we are in an array, object, or slice
                            array_push($stk, array('what' => html_ajax_json_in_arr, 'where' => $c, 'delim' => false));
                            //print("found start of array at {$c}\n");

                        } elseif(($chrs{$c} == ']') && ($top['what'] == html_ajax_json_in_arr)) { // found a right-bracket, and we're in an array
                            array_pop($stk);
                            //print("found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");

                        } elseif(($chrs{$c} == '{') && in_array($top['what'], array(html_ajax_json_slice, html_ajax_json_in_arr, html_ajax_json_in_obj))) { // found a left-brace, and we are in an array, object, or slice
                            array_push($stk, array('what' => html_ajax_json_in_obj, 'where' => $c, 'delim' => false));
                            //print("found start of object at {$c}\n");

                        } elseif(($chrs{$c} == '}') && ($top['what'] == html_ajax_json_in_obj)) { // found a right-brace, and we're in an object
                            array_pop($stk);
                            //print("found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");

                        } elseif(($substr_chrs_c_2 == '/*') && in_array($top['what'], array(html_ajax_json_slice, html_ajax_json_in_arr, html_ajax_json_in_obj))) { // found a comment start, and we are in an array, object, or slice
                            array_push($stk, array('what' => html_ajax_json_in_cmt, 'where' => $c, 'delim' => false));
                            $c++;
                            //print("found start of comment at {$c}\n");

                        } elseif(($substr_chrs_c_2 == '*/') && ($top['what'] == html_ajax_json_in_cmt)) { // found a comment end, and we're in one now
                            array_pop($stk);
                            $c++;

                            for($i = $top['where']; $i <= $c; $i++)
                                $chrs = substr_replace($chrs, ' ', $i, 1);

                            //print("found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");

                        }

                    }

                    if(reset($stk) == html_ajax_json_in_arr) {
                        return $arr;

                    } elseif(reset($stk) == html_ajax_json_in_obj) {
                        return $obj;

                    }
                }
        }
    }
}

if ( !function_exists("json_encode") || !function_exists("json_decode") ) {
    include_once "json.php";
    function json_encode($data) {
        $json = new html_ajax_json();
        return $json->encode($data);
    }
    function json_decode($data) {
        $json = new html_ajax_json();
        return $json->decode($data);
    }
}
?>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网