PHP obtains the Flash playback addresses on the pages of Major video websites.

Source: Internet
Author: User
Tags iqiyi

Many of our friends directly use the flash playback address of a large video website for movie websites. If this does not affect our server, the following section describes how to use PHP to obtain the Flash playback address instances on the pages of Major video websites.

First look at a simple

Then I implemented this function using PHP. I think it is a pleasure to use PHP to do this job! With its powerful HTML page processing functions and regular expressions, you can use this function with just a few lines of code.

Paste the key code:

The Code is as follows: Copy code

<? Php

// Obtain the flash Address on the Youku page
Function get_flash_url ($ url)
{
$ Lines = file ($ url );
Foreach ($ lines as $ linenum => $ line ){
Preg_match_all ('| <input type = "text" id = "link2" value = "([^ <>] +)"/> |', $ line, $ result );
$ Swfurl = $ result [1] [0];
If (! Empty ($ swfurl ))
Return $ swfurl;
}
}
?>

<? Php

$ Url = $ _ SERVER ["QUERY_STRING"];
 
$ Flashurl = get_flash_url ($ url );
 
Echo ($ flashurl );
 
?>

For example, if we store this file as test. php, we only need to run test. php? The url of youku video can parse the FLASH Address.

 

The idea is simple. First, let's look at the key FLASH Address section in the HTML code of Youku's video webpage. Find a webpage. For example, we can see this section:

The Code is as follows: Copy code

<Div class = "item"> <span class = "label"> flash Address: </span> <input type = "text" id = "link2" value = "http://player.youku.com/player.php/sid/XMTU1MzcxMzAw/v.swf"/>

Then, use the regular expression to match the address segment, and then click OK. The above is only a single one, and then find an upgrade method, you can automatically obtain the flash video playback addresses of Major video websites.

Currently, it supports video playback page links for Sina podcasts, Youku, Tudou, cool 6, Sohu, 56, Qiyi, and Phoenix.

The Code is as follows: Copy code
<? Php
If (! Empty ($ _ GET ['url'])
{
$ Web_video = new free_flash_video ();
$ Web_video-> index ();
}
/**
* Get the video address
* @ Author qiufeng <fengdingbo@gmail.com>
* @ Link http://www.fengdingbo.com
*
*/
Class free_flash_video {
 
Public function index ()
{
// Obtain the normal video address
$ Url = $ _ GET ['url'];
If ($ url)
{
$ Parse = parse_url ($ url );
 
Isset ($ parse ['host']) & $ host = $ parse ['host'];
 
$ Methods = array (
"Www.tudou.com" => "tudou ",
"V.youku.com" => "youku ",
"V.ku6.com" => "ku6 ",
"TV .sohu.com" => "sohu ",
"Video.sina.com.cn" => "sina ",
"Www.56.com" => "five_six ",
"Www.iqiyi.com" => "iqiyi ",
"V.ifeng.com" => "ifeng ",
"Www.yinyuetai.com" => "yinyuetai ",
);
 
Isset ($ methods [$ host]) & print_r ($ this-> $ methods [$ host] ($ url ));
 
}
}
 
/**
* Youku
* // Http://www.youku.com
* @ Param string $ url
*/
Private function youku ($ url)
{
Preg_match ('/id _ (. * pai.html/', $ url, $ url );
 
If (isset ($ url [1])
{
Return "http://static.youku.com/v/swf/qplayer.swf? VideoIDS = {$ url [1]} & = & isAutoPlay = true & embedid ";
}
}
 
/**
* Tudou
* // Http://www.tudou.com
* @ Param string $ url
*/
Private function tudou ($ url)
{
$ Data = file_get_contents ($ url );
// ID of the iid required to match the real url
 
Preg_match ('/iid :(. *)/', $ data, $ result );
If (isset ($ result [1])
{
$ Url = trim ($ result [1]);
Return "http://www.tudou.com/player/skin/plu.swf? Iid = {$ url }";
}
}
 
/**
* Cool 6 Network
* // Http://www.ku6.com
* @ Param string $ url
*/
Private function ku6 ($ url)
{
// Match the real url
Preg_match ('/show/(. *). {1}/', $ url, $ result );
 
If (isset ($ result [1])
{
Return "http://player.ku6.com/refer/?result=1}#/v.swf&auto=1 ";
}
}
 
/**
* Sohu video
* // Http:// TV .sohu.com
* @ Param string $ url
*/
Private function sohu ($ url)
{
$ Data = file_get_contents ($ url );
// Match the real url
Preg_match ('/<meta property = "og: video" content = "(. *)"/>/', $ data, $ result );
If (isset ($ result [1])
{
Return $ result [1];
}
}
 
/**
* Sina podcast
* // Http://video.sina.com.cn
* @ Param string $ url
*/
Private function sina ($ url)
{
$ Data = file_get_contents ($ url );
// Match the real url
Preg_match ("/swfOutsideUrl: '(. *)',/", $ data, $ result );
If (isset ($ result [1])
{
Return $ result [1];
}
}
 
/**
* 56 Network
* // Http://www.56.com
* @ Param string $ url
*/
Private function five_six ($ url)
{
// Retrieve the key required for the video
Preg_match ('/(v _. * example .html/', $ url, $ result );
 
If (isset ($ result [1])
{
Return "http://player.56.com/?result=1}}.swf ";
}
}
 
/**
* Qiyi net
* // Http://www.qiyi.com
* @ Param string $ url
*/
Private function iqiyi ($ url)
{
$ Data = file_get_contents ($ url );
 
// Retrieve the key required for the video
Preg_match ('/("videoId ":"(. *) ") | (data-player-videoid = "(. *) ")/U', $ data, $ result );
 
If (isset ($ result [4])
{
Return "http://www.iqiyi.com/player/20130315154043/SharePlayer.swf? Vid = {$ result [4]} ";
}
}
 
/**
* Phoenixnet
* // Http://www.ifeng.com
* @ Param string $ url
*/
Private function ifeng ($ url)
{
// Retrieve the key required for the video
Preg_match ('/d +/(. *)./', $ url, $ result );
 
If (isset ($ result [1])
{
Return "http://v.ifeng.com/include/exterior.swf? Guid = {$ result [1]} & fromweb = sinaweibo & AutoPlay = true ";
}
}
}
?>

Php api call instance

The Code is as follows: Copy code

/Tools/web_video.php? Url = video page address
Eg:/web_video.php? Url = http://www.iqiyi.com/dianying/20130217/e72ffd87c2e9c5af.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.