Permalink
Browse files

aria2 -i export, command build with custom script

  • Loading branch information...
1 parent 36e547f commit 70611e4b5a6f348bb4b1ccda03cb2979b0f61e36 Binux committed Feb 5, 2012
Showing with 171 additions and 174 deletions.
  1. +16 −0 handlers/files.py
  2. +1 −1 libs/db_task_manager.py
  3. +78 −0 static/js/common.js
  4. +45 −89 templates/lixian.html
  5. +31 −84 templates/share.html
View
@@ -30,11 +30,26 @@ def get(self, task_id):
files = self.task_manager.get_file_list(task_id)
if files is None:
raise HTTPError(500)
+ if files == []:
+ raise HTTPError(404)
self.set_header("Content-Type", "application/octet-stream")
for f in files:
self.write(template % (f.lixian_url, self.task_manager.gdriveid))
+class aria2cExportHandler(BaseHandler):
+ def get(self, task_id):
+ template = "%s\r\n out=%s\r\n header=Cookie: gdriveid=%s\r\n continue=true\r\n max-connection-per-server=5\r\n split=10\r\n parameterized-uri=true\r\n\r\n"
+ files = self.task_manager.get_file_list(task_id)
+ if files is None:
+ raise HTTPError(500)
+ if files == []:
+ raise HTTPError(404)
+
+ self.set_header("Content-Type", "application/octet-stream")
+ for f in files:
+ self.write(template % (f.lixian_url.replace("gdl", "{gdl,dl.f,dl.g,dl.h,dl.i,dl.twin}"), f.dirtitle, self.task_manager.gdriveid))
+
class ShareHandler(BaseHandler):
def get(self, task_id):
task_id = int(task_id)
@@ -68,6 +83,7 @@ def get(self):
handlers = [
(r"/get_lixian_url", GetLiXianURLHandler),
(r"/export/"+options.site_name+"_idm_(\d+).*?\.ef2", IDMExportHandler),
+ (r"/export/"+options.site_name+"_aria2c_(\d+).*?\.down", aria2cExportHandler),
(r"/share/(\d+)", ShareHandler),
(r"/xss", XSSDoneHandler),
(r"/xssjs", XSSJSHandler),
View
@@ -106,7 +106,7 @@ def _update_task_list(self, limit=10, st=0, ignore=False):
self.last_task_id = task['task_id']
db_task_status = session.query(db.Task.status).filter(
db.Task.id == task['task_id']).first()
- if db_task_status and db_task_status[0] == "finished":
+ if db_task_status and db_task_status[0] == "finished" and self.last_task_id:
continue
db_task = db.Task()
View
@@ -0,0 +1,78 @@
+function escape_command(str) {
+ var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ var result = "";
+ for (var i = 0; i < str.length; i++) {
+ if (alpha.indexOf(str[i]) == -1)
+ result += "\\"+str[i];
+ else
+ result += str[i];
+ }
+ return result;
+};
+
+var LE = {
+ export: function(gen) {
+ LE.show(gen(LE.taskname, LE.links(), LE.cookie));
+ },
+ wget_links: function() {
+ LE.export(function(taskname, links, cookie) {
+ var str = "";
+ $.each(links, function(i, n) {
+ str += "wget -c -O "+escape_command(n.title)+" --header 'Cookie:"+cookie+";' '"+n.url+"'\n";
+ });
+ return str;
+ });
+ },
+ aria2_links: function() {
+ function multiple_server_fix(url) {
+ return "'"+url.replace("gdl", "'{gdl,dl.{f,g,h,i,twin}}'")+"'";
+ }
+ LE.export(function(taskname, links, cookie) {
+ var str = "";
+ $.each(links, function(i, n) {
+ str += "aria2c -c -s10 -x10 --out "+escape_command(n.title)+" --header 'Cookie:"+cookie+";' "+multiple_server_fix(n.url)+"\n";
+ });
+ return str;
+ });
+ },
+
+ default_script: function sample(taskname, links, cookie) {
+ var str = "====== sample script ======\n";
+ str += "taskname = "+taskname+"\n";
+ str += "escape_command(taskname) = "+escape_command(taskname)+"\n";
+ str += "cookie = "+cookie+"\n";
+ str += "==========================\n";
+ $.each(links, function(i, n) {
+ str += "links["+i+"].title = "+n.title+"\n";
+ str += "links["+i+"].url = "+n.url+"\n";
+ });
+ return str;
+},
+ custom: function() {
+ LE.export(LE.custom_script || LE.default_script);
+ },
+};
+if (localStorage && localStorage.custom_script) {
+ eval("LE.custom_script = "+localStorage.custom_script);
+}
+
+var LS = {
+ share: function(url) {
+ window.open(url,"","width=480,height=480,left="+Number((window.screen.width-480)/2)+",top="+Number((window.screen.width-480)/2)+",scrollbars=no");
+ },
+ share_google: function() {
+ LS.share("https://plusone.google.com/_/+1/confirm?url="+LS.share_url+"&title="+LS.share_title);
+ },
+ share_twitter: function() {
+ LS.share("https://twitter.com/intent/tweet?source=webclient&text="+LS.share_title+"&url="+LS.share_url);
+ },
+ share_sina: function() {
+ LS.share("http://v.t.sina.com.cn/share/share.php?url="+LS.share_url+"&title="+LS.share_title);
+ },
+ share_qq: function() {
+ LS.share("http://v.t.qq.com/share/share.php?url="+LS.share_url+"&title="+LS.share_title);
+ },
+ share_douban: function() {
+ LS.share("http://www.douban.com/recommend/?url="+LS.share_url+"&title="+LS.share_title);
+ },
+};
View
@@ -7,6 +7,27 @@
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script> !window.jQuery && document.write('<script type="text/javascript" src=\"{{static_url("js/jquery-1.4.3.min.js")}}\"><\/script>'); </script>
<script type="text/javascript" src="{{static_url('js/fancybox/jquery.fancybox-1.3.4.pack.js')}}"></script>
+<script type="text/javascript" src="{{static_url('js/common.js')}}"></script>
+<script type="text/javascript">
+ LE.taskname = {% raw json_encode(task.taskname) %};
+ LE.links = function () {
+ var result = [];
+ $.each($("ul.file-list a"), function(i, n) {
+ n = $(n);
+ result.push({url: n.attr("href"), title: n.text()});
+ });
+ return result;
+ };
+ LE.cookie = "{{ cookie }}".split(";")[0];
+ LE.show = function(str) {
+ $("#link-text").val(str);
+ $(".file-list").hide();
+ $("#link-text").show();
+ $("#link-text").get(0).style.height=$("#link-text").get(0).scrollHeight+"px"
+ };
+ LS.share_url = {% raw json_encode(request.protocol+"://"+request.host+"/share/"+str(task.id)) %};
+ LS.share_title = {% raw json_encode(task.taskname+u" - 迅雷离线下载分享 - "+options.site_name) %};
+</script>
<link rel="stylesheet" href="{{static_url('js/fancybox/jquery.fancybox-1.3.4.css')}}" type="text/css" media="screen" />
<link rel="canonical" href="{{ request.protocol }}://{{ request.host }}/share/{{ task.id }}" />
{% end %}
@@ -23,20 +44,20 @@
<div id="share-button" class="task-button">
<a href="/share/{{ task.id }}" target="_blank"><div>分享</div></a>
<div id="share-links" class="more-links" style="display: none;">
- <a href="javascript:share_google();" title="分享到 Google+"><div class="task-button">Google+</div></a>
- <a href="javascript:share_twitter();" title="分享到 Twitter+"><div class="task-button">Twitter</div></a>
- <a href="javascript:share_sina();" title="分享到 新浪微博"><div class="task-button">新浪微博</div></a>
- <a href="javascript:share_qq();" title="分享到 腾讯微博"><div class="task-button">腾讯微博</div></a>
- <a href="javascript:share_douban();" title="分享到 豆瓣"><div class="task-button">豆瓣</div></a>
+ <a href="javascript:LS.share_google();" title="分享到 Google+"><div class="task-button">Google+</div></a>
+ <a href="javascript:LS.share_twitter();" title="分享到 Twitter+"><div class="task-button">Twitter</div></a>
+ <a href="javascript:LS.share_sina();" title="分享到 新浪微博"><div class="task-button">新浪微博</div></a>
+ <a href="javascript:LS.share_qq();" title="分享到 腾讯微博"><div class="task-button">腾讯微博</div></a>
+ <a href="javascript:LS.share_douban();" title="分享到 豆瓣"><div class="task-button">豆瓣</div></a>
</div>
</div>
<div id="batch-button" class="task-button">
<div>批量下载</div>
<div id="batch-links" class="more-links" style="display: none;">
- <!--<a href="#" onclick="copy_links(); return false;"><div class="task-button">copy</div></a>-->
- <a href="#" onclick="wget_links(); return false"><div class="task-button">wget</div></a>
- <a href="#" onclick="aria2_links(); return false"><div class="task-button">aria2 x6</div></a>
+ <a href="javascript:LE.wget_links();"><div class="task-button">wget</div></a>
+ <a href="javascript:LE.aria2_links();"><div class="task-button">aria2x10</div></a>
<a href="/export/{{ url_escape(options.site_name) }}_idm_{{ task.id }}_{{ url_escape(task.taskname.replace(" ", "_")) }}.ef2"><div class="task-button">IDM 导出</div></a>
+ <a href="/export/{{ url_escape(options.site_name) }}_aria2c_{{ task.id }}_{{ url_escape(task.taskname.replace(" ", "_")) }}.down"><div class="task-button">aria2导出</div></a>
</div>
</div>
{% else %}
@@ -96,89 +117,24 @@
$("#share-links").hide();
});
- function get_links() {
- var result = [];
- $.each($("ul.file-list a"), function(i, n) {
- n = $(n);
- result.push({url: n.attr("href"), title: n.text()});
- });
- return result;
- }
-
- function get_cookie() {
- return "{{ cookie }}".split(";")[0];
- }
-
- var alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- function escape_command(str) {
- var result = "";
- for (var i = 0; i < str.length; i++) {
- if (alpha.indexOf(str[i]) == -1)
- result += "\\"+str[i];
- else
- result += str[i];
+ if (localStorage) {
+ var custom = '<a id="custom-button" title="双击编辑" href="javascript:LE.custom();"><div class="task-button">'+(LE.custom_script && LE.custom_script.name || '自定义')+'</div></a>';
+ if (LE.custom_script) {
+ $("#batch-links").prepend(custom);
+ } else {
+ $("#batch-links").append(custom);
}
- return result;
- }
-
- function copy_links() {
- $("ul.file-list").hide();
- var str = "";
- $.each(get_links(), function(i, n) {
- str += n.url+"\n";
+ $("#custom-button").dblclick(function() {
+ LE.show(LE.custom_script && LE.custom_script.toString() || LE.default_script.toString());
+ $("#link-text").change(function() {
+ localStorage.custom_script = $("#link-text").val();
+ if (localStorage.custom_script)
+ eval("LE.custom_script = "+localStorage.custom_script);
+ else
+ LE.custom_script = undefined;
+ $("#link-text").unbind();
+ });
});
- $("#link-text").text(str);
- $("#link-text").show();
- $("#link-text").get(0).style.height=$("#link-text").get(0).scrollHeight+"px"
- }
-
- function wget_links() {
- $("ul.file-list").hide();
- var str = "";
- var cookie = get_cookie();
- $.each(get_links(), function(i, n) {
- str += "wget -c -O "+escape_command(n.title)+" --header 'Cookie:"+cookie+";' '"+n.url+"'\n";
- });
- $("#link-text").text(str);
- $("#link-text").show();
- $("#link-text").get(0).style.height=$("#link-text").get(0).scrollHeight+"px"
- }
-
- function multiple_server_fix(url) {
- return "'"+url.replace("gdl", "'{gdl,dl.{f,g,h,i,twin}}'")+"'";
- }
- function aria2_links() {
- $("ul.file-list").hide();
- var str = "";
- var cookie = get_cookie();
- $.each(get_links(), function(i, n) {
- str += "aria2c -c -s6 -x5 -j30 --out "+escape_command(n.title)+" --header 'Cookie:"+cookie+";' "+multiple_server_fix(n.url)+"\n";
- });
- $("#link-text").text(str);
- $("#link-text").show();
- $("#link-text").get(0).style.height=$("#link-text").get(0).scrollHeight+"px"
- }
-
- var w=480;
- var h=480;
- var x=Number((window.screen.width-w)/2);
- var y=Number((window.screen.height-h)/2);
- var share_url = {% raw json_encode(request.protocol+"://"+request.host+"/share/"+str(task.id)) %};
- var share_title = {% raw json_encode(task.taskname+u" - 迅雷离线下载分享 - "+options.site_name) %};
- function share_google() {
- window.open("https://plusone.google.com/_/+1/confirm?url="+share_url+"&title="+share_title,"","width="+w+",height="+h+",left="+x+",top="+y+",scrollbars=no");
- }
- function share_twitter() {
- window.open("https://twitter.com/intent/tweet?source=webclient&text="+share_title+"&url="+share_url,"","width="+w+",height="+h+",left="+x+",top="+y+",scrollbars=no");
- }
- function share_sina() {
- window.open("http://v.t.sina.com.cn/share/share.php?url="+share_url+"&title="+share_title,"","width="+w+",height="+h+",left="+x+",top="+y+",scrollbars=no");
- }
- function share_qq() {
- window.open("http://v.t.qq.com/share/share.php?url="+share_url+"&title="+share_title,"","width="+w+",height="+h+",left="+x+",top="+y+",scrollbars=no");
- }
- function share_douban() {
- window.open("http://www.douban.com/recommend/?url="+share_url+"&title="+share_title,"","width="+w+",height="+h+",left="+x+",top="+y+",scrollbars=no");
}
$("#disable-helper").fancybox();
Oops, something went wrong.

0 comments on commit 70611e4

Please sign in to comment.