【转】NBB论坛BT文件信息获取实现方法

原理是利用某BT发布站的收集系统,通过文件的HASH码检索文件信息并保存为服务器本地XML文件,然后除了重新获取时皆以此XML文件为数据来源.因为此BT发布站的检索系统在白天较慢,所以不能实时获取信息,这样会导致页面打开速度的缓慢.

 VB/VB.NET 代码 
 
<!--#include file="Module/UBB.asp" --> 
<html><head> 
<title>查询torrent文件信息</title> 
<style type="text/css"> 
body{ 
    font-family:宋体; 
    font-size:12px; 

td{ 
    font-family:宋体; 
    font-size:12px; 
    BACKGROUND-COLOR: #FFFFFF; 

.bold{ 
    font-weight:bold; 
    font-family:宋体; 
    font-size:12px; 
    BACKGROUND-COLOR: #FFFFFF; 

.th{ 
    font-weight:bold; 
    font-family:宋体; 
    font-size:12px; 
    BACKGROUND-COLOR:#9CDCF1; 

</style> 
</head> 
<body> 
<% 
Hashcode = lcase(trim(request("hash"))) 
level = lcase(trim(request("level"))) 
if level = "" or not isnumeric(level) then 
    response.write "错误的附加参数" 
    response.end 
end if 
 
isreload = request("isreload") 
safestr = "qwertyuiopasdfghjklzxcvbnm1234567890" 
for i=1 to len(hashcode) 
    if instr(safestr,mid(hashcode,i,1)) < 1 then 
        response.write "错误的Hash码" 
        response.end 
    end if 
next 
 
hashfile = server.mappath("xml/" & Hashcode & ".xml") 
 
Set xml=Server.CreateObject("Microsoft.XMLDOM") 
xml.Async = False 
xml.ValidateOnParse = False 
xml.Load(hashfile) 
 
if (not (xml.ReadyState > 2)) or isreload = "1" then 
    Set http=Server.CreateObject("Microsoft.XMLHTTP") 
    http.Open "GET","
http://www2.sa20.com/btsearch0.php?keyword=" & Hashcode & "&type=2&show_query=1",False 
    http.send 
 
    Set s = server.createObject("ADODB.Stream") 
    s.type = 2 
    s.open 
    s.charset="gb2312" 
    s.writetext bin2str2(http.Responsebody) 
    s.savetofile hashfile,2 
    s.close 
    set http = nothing     
    xml.Load(hashfile) 
end if 
 
 
If xml.ReadyState > 2 Then 
        Set SearchResult = xml.getElementsByTagName("SearchResult") 
    If Cint(SearchResult.length) > 0 then 
            Set BTInfo = SearchResult.Item(0).getElementsByTagName("ResultSet").Item(0).getElementsByTagName("BTInfo") 
        Set Category = BTInfo.Item(0).getElementsByTagName("CategoryList").item(0).getElementsByTagName("Category") 
        Set Tinfo = BTInfo.Item(0).getElementsByTagName("TInfo") 
        FileName = BTInfo.Item(0).getElementsByTagName("FileName").item(0).text 
        Title = BTInfo.Item(0).getElementsByTagName("Title").item(0).text 
        Desc = UBBdecode(htmlencode(BTInfo.Item(0).getElementsByTagName("Desc").item(0).text)) 
        Sources = Tinfo.Item(0).getAttribute("Sources") 
        FileSize = ccur(BTInfo.Item(0).getAttribute("FSize")) 
        FileSize = FileSize / 1024 
        If FileSize > 1024 Then 
            FileSize = FileSize / 1024 
            If FileSize > 1024 Then 
                FileSize = FileSize / 1024 
                FileSize = FormatNumber(FileSize,2,-1) & " GB" 
            Else 
                FileSize = FormatNumber(FileSize,2,-1) & " MB" 
            End If 
        Else 
            FileSize = FormatNumber(FileSize,2,-1) & " KB" 
        End If 
        Connected =  Tinfo.Item(0).getAttribute("Connected") 
        Completed =  Tinfo.Item(0).getAttribute("Completed") 
        CategoryList = Category.item(2).text & " >> " & Category.item(1).text & " >> " & Category.item(0).text 
    Elseif isreload = "" then 
        Response.redirect("bt.asp?hash=" & Hashcode & "&level=" & level & "&isreload=1") 
    End If 
 
Else 
        Response.Write("发生意外,此次信息获取未能成功,请重试") 
    Response.End 
End If 
Set http=Nothing 
Set xml=Nothing 
 
Function bin2str2(binstr)  
Dim BytesStream,StringReturn  
 
Set BytesStream = server.createObject("ADODB.Stream")  
With BytesStream  
 .Type = 2 
 .Open  
 .WriteText binstr  
 .Position = 0  
 .Charset = "GB2312"  
 .Position = 2  
 StringReturn = .ReadText  
 .close  
End With  
Set BytesStream = Nothing  
 
bin2str2 = StringReturn  
 
End Function  
%> 
<table border=0 bgcolor=#666666 width=70% align=center cellspacing=1 cellpadding=5> 
<tr><td colspan=2 class=th>torrent文件信息 - <a href="?hash=<%=Hashcode%>&level=<%=level%>&isreload=1">重新获取</a></td></tr> 
<tr><td class=bold align=right nowrap width=60>标题</td><td width=100%><%=Title%></td></tr> 
<tr><td class=bold align=right nowrap width=60>大小</td><td width=100%><%=FileSize%></td></tr> 
<tr><td class=bold align=right nowrap width=60>种子数</td><td width=100%><font color=green><b><%=Sources%></b></font></td></tr> 
<tr><td class=bold align=right nowrap width=60>连接数</td><td width=100%><font color=red><b><%=Connected%></b></font></td></tr> 
<tr><td class=bold align=right nowrap width=60>完成数</td><td width=100%><font color=blue><b><%=Completed%></b></font></td></tr> 
<tr><td class=bold align=right nowrap width=60>类型</td><td width=100%><%=CategoryList%></td></tr> 
<tr><td class=bold align=right nowrap valign=top width=60>简介</td><td width=100%><%=Desc%></td></tr> 
<tr><td colspan=2 class=bold align=center><br><b><a href="javascript:self.close()">关闭窗口</a></b></td></tr> 
</table> 
</body></html> 



以下是更新帖子显示页的BT文件信息
 JAVA/J# 代码 
 
<script language=JavaScript> 
function senddata(){ 
    if(parent.BT<%=level%>Sources!=null) parent.BT<%=level%>Sources.innerHTML = '<font color=green><b><%=Sources%></b></font>'; 
    if(parent.BT<%=level%>Connected!=null) parent.BT<%=level%>Connected.innerHTML = '<font color=red><b><%=Connected%></b></font>'; 
    if(parent.BT<%=level%>Completed!=null) parent.BT<%=level%>Completed.innerHTML = '<font color=blue><b><%=Completed%></b></font>'; 
    if(parent.BT<%=level%>FileSize!=null) parent.BT<%=level%>FileSize.innerHTML = '<font color=black><b><%=FileSize%></b></font>'; 

senddata(); 
</script> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值