Example #1
0
 public static function getSrcSeedURL($btih)
 {
     global $USER_AGENT;
     /// 1. 从数据库中查询原始页面链接
     $res = get_by_btih($btih);
     if (!$res) {
         LOGW("BTIH 为 {$btih} 的资源在数据库中不存在");
         return FALSE;
     }
     /// 2. 获取 link 页面内容
     LOGI("正在获取动漫花园的资源页面内容: {$res['link']}");
     $content = NULL;
     $ch = curl_init($res['link']);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ch, CURLOPT_ENCODING, '');
     curl_setopt($ch, CURLOPT_USERAGENT, $USER_AGENT);
     $content = curl_exec($ch);
     if (!$content) {
         LOGE("无法抓取动漫花园的资源页面: {$res['link']}'");
         return FALSE;
     }
     /// 3. 解析 BT 地址
     $matches = [];
     $pattern = '/\\/\\/.+[a-f0-9]{40}\\.torrent/';
     $ret = preg_match($pattern, $content, $matches);
     if ($ret >= 1) {
         return 'http:' . $matches[0];
     } else {
         return FALSE;
     }
 }
Example #2
0
}
/// 1. 种子文件还未下载回本地,到源网站去下载
/// 检查 btih 合法性,btih 应该是一个长度为 40 的哈希字符串
$ret = preg_match('/^[0-9a-z]{40}$/', $btih);
if (!$ret) {
    LOGD("btih 非法:“{$btih}”,向用户返回 404");
    header('HTTP/1.1 404 Not Found');
    die('<h1>404 Not Found</h1>');
} else {
    $btih = strtolower($btih);
}
/// 2. 种子文件不存在,试图去源网站下载并保存
/// 2.1 解析种子地址
LOGD("请求的种子文件“{$btih}”不存在,尝试去源网站下载");
$url = "";
$res = get_by_btih($btih);
if (!$res) {
    LOGW("BTIH 为 {$btih} 的资源不存在");
    header('HTTP/1.1 404 Not Found');
    die('<h1>404 Not Found</h1> <h2>BTIH not exists</h2>');
}
switch ($res['src']) {
    case 'popgo':
        $url = Indexer_Popgo::getSrcSeedURL($btih);
        break;
    case 'dmhy':
        $url = Indexer_DMHY::getSrcSeedURL($btih);
        break;
    default:
        LOGE("代码不应执行到此处");
        $url = FALSE;