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

PHP嗅探youku视频的真实flv文件地址!

May 25, 2016 pm 04:44 PM
explode foreach iconv preg_match substr

认识几个做视频网站的站长他们的视频电影都是来自于我们国内的几大视频网站了,有一站长要我帮助它做一个可以自动测试出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);
?>
Copy after login

这个测试出来的只是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;
}
?>
Copy after login

调用方法:

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

访问: 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 of this Website
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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the difference between using foreach and iterator to delete elements when traversing Java ArrayList? What is the difference between using foreach and iterator to delete elements when traversing Java ArrayList? Apr 27, 2023 pm 03:40 PM

1. The difference between Iterator and foreach is the polymorphic difference (the bottom layer of foreach is Iterator) Iterator is an interface type, it does not care about the type of collection or array; both for and foreach need to know the type of collection first, even the type of elements in the collection; 1. Why is it said that the bottom layer of foreach is the code written by Iterator: Decompiled code: 2. The difference between remove in foreach and iterator. First, look at the Alibaba Java Development Manual, but no error will be reported in case 1, and an error will be reported in case 2 (java. util.ConcurrentModificationException) first

How to determine the number of foreach loop in php How to determine the number of foreach loop in php Jul 10, 2023 pm 02:18 PM

​The steps for PHP to determine the number of the foreach loop: 1. Create an array of "$fruits"; 2. Create a counter variable "$counter" with an initial value of 0; 3. Use "foreach" to loop through the array, and Increase the value of the counter variable in the loop body, and then output each element and their index; 4. Output the value of the counter variable outside the "foreach" loop to confirm which element the loop reaches.

Recommended essential functions for Chinese processing: Detailed explanation of PHP iconv function Recommended essential functions for Chinese processing: Detailed explanation of PHP iconv function Jun 27, 2023 pm 02:04 PM

In the process of text processing, it is a common requirement to convert strings in different encoding formats. The iconv (InternationalizationConversion) function provided in the PHP language can meet this need very conveniently. This article will introduce the use of iconv function in detail from the following aspects: Definition of iconv function and introduction to common parameters Example demonstration: Convert GBK encoded string to UTF-8 encoded string Example demonstration: Convert UTF

PHP returns an array with key values ​​flipped PHP returns an array with key values ​​flipped Mar 21, 2024 pm 02:10 PM

This article will explain in detail how PHP returns an array after key value flipping. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP Key Value Flip Array Key value flip is an operation on an array that swaps the keys and values ​​in the array to generate a new array with the original key as the value and the original value as the key. Implementation method In PHP, you can perform key-value flipping of an array through the following methods: array_flip() function: The array_flip() function is specially used for key-value flipping operations. It receives an array as argument and returns a new array with the keys and values ​​swapped. $original_array=[

How to use PHP explode function and solve errors How to use PHP explode function and solve errors Mar 10, 2024 am 09:18 AM

The explode function in PHP is a function used to split a string into an array. It is very common and flexible. In the process of using the explode function, we often encounter some errors and problems. This article will introduce the basic usage of the explode function and provide some methods to solve the error reports. 1. Basic usage of the explode function In PHP, the basic syntax of the explode function is as follows: explode(string$separator,string$stri

Introduction to iconv command under CentOS Introduction to iconv command under CentOS Dec 29, 2023 pm 07:52 PM

iconv-fencoding[-tencoding][inputfile]...[Function] Converts the contents of a given file from one encoding to another. [Description]-fencoding: Convert characters from encoding to encoding. -tencoding: Convert characters to encoding. -l: List the known set of encoded characters -ofile: Specify the output file -c: Ignore illegal characters in the output -s: Suppress warning messages, but not error messages --verbose: Display progress information -f and -t can The specified legal characters are listed in the command with the -l option. [Example]* List currently supported character encodings

Split and merge strings using the explode and implode functions Split and merge strings using the explode and implode functions Jun 15, 2023 pm 08:42 PM

In PHP programming, processing strings is a frequently required operation. Among them, splitting and merging strings are two common requirements. In order to perform these operations more conveniently, PHP provides two very practical functions, namely the explode and implode functions. This article will introduce the usage of these two functions, as well as some practical skills. 1. The explode function The explode function is used to split a string according to the specified delimiter and return an array. Its function prototype is as follows: arra

PHP returns the ASCII value of the first character of the string PHP returns the ASCII value of the first character of the string Mar 21, 2024 am 11:01 AM

This article will explain in detail the ASCII value of the first character of the string returned by PHP. The editor thinks it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP returns the ASCII value of the first character of a string Introduction In PHP, getting the ASCII value of the first character of a string is a common operation that involves basic knowledge of string processing and character encoding. ASCII values ​​are used to represent the numeric value of characters in computer systems and are critical for character comparison, data transmission and storage. The process of getting the ASCII value of the first character of a string involves the following steps: Get String: Determine the string for which you want to get the ASCII value. It can be a variable or a string constant

See all articles