PHP提取emule下载ed2k链接

心血来潮,最近在电驴上下载高清资源---欧美高清MV-720P(http://www.verycd.com/files/fcc77802a50dcea22166f1f7141bff9048612903)。这个页面中右下角如下:


有很多类似的链接。现在就是要把这所有的ed2k链接都保存下来,然后批量下载,而不用一个一个点击下载。


由于上面的链接地址:http://www.verycd.com/files/fcc77802a50dcea22166f1f7141bff9048612903对应如下:

实际上就是对应的是:

现在要做的就是取回相关文件下的除了灰色部分的所有链接对应的页面内容,再从中取出相应的ed2k链接。

运行环境如下:

OS:Win7 Professional 64bit

Zend Studio 8.0.1

Zend Server Communication Edition: 5.5.0

代码如下:

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Input the initial url</title>
</head>
<body>
<form action="main.php" method="post" target="_blank">
Please input initial url:<br>
<font color="red">Example:http://www.verycd.com/files/7497c692fc812558e5ba0fc78d84fbf8310530048</font><br>

<textarea rows="10" cols="80" id="initial_url" name="initial_url"></textarea>
<br>
<br>
<input type="submit" value="Submit"/>
</form>

</body>
</html>

main.php

<?php
ob_start();
set_time_limit(0);
$url = $_POST["initial_url"];
//$url = "http://www.verycd.com/files/fb07beed85d207aa756abc998afecc9693668604";

echo "Original url:<br>".$url."<br>";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);

$content_fetched = curl_exec($ch);

if(false == $content_fetched)
{
	echo "Sorry, the request is error! Please try again!<br>";
	exit;
}

curl_close($ch);

$pattern = '#<a href="(http://www\.verycd\.com/files/[0-9A-Za-z]+)"#i';

preg_match_all($pattern, $content_fetched, $matches);

$ed2k_abstracted = array();

echo "Abstracted ed2k links as follows:<br>";

$all_ed2k_links = "";

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
for($i = 0; $i < count($matches[1]); $i++)
{
	curl_setopt($ch, CURLOPT_URL, $matches[1][$i]);
	$content_fetched = curl_exec($ch);
	/*
	 * <input type="button" class="downloadButton" 
	 * name="ed2k://|file|%5B%E8%BF%88%E5%85%8B%E5%B0%94%E6%9D%
	 * B0%E5%85%8B%E9%80%8A%E7%8F%8D%E8%B4%B5%E7%BD%95%E8%A7%81
	 * %E8%A7%86%E9%A2%91%E5%90%88%E9%9B%86%5D.Michael.Jackson.
	 * -.%5B01.American.Music.Awards.Dangerous.1993%5D.mv.mpg|3
	 * 10530048|7497c692fc812558e5ba0fc78d84fbf8|h=XMDFNICTGCNK
	 * X7AXRHTURXVBBAWXSRZF|/" id="downloadButton" 
	 * value="点击下载" />
	 */
	$pattern = '#ed2k[^"]+#i';
	preg_match($pattern, $content_fetched, $match);
	$ed2k_abstracted[] = $match[0];
	//Display them in the screen.
	echo "<font color=red>".$i.":</font>".$match[0]."<br>";
	$all_ed2k_links = $all_ed2k_links . $match[0]."\n";
}
curl_close($ch);
ob_end_flush();
/*
 * Save as ed2k_abstracted.txt.
 */
file_put_contents("ed2k_abstracted.txt", $all_ed2k_links, FILE_APPEND);

然后出现的很奇怪的问题:

首先碰到了php运行超时的问题。调试的时候一点儿问题都没有,运行的时候就是显示不出来结果。后来在main.php中增加set_time_limit(0);语句,结果还是不对,总是弹出一个main.php的对话框。查找各种日志文件后,在C:\Program Files (x86)\Zend\ZendServer\logs\ZendEnabler.log发现以下错误:

Request timed out during the communication with the PHP process。

Google之,终于在:http://kb.zend.com/index.php?View=entry&EntryID=476找到了答案。

重要摘抄如下:

A Server Error Appears During a Long Debug Session

Article ID: 476
Last updated: 27 Oct, 2010
Views: 3379

This article applies to:

[ Zend Server x.x, Zend Studio x.x ]
[ Windows ]


Symptom

An error message appears when remotely debugging a PHP application running on a Windows server. Depending on the Web server, the error is either the standard HTTP Error 500 or the Open/Save dialog prompting you to save an empty file:

Technical Details

This problem happens only on Windows with Zend Server installed and the PHP code is handled by FastCGI on this platform. The available FastCGI implementations are very limited in their ability to communicate with the Web server on one side, and with the PHP-CGI process on the other side. Therefore, during a long debug session the FastCGI process may reach its timeout while waiting for PHP to complete the debug session. The FastCGI may then return an error to the Web server even though the PHP process is still working.

Resolution / Workaround

To workaround this limitation, the user can increase the timeout value to a reasonably high number, thus eliminating the possibility that a timeout will occur. The instructions for all supported Web servers are given below. In all cases, restart the Web server after making the change.

Apache

If Zend Server is installed with the bundled Apache Web server, it uses the FastCGI component called Zend Enabler. Edit the configuration file of Zend Enabler as it appears in the below Listing (the timeout value is shown in bold):

Listing of <Zend Server installation directory>\etc\ZendEnablerConf.xml :
<?xml version="1.0" encoding="UTF-8"?>
<ZendEnablerConfiguration version="2.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="ZendEnablerConf.xsd">
  <Global>
    <LogFile path="C:\Program Files\Zend\ZendServer\logs\ZendEnabler.log"
      verbosity="0" maxFileSizeKB="100" />
  </Global>
  <DefaultPool impersonation="true">
    <Environment>
      <Variable name="DB2INSTANCE" value="DB2" />
      <Variable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
      <Variable name="TEMP" value="C:\DOCUME~1\user\LOCALS~1\Temp" />
      <Variable name="PHPRC" value="C:\Program Files\Zend\ZendServer\etc" />
      <Variable name="PATH"
        value="C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Zend\MySQL51\bin;C:\Program Files\Zend\ZendServer\bin" />
    </Environment>
    <ProcessCount start="2" extra="8" />
    <Timeouts connectionTimeout="60" requestTimeout="1200" />
  </DefaultPool>
  <ServerPool mimeType="application/x-httpd-php"
    commandLine="C:\Program Files\Zend\ZendServer\bin\php-cgi.exe"
    impersonation="true">
  </ServerPool>
</ZendEnablerConfiguration>
然后定位到该文件,修改 <Timeouts connectionTimeout="60" requestTimeout="1200" /><Timeouts connectionTimeout="60"requestTimeout="3600" />

It works! Great!


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
【概括介绍】 分享音乐,分享快乐。 【基本介绍】 《MTV分享精灵》是着名的高质MTV下载软件《MTV下载精灵》的P2P版,简称MTVP2P。软件基于全球最着名的eDonkey2000 network和Kademlia network网络技术开发,以便将我们“分享音乐,分享快乐”的理念传遍四方,让全球所有热爱音乐的朋友们方便快捷地分享珍藏的音乐。   《MTV分享精灵》2012版是一个绿色、免费软件,您可以自由下载安装。适合个人MV收藏\分享、在家KTV娱乐。   《MTV分享精灵》从2012年4月起,全面推行 绿色免安装版,请下载软件包后,直接解压到您喜欢的目录下,双击 MTVP2P.exe 文件,就可以打开《MTV分享精灵》2012版,享受“分享音乐,分享快乐”的乐趣!   202年2月9日发布,发布2012版,全新界面图标,新增MV批量下载功能,大幅修改软件内核,增强了P2P分享的能力,请所有新老用户都更新到2012版!   2011年11月30日发布,更新P2P搜索服务器,增强P2P搜索功能!   2011年9月27日发布,更新歌库,新增精灵助手程序,可自动修复精灵软件问题!   2011年4月1日发布,更新歌库,解决部分BUG!   2011年3月15日发布,提高了下载速度,增强了多线程下载能力,大幅更新了歌库,提高了下载速度,修正软件中的BUG!   2011年1月2日发布,解决自动关闭问题!   2009年12月27日发布1.1.10版,增加了MP2P搜索和第三方网络搜索,实现了不依靠服务器的生存能力,增强了精灵的稳定性,确保精灵在不稳定的网络中正常运行!   2009年10月3日发布1.03版,改进算法,提高下载速度,修正BUG,加强搜索栏功能! 【软件特点】   1、和《MTV下载精灵》实现了资源共享,可以直接下载《MTV下载精灵》中的6万部高质KTV,资源更丰富。   2、强大的搜索和多点下载功能,搜索更容易,下载速度更快,并增加了用户点评推荐功能。   3、强大的P2P文件共享技术和突破防火墙下载功能,让你在局域网内也下载无忧。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值