search
Homephp教程php手册PHP嗅探youku视频的真实flv文件地址!

认识几个做视频网站的站长他们的视频电影都是来自于我们国内的几大视频网站了,有一站长要我帮助它做一个可以自动测试出youku视频网站的flv真实地址,下面我整理了一下午解决了此问题非常的不错,大家可参考一下。

这个是借力打力,只是抓去朋友网的内容!!!

不过相当好用哦!

看代码:

<?php
$videourl = &#39;http://v.youku.com/v_show/id_XMjA5MjQ0OTQ0.html&#39;;
function get_content($url, $data) {
    if (is_array($data)) {
        $data = http_build_query($data, &#39;&#39;, &#39;&&#39;);
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $result = curl_exec($ch);
    return $result;
}
$str = get_content(&#39;http://share.pengyou.com/json.php?mod=usershare&act=geturlinfo&#39;, array(
    &#39;url&#39; => $videourl
));
$str = json_decode($str);
var_dump($str);
?>

这个测试出来的只是swf文件并不是我们要的flv文件了,后来参考一站长的写法进行了改进

核心代码:

<?php
function fetch_youku_flv($url) {
    preg_match("#id_(.*?).html#", $url, $out);
    $id = $out[1];
    $content = get_curl_contents(&#39;http://v.youku.com/player/getPlayList/VideoIDS/&#39; . $id);
    $data = json_decode($content);
    foreach ($data->data[0]->streamfileids AS $k => $v) {
        $sid = getSid();
        $fileid = getfileid($v, $data->data[0]->seed);
        $one = ($data->data[0]->segs->$k);
        if ($k == &#39;flv&#39; || $k == &#39;mp4&#39;) return "http://f.youku.com/player/getFlvPath/sid/{$sid}_00/st/{$k}/fileid/{$fileid}?K={$one[0]->k}";
        continue;
    }
}
function get_curl_contents($url, $second = 5) {
    if (!function_exists(&#39;curl_init&#39;)) die(&#39;php.ini未开启php_curl.dll&#39;);
    $c = curl_init();
    curl_setopt($c, CURLOPT_URL, $url);
    $UserAgent = $_SERVER[&#39;HTTP_USER_AGENT&#39;];
    curl_setopt($c, CURLOPT_USERAGENT, $UserAgent);
    curl_setopt($c, CURLOPT_HEADER, 0);
    curl_setopt($c, CURLOPT_TIMEOUT, $second);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    $cnt = curl_exec($c);
    $cnt = mb_check_encoding($cnt, &#39;utf-8&#39;) ? iconv(&#39;gbk&#39;, &#39;utf-8//IGNORE&#39;, $cnt) : $cnt; //字符编码转换
    curl_close($c);
    return $cnt;
}
function getSid() {
    $sid = time() . (rand(0, 9000) + 10000);
    return $sid;
}
function getkey($key1, $key2) {
    $a = hexdec($key1);
    $b = $a ^ 0xA55AA5A5;
    $b = dechex($b);
    return $key2 . $b;
}
function getfileid($fileId, $seed) {
    $mixed = getMixString($seed);
    $ids = explode("*", $fileId);
    unset($ids[count($ids) - 1]);
    $realId = "";
    for ($i = 0; $i < count($ids); ++$i) {
        $idx = $ids[$i];
        $realId.= substr($mixed, $idx, 1);
    }
    return $realId;
}
function getMixString($seed) {
    $mixed = "";
    $source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/:._-1234567890";
    $len = strlen($source);
    for ($i = 0; $i < $len; ++$i) {
        $seed = ($seed * 211 + 30031) % 65536;
        $index = ($seed / 65536 * strlen($source));
        $c = substr($source, $index, 1);
        $mixed.= $c;
        $source = str_replace($c, "", $source);
    }
    return $mixed;
}
?>

调用方法:

<?php
$url = &#39;http://v.youku.com/v_show/id_XMzg2OTQ3MjQw.html&#39;;
echo fetch_youku_flv($url);
?>

访问: http://xiaomizhou.net/demo/flv.php?url=http://v.youku.com/v_show/id_XMzg2OTQ3MjQw.html

输出的结果是:http://f.youku.com/player/getFlvPath/sid/138035737110468_00/st/flv/fileid/03000201004F97EF4A2E350467A09DB266E872-5522-225F-DC45-40B4E1F9BE49?K=c2a4327df2bb5a65261d40ea

这个是可以直接下载的!!


教程链接:

随意转载~但请保留教程地址★

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.