/** * 解析 POPGO 的 HTML 页面,提取 link,btih,magnet,并自动生成 guid 等信息 * * @return array 成功返回数组,失败时会输出错误信息,并返回空数组 */ function popgo_parse_html($content) { require_once 'phpQuery/phpQuery.php'; $dom = phpQuery::newDocumentHTML($content); if (!$dom) { LOGE("无法解析漫游页面,原始内容:" . $content); return array(); } $ret = array(); for ($i = 0; $i < $dom->find('#index_maintable tr')->length(); $i++) { $pubDate = $dom->find("#index_maintable tr")->eq($i)->find("td")->eq(1)->text(); $title = $dom->find("#index_maintable tr")->eq($i)->find("td.inde_tab_seedname")->text(); $magnet = $dom->find("#index_maintable tr")->eq($i)->find("td")->eq(9)->find("a")->attr("href"); $link = $dom->find("#index_maintable tr")->eq($i)->find("td")->eq(3)->find("a")->attr("href"); $btih = popgo_get_btih_from_link($link); /// 针对 pubDate 格式的一点调整 $pubDate = '20' . substr($pubDate, 0, 8) . ' ' . substr($pubDate, 8); if (stripos($title, '置顶') !== FALSE) { continue; } if ($title == '') { continue; } $ret[] = array('title' => $title, 'magnet' => $magnet, 'link' => 'http://share.popgo.org' . $link, 'guid' => popgo_get_seed_url($btih), 'pubDate' => strtotime($pubDate), 'btih' => $btih); } return $ret; }
<?php /** * popgo-gone 版本之后,b_resource 表中的 btih 字段变为 UNIQUE 索引,该脚本用于更新 btih 为空的行,以便修改 btih 索引为 UNIQUE 索引 */ require_once '../header.php'; $sql = "SELECT * FROM b_resource WHERE src='popgo' AND btih=''"; $res = $mysqli->query($sql) or die($mysqli->error); if (!$res) { LOGI("已经没有需要更新的资源了"); exit(0); } LOGI(sprintf("需要更新 %d 个资源", $res->num_rows)); while ($row = $res->fetch_assoc()) { $btih = popgo_get_btih_from_link($row['guid']); $sql = "UPDATE b_resource SET btih='{$btih}' WHERE resource_id={$row['resource_id']}"; $mysqli->query($sql) or die($mysqli->error); }