-
Notifications
You must be signed in to change notification settings - Fork 61
/
main.py
115 lines (104 loc) · 4.77 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#/usr/bin/env python
# -*- encoding: utf8 -*-
# author: binux<[email protected]>
import os
import tornado
import logging
from time import time
from tornado import web
from tornado.ioloop import IOLoop, PeriodicCallback
from tornado.options import define, options
from tornado.httpserver import HTTPServer
define("f", default="", help="config file path")
define("debug", default=True, help="debug mode")
define("port", default=8880, help="the port tornado listen to")
define("bind_ip", default="0.0.0.0", help="the bind ip")
define("username", help="xunlei vip login name")
define("password", help="xunlei vip password")
define("ga_account", default="", help="account of google analytics")
define("site_name", default="LOLI.LU", help="site name used in description")
define("cookie_secret", default="61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o",
help="key for HMAC")
define("check_interval", default=60*60,
help="the interval of checking login status")
define("cache_enabled", default=True,
help="enable mem cache")
define("cross_userscript", default="http://userscripts.org/scripts/show/117745",
help="the web url of cross cookie userscirpt")
define("cross_cookie_version", default="0.35",
help="cross cookie user script version")
define("cross_userscript_local", default="/static/cross-cookie.user.js",
help="the local path of cross cookie userscirpt")
define("cross_cookie_url", default="http://vip.xunlei.com/gen/yuanxun/gennew/newyx.html",
help="the url to insert to")
define("cookie_str", default="gdriveid=%s; path=/; domain=.vip.xunlei.com",
help="the cookie insert to cross path")
define("finished_task_check_interval", default=60*60,
help="the interval of getting the task list")
define("downloading_task_check_interval", default=5*60,
help="the interval of getting the downloading task list")
define("task_list_limit", default=500,
help="the max limit of get task list each time")
define("always_update_lixian_url", default=False,
help="always update lixian url")
define("database_echo", default=False,
help="sqlalchemy database engine echo switch")
define("database_engine", default="sqlite:///task_files.db",
help="the database connect string for sqlalchemy")
define("task_title_prefix", default="[loli.lu] ",
help="prefix of task")
define("using_xss", default=False,
help="use xss or cross-cookie")
define("using_xsrf", default=False,
help="using xsrf to prevent cross-site request forgery")
define("reg_key", default=None,
help="if setted new user is not allowed except login with '/login?key=<reg_key>'.")
define("enable_share", default=True, help="enable share task")
define("google_oauth_key", default=None, help="google oauth client id")
define("google_oauth_secret", default=None, help="google oauth client secret")
define("root_user_mode", default=False, help="everyone is root")
class Application(web.Application):
def __init__(self):
from handlers import handlers, ui_modules
from libs.util import ui_methods
from libs.db_task_manager import DBTaskManager
from libs.user_manager import UserManager
from libs.vip_pool import VIPool
settings = dict(
debug=options.debug,
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
cookie_secret=options.cookie_secret,
login_url="/login",
google_oauth={
"key": options.google_oauth_key,
"secret": options.google_oauth_secret,
},
ui_modules=ui_modules,
ui_methods=ui_methods,
)
super(Application, self).__init__(handlers, **settings)
self.user_manager = UserManager()
self.task_manager = DBTaskManager(
username = options.username,
password = options.password
)
self.vip_pool = VIPool()
if not self.task_manager.islogin:
raise Exception, "xunlei login error"
self.task_manager.async_update()
PeriodicCallback(self.task_manager.async_update,
options.downloading_task_check_interval * 1000).start()
PeriodicCallback(self.user_manager.reset_all_add_task_limit, 86400 * 1000).start()
logging.info("load finished! listening on %s:%s" % (options.bind_ip, options.port))
def main():
tornado.options.parse_command_line()
if options.f:
tornado.options.parse_config_file(options.f)
tornado.options.parse_command_line()
http_server = HTTPServer(Application(), xheaders=True)
http_server.bind(options.port, options.bind_ip)
http_server.start()
IOLoop.instance().start()
if __name__ == "__main__":
main()