2009年10月21日星期三

elinks handle ed2k for mldonkey by lua [让elinks 支持点击电驴连接就下载]

elinks handle ed2k for mldonkey by lua


OS:CentOS 5.3
需求来源:
此机器很大部分时间还是台电驴BT下载机。

有时候远程putty想加些mldonkey任务,一般可以通过mldonkey的 telnet console添加, 但是需要整理出ed2k的地址,然后dllink添加。特别是多个链接的时候特别麻烦。
如果可以直接在putty浏览网页时添加就最好不过了,console浏览器一般lnyx,elinks等等。
看了下下文 elinks和mldonkey工作的很好。
http://mldonkey.sourceforge.net/Browser_Integration

首先需要确定elinks的Lua脚本支持是否编译进去了(elinks 0.11目前只支持lua 5.0, 使用yum没办法,我用源代码编译的)。
[frank@CentOS5 mldonkeydown]$ elinks --version
ELinks 0.11.6.GIT (built on May 20 2009 13:06:33)

Features:
Standard, IPv6, gzip, bzip2, Periodic Saving, Timer, Cascading Style Sheets,
Protocol (File, FTP, HTTP, URI rewrite, User protocols), SSL (OpenSSL),
MIME (Option system, Mailcap, Mimetypes files), LED indicators, Bookmarks,
Cookies, Form History, Global History, Scripting (Lua), Goto URL History,
Search History

接下去就是关键的用户hooks.lua编写(位于~/.elinks/hooks.lua).
wiki上的脚本语法有问题,
花了两天看了些资料终于work拉。修改了下脚本使其支持ed2k的几种方式。
hooks.lua
1 function url_encode(text)
2 text = string.gsub(text, " ", "%%20")
3 -- text = string.gsub(text, "%:", "%%3A")
4 text = string.gsub(text, "%/", "%%2F")
5 text = string.gsub(text, "%||", "%%7C")
6 text = string.gsub(text, "%!", "%%21")
7 -- text = string.gsub(text, "%?", "%%AA")
8 text = string.gsub(text, "%&", "%%26")
9 return string.gsub(text, "%#", "%%23")
10 end
11
12 function follow_url_hook (url)
13 -- Detecting ed2k links
14 if string.find(url,"ed2k.-file|.-|%d-|%x-|/.*") then
15 -- ed2k link with h=XXX hash infor
16 text = url_encode(string.gsub(url, "(.-)ed2k.-file|(.-)|(%d-)|(%x-)|/.*", "dllink ed2k://|file|%2|%3|%4|/"))
17 return "http://127.0.0.1:40080/submit?q="..text
18 elseif string.find(url,"ed2k.-file|.-|%d-|%x-|.-|/.*") then
19 -- ed2k link without hash infor
20 text = url_encode(string.gsub(url, "(.-)ed2k.-file|(.-)|(%d-)|(%x-)|(.-)|/.*", "dllink ed2k://|file|%2|%3|%4|%5|/"))
21 return "http://127.0.0.1:40080/submit?q="..text
22 end
23 -- Return url without changes.
24 return url
25 end

看了下面这些资料:
Programming in Lua
lua reference
Beginning Lua Programming
http://en.wikipedia.org/wiki/Ed2k_link

没有评论:

回国科学上网姿势 软路由 通过apple私有Mac地址动态切换

回国科学上网姿势 软路由 通过apple私有Mac地址动态切换 断断续续的尝试了很多科学上网方式,自己搭VPS,家里路由器也升级了好几次,都是为了能装可以跑科学上网的固件,但是最大的问题是性能都一般,速度也不是很稳定。 最近软路由被提到较多,最吸引人的是可以达的速度非常高,可以看...