提交 2674875d 编写于 作者: H hjdhnx

大版本升级

上级 87e9cbb5
此差异已折叠。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File : ___init__.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date : 2022/8/27
from .cms import *
\ No newline at end of file
此差异已折叠。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File : config.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date : 2022/8/27
DIALECT = 'mysql'
DRIVER = 'pymysql'
USERNAME = 'gp'
PASSWORD = '123456'
HOST = '127.0.0.1'
PORT = '3306'
DATABASE = 'pira'
# DB_URI = '{}+{}://{}:{}@{}:{}/{}?charset=utf8'.format(DIALECT, DRIVER, USERNAME, PASSWORD, HOST, PORT, DATABASE)
DB_URI = 'sqlite:///models/rules.db?charset=utf8&check_same_thread=False'
SQLALCHEMY_DATABASE_URI = DB_URI
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_ECHO = False # 打印sql语句
JSON_AS_ASCII = False # jsonify返回的中文正常显示
PLAY_URL = 'http://cms.nokia.press' # 匹配远程解析服务器链接 远程接口主页地址,后面不能有/
PLAY_URL = PLAY_URL.rstrip('/')
HTTP_HOST = '0.0.0.0'
HTTP_PORT = '5705'
PLAY_DISABLE = False # 全局禁用播放解析
LAZYPARSE_MODE = 1 # 播放解析模式(0 本地 1 局域网 2远程 仅在全局禁用为False的时候生效)
WALL_PAPER_ENABLE = True # 启用自定义壁纸
WALL_PAPER = "https://picsum.photos/1280/720/?blur=10" # 自定义壁纸,可注释
SUP_PORT = 9001 # supervisord 服务端口
RETRY_CNT = 3 # 验证码重试次数
# OCR_API = 'http://192.168.3.224:9000/api/ocr_img' # 验证码识别接口,传参数data
OCR_API = 'http://dm.mudery.com:10000' # 验证码识别接口,传参数data
UNAME = 'admin' # 管理员账号
PWD = 'drpy' # 管理员密码
MAX_CONTENT_LENGTH = 1 * 1024 * 1024/100 # 100 kB
LIVE_MODE = 0 # 0 本地 1外网
LIVE_URL = 'https://gitcode.net/qq_26898231/TVBox/-/raw/main/live/zb.txt' # 初始化外网直播地址(后续在管理界面改)
CATE_EXCLUDE = '首页|留言|APP|下载|资讯|新闻|动态' # 动态分类过滤
# {% if config.WALL_PAPER %}"wallpaper":"{{ config.WALL_PAPER }}",{% endif %}
\ No newline at end of file
......@@ -5,6 +5,10 @@
# Date : 2022/8/25
import os
from time import time
import js2py
from utils.log import logger
from utils.web import get_interval,UA
def getRuleLists():
base_path = os.path.dirname(os.path.abspath(__file__)) # 当前文件所在目录
......@@ -16,5 +20,74 @@ def getRuleLists():
# print(rule_list)
return rule_list
def getRules(path='cache'):
t1 = time()
base_path = path+'/' # 当前文件所在目录
# print(base_path)
os.makedirs(base_path,exist_ok=True)
file_name = os.listdir(base_path)
file_name = list(filter(lambda x: str(x).endswith('.js') and str(x).find('模板') < 0, file_name))
# print(file_name)
rule_list = [file.replace('.js', '') for file in file_name]
js_path = [f'{path}/{rule}.js' for rule in rule_list]
with open('js/模板.js', encoding='utf-8') as f:
before = f.read()
rule_codes = []
# for js in js_path:
# with open(js,encoding='utf-8') as f:
# code = f.read()
# rule_codes.append(js2py.eval_js(before+code))
ctx = js2py.EvalJs()
codes = []
for i in range(len(js_path)):
js = js_path[i]
with open(js,encoding='utf-8') as f:
code = f.read()
codes.append(code.replace('rule',f'rule{i}',1))
newCodes = before + '\n'+ '\n'.join(codes)
# print(newCodes)
ctx.execute(newCodes)
for i in range(len(js_path)):
rule_codes.append(ctx.eval(f'rule{i}'))
# print(rule_codes)
# print(type(rule_codes[0]),rule_codes[0])
# print(rule_codes[0].title)
# print(rule_codes[0].searchable)
# print(rule_codes[0].quickSearch)
new_rule_list = []
for i in range(len(rule_list)):
new_rule_list.append({
'name':rule_list[i],
'searchable':rule_codes[i].searchable or 0,
'quickSearch':rule_codes[i].quickSearch or 0,
'filterable':rule_codes[i].filterable or 0,
})
# print(new_rule_list)
rules = {'list': new_rule_list, 'count': len(rule_list)}
logger.info(f'自动配置装载耗时:{get_interval(t1)}毫秒')
return rules
def getJxs(path='js'):
with open(f'{path}/解析.conf',encoding='utf-8') as f:
data = f.read().strip()
jxs = []
for i in data.split('\n'):
i = i.strip()
dt = i.split(',')
if not i.startswith('#'):
jxs.append({
'name':dt[0],
'url':dt[1],
'type':dt[2] if len(dt) > 2 else 0,
'ua':dt[3] if len(dt) > 3 else UA,
})
# jxs = [{'name':dt.split(',')[0],'url':dt.split(',')[1]} for dt in data.split('\n')]
# jxs = list(filter(lambda x:not str(x['name']).strip().startswith('#'),jxs))
# print(jxs)
print(f'共计{len(jxs)}条解析')
return jxs
if __name__ == '__main__':
print(getRuleLists())
\ No newline at end of file
3.1.7
\ No newline at end of file
3.2.0
\ No newline at end of file
此差异已折叠。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File : __init__.py.py
# File : __init__.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date : 2022/8/25
# Date : 2022/9/6
from . import rule_classes
from . import play_parse
from . import storage
\ No newline at end of file
from . import storage
from . import playparse
from . import ruleclass
无法预览此类型文件
......@@ -4,63 +4,61 @@
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date : 2022/9/6
from base.database import db
from functools import lru_cache
from utils.system import cfg
def init(db):
class Storage(db.Model):
__tablename__ = 'storage'
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
key = db.Column(db.String(20),unique=True)
value = db.Column(db.UnicodeText())
# value = db.Column(db.Text())
class Storage(db.Model):
__tablename__ = 'storage'
def __repr__(self):
return "<Storage(key='%s', value='%s')>" % (
self.key, self.value)
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
key = db.Column(db.String(20), unique=True)
value = db.Column(db.UnicodeText())
# value = db.Column(db.Text())
@classmethod
def setItem(self, key, value=None):
res = db.session.query(self).filter(self.key == key).first()
if res:
res.value = value
db.session.add(res)
else:
res = Storage(key=key, value=value)
db.session.add(res)
db.session.flush()
try:
db.session.commit()
self.clearCache()
return res.id
except Exception as e:
print(f'发生了错误:{e}')
return None
def __repr__(self):
return "<Storage(key='%s', value='%s')>" % (
self.key, self.value)
@classmethod
@lru_cache(maxsize=200)
def getItem(self, key, value=''):
res = db.session.query(self).filter(self.key == key).first()
if res:
return res.value or value
else:
return value
@classmethod
def clearItem(self, key):
@classmethod
def setItem(self, key, value=None):
res = db.session.query(self).filter(self.key == key).first()
if res:
res.value = value
db.session.add(res)
else:
res = Storage(key=key, value=value)
db.session.add(res)
db.session.flush()
try:
db.session.commit()
self.clearCache()
res = db.session.query(self).filter(self.key == key).first()
if res:
res.delete()
ret = db.session.commit()
self.clearCache()
return ret
else:
return True
return res.id
except Exception as e:
print(f'发生了错误:{e}')
return None
@classmethod
@lru_cache(maxsize=200)
def getItem(self, key, value=''):
res = db.session.query(self).filter(self.key == key).first()
if res:
return res.value or value
else:
return value
@classmethod
def clearCache(self):
self.getItem.cache_clear()
@classmethod
def clearItem(self, key):
self.clearCache()
res = db.session.query(self).filter(self.key == key).first()
if res:
res.delete()
ret = db.session.commit()
self.clearCache()
return ret
else:
return True
# db.create_all()
db.create_all()
return Storage
\ No newline at end of file
@classmethod
def clearCache(self):
self.getItem.cache_clear()
\ No newline at end of file
......@@ -52,6 +52,7 @@
- [X] 3.首页推荐内容不限制数量(新版pluto牛逼!!!)
- [X] 4.增加lsg配置模型和缓存
- [X] 5.增加了默认alist挂载
- [X] 6.升级到3.2.0,进行了全面后端重构用了蓝图写法,app.py文件以后尽量不动
###### 2022/09/05
- [X] 1.内置jar修复了原本tv_box无法播放直播的问题
- [X] 2.重新构建了三种平台的镜像 amd64,armv7,arm64
......
......@@ -91,7 +91,7 @@
form_data.append("file", file_data);
$.ajax({
type: "POST",
url: "/upload",
url: "/admin/upload",
dataType : "json",
processData: false, // 注意:让jQuery不要处理数据
contentType: false, // 注意:让jQuery不要设置contentType
......@@ -160,7 +160,7 @@ function getFileSize(fileObj) {
</h4>
<input id="live_url" value="{{live_url}}" style="display: none"/>
<p>你可以在此页面在线上传规则文件到js目录或者删除js目录的文件</p>
<form action = "/upload" method = "POST" enctype = "multipart/form-data">
<form action = "/admin/upload" method = "POST" enctype = "multipart/form-data">
<!-- <input type = "file" name = "file" class="btn" accept=".js" onchange="getFileSize(this)"/>-->
<input type = "file" name = "file" class="btn" onchange="getFileSize(this)"/>
<!-- <input type = "submit" value="上传" class="btn"/>-->
......
......@@ -3,7 +3,7 @@
"dr_count": {{rules.list|length}},
"mode": {{ mode }},
"spider": "{{ host }}/liveslib",
{% if alists|length > 0 %}"drives": {{alists}},{% endif %}
{% if alists|length > 0 %}"drives": {{alists_str}},{% endif %}
"homepage":"https://gitcode.net/qq_32394351/dr_py",
"sites": [{% for rule in rules.list %}{% if mode == 0 %}
{
......
......@@ -44,11 +44,12 @@
<a href="/admin">CMS后台管理</a>
</div>
<div class="btn">
<a href="/rules">缓存文件列表-清除</a>
<a href="/rules/view">缓存文件列表-查看</a>
</div>
<div class="btn">
<a href="/raw">缓存文件列表-查看</a>
<a href="/rules/clear">缓存文件列表-清除</a>
</div>
<div class="btn">
<a href="{{ getHost(0) }}/config/0">本地配置地址</a>
</div>
......
......@@ -69,7 +69,7 @@ $('#picture_autologin').attr('src',"/static/img/checked.png");
var json = {"username":username,"password":password,"autologin":autologin,"login":"1"};
// ajax_post("login.php",json,backmsg);
console.log(json);
$.post("/api/login",json,function(result){
$.post("/admin/login",json,function(result){
console.log(result);
if(result.code === 200){
console.log('登录成功');
......
{
"wallpaper": "http://localhost:5705/pics",
"dr_count": 20,
"dr_count": 21,
"mode": 0,
"spider": "http://localhost:5705/liveslib",
"drives": [
{
"name": "🔮嗨翻",
"server": "https://pan.hikerfans.com",
"type": "alist"
},
{
"name": "🦀9T(Adult)",
"server": "https://drive.9t.ee",
"type": "alist"
},
{
"name": "🐱梓澪の妙妙屋",
"server": "https://xn--i0v44m.xyz",
"type": "alist"
},
{
"name": "🚆资源小站",
"server": "https://pan.142856.xyz",
"type": "alist"
},
{
"name": "🌤晴园的宝藏库",
"server": "https://alist.52qy.repl.co",
"type": "alist"
},
{
"name": "🐭米奇妙妙屋",
"server": "https://anime.mqmmw.ga",
"type": "alist"
},
{
"name": "💂小兵组网盘影视",
"server": "https://6vv.app",
"type": "alist"
},
{
"name": "📀小光盘",
"server": "https://alist.xiaoguanxiaocheng.life",
"type": "alist"
},
{
"name": "🐋一只鱼",
"server": "https://alist.youte.ml",
"type": "alist"
},
{
"name": "🌊七米蓝",
"server": "https://al.chirmyram.com",
"type": "alist"
},
{
"name": "🌴非盘",
"server": "http://www.feifwp.top",
"type": "alist"
},
{
"name": "🥼帅盘",
"server": "https://hi.shuaipeng.wang",
"type": "alist"
},
{
"name": "🐉神族九帝",
"server": "https://alist.shenzjd.com",
"type": "alist"
},
{
"name": "☃姬路白雪",
"server": "https://pan.jlbx.xyz",
"type": "alist"
},
{
"name": "🎧听闻网盘",
"server": "https://wangpan.sangxuesheng.com",
"type": "alist"
},
{
"name": "💾DISK",
"server": "http://124.222.140.243:8080",
"type": "alist"
},
{
"name": "🌨云播放",
"server": "https://quanzi.laoxianghuijia.cn",
"type": "alist"
},
{
"name": "✨星梦",
"server": "https://pan.bashroot.top",
"type": "alist"
},
{
"name": "🌊小江",
"server": "https://dyj.me",
"type": "alist"
},
{
"name": "💫触光",
"server": "https://pan.ichuguang.com",
"type": "alist"
},
{
"name": "🕵好汉吧",
"server": "https://8023.haohanba.cn",
"type": "alist"
},
{
"name": "🥗AUNEY",
"server": "http://121.227.25.116:8008",
"type": "alist"
},
{
"name": "🎡资源小站",
"server": "https://960303.xyz/",
"type": "alist"
},
{
"name": "🏝fenwe",
"server": "http://www.fenwe.tk:5244",
"type": "alist"
},
{
"name": "🎢轻弹浅唱",
"server": "https://g.xiang.lol",
"type": "alist"
}
],
"homepage": "https://gitcode.net/qq_32394351/dr_py",
"sites": [
{
......@@ -112,6 +240,15 @@
"quickSearch": 0,
"filterable": 0
},
{
"key": "dr_库马伊",
"name": "库马伊(道长)",
"type": 1,
"api": "http://localhost:5705/vod?rule=库马伊",
"searchable": 1,
"quickSearch": 1,
"filterable": 0
},
{
"key": "dr_影视工厂",
"name": "影视工厂(道长)",
......@@ -352,7 +489,7 @@
{
"name": "直播",
"urls": [
"proxy://do=live&type=txt&ext=aHR0cHM6Ly9naXRjb2RlLm5ldC9xcV8yNjg5ODIzMS9UVkJveC8tL3Jhdy9tYWluL2xpdmUvMDgzMHpiLnR4dA=="
"proxy://do=live&type=txt&ext=aHR0cDovL2xvY2FsaG9zdDo1NzA1L2xpdmVz"
]
}
]
......
{
"wallpaper": "http://192.168.3.224:5705/pics",
"dr_count": 20,
"dr_count": 21,
"mode": 1,
"spider": "http://192.168.3.224:5705/liveslib",
"drives": [
{
"name": "🔮嗨翻",
"server": "https://pan.hikerfans.com",
"type": "alist"
},
{
"name": "🦀9T(Adult)",
"server": "https://drive.9t.ee",
"type": "alist"
},
{
"name": "🐱梓澪の妙妙屋",
"server": "https://xn--i0v44m.xyz",
"type": "alist"
},
{
"name": "🚆资源小站",
"server": "https://pan.142856.xyz",
"type": "alist"
},
{
"name": "🌤晴园的宝藏库",
"server": "https://alist.52qy.repl.co",
"type": "alist"
},
{
"name": "🐭米奇妙妙屋",
"server": "https://anime.mqmmw.ga",
"type": "alist"
},
{
"name": "💂小兵组网盘影视",
"server": "https://6vv.app",
"type": "alist"
},
{
"name": "📀小光盘",
"server": "https://alist.xiaoguanxiaocheng.life",
"type": "alist"
},
{
"name": "🐋一只鱼",
"server": "https://alist.youte.ml",
"type": "alist"
},
{
"name": "🌊七米蓝",
"server": "https://al.chirmyram.com",
"type": "alist"
},
{
"name": "🌴非盘",
"server": "http://www.feifwp.top",
"type": "alist"
},
{
"name": "🥼帅盘",
"server": "https://hi.shuaipeng.wang",
"type": "alist"
},
{
"name": "🐉神族九帝",
"server": "https://alist.shenzjd.com",
"type": "alist"
},
{
"name": "☃姬路白雪",
"server": "https://pan.jlbx.xyz",
"type": "alist"
},
{
"name": "🎧听闻网盘",
"server": "https://wangpan.sangxuesheng.com",
"type": "alist"
},
{
"name": "💾DISK",
"server": "http://124.222.140.243:8080",
"type": "alist"
},
{
"name": "🌨云播放",
"server": "https://quanzi.laoxianghuijia.cn",
"type": "alist"
},
{
"name": "✨星梦",
"server": "https://pan.bashroot.top",
"type": "alist"
},
{
"name": "🌊小江",
"server": "https://dyj.me",
"type": "alist"
},
{
"name": "💫触光",
"server": "https://pan.ichuguang.com",
"type": "alist"
},
{
"name": "🕵好汉吧",
"server": "https://8023.haohanba.cn",
"type": "alist"
},
{
"name": "🥗AUNEY",
"server": "http://121.227.25.116:8008",
"type": "alist"
},
{
"name": "🎡资源小站",
"server": "https://960303.xyz/",
"type": "alist"
},
{
"name": "🏝fenwe",
"server": "http://www.fenwe.tk:5244",
"type": "alist"
},
{
"name": "🎢轻弹浅唱",
"server": "https://g.xiang.lol",
"type": "alist"
}
],
"homepage": "https://gitcode.net/qq_32394351/dr_py",
"sites": [
{
......@@ -112,6 +240,15 @@
"quickSearch": 0,
"filterable": 0
},
{
"key": "dr_库马伊",
"name": "库马伊(道长)",
"type": 1,
"api": "http://192.168.3.224:5705/vod?rule=库马伊",
"searchable": 1,
"quickSearch": 1,
"filterable": 0
},
{
"key": "dr_影视工厂",
"name": "影视工厂(道长)",
......@@ -352,7 +489,7 @@
{
"name": "直播",
"urls": [
"proxy://do=live&type=txt&ext=aHR0cHM6Ly9naXRjb2RlLm5ldC9xcV8yNjg5ODIzMS9UVkJveC8tL3Jhdy9tYWluL2xpdmUvMDgzMHpiLnR4dA=="
"proxy://do=live&type=txt&ext=aHR0cDovLzE5Mi4xNjguMy4yMjQ6NTcwNS9saXZlcw=="
]
}
]
......
{
"wallpaper": "http://cms.nokia.press/pics",
"dr_count": 20,
"dr_count": 21,
"mode": 1,
"spider": "http://cms.nokia.press/liveslib",
"drives": [
{
"name": "🔮嗨翻",
"server": "https://pan.hikerfans.com",
"type": "alist"
},
{
"name": "🦀9T(Adult)",
"server": "https://drive.9t.ee",
"type": "alist"
},
{
"name": "🐱梓澪の妙妙屋",
"server": "https://xn--i0v44m.xyz",
"type": "alist"
},
{
"name": "🚆资源小站",
"server": "https://pan.142856.xyz",
"type": "alist"
},
{
"name": "🌤晴园的宝藏库",
"server": "https://alist.52qy.repl.co",
"type": "alist"
},
{
"name": "🐭米奇妙妙屋",
"server": "https://anime.mqmmw.ga",
"type": "alist"
},
{
"name": "💂小兵组网盘影视",
"server": "https://6vv.app",
"type": "alist"
},
{
"name": "📀小光盘",
"server": "https://alist.xiaoguanxiaocheng.life",
"type": "alist"
},
{
"name": "🐋一只鱼",
"server": "https://alist.youte.ml",
"type": "alist"
},
{
"name": "🌊七米蓝",
"server": "https://al.chirmyram.com",
"type": "alist"
},
{
"name": "🌴非盘",
"server": "http://www.feifwp.top",
"type": "alist"
},
{
"name": "🥼帅盘",
"server": "https://hi.shuaipeng.wang",
"type": "alist"
},
{
"name": "🐉神族九帝",
"server": "https://alist.shenzjd.com",
"type": "alist"
},
{
"name": "☃姬路白雪",
"server": "https://pan.jlbx.xyz",
"type": "alist"
},
{
"name": "🎧听闻网盘",
"server": "https://wangpan.sangxuesheng.com",
"type": "alist"
},
{
"name": "💾DISK",
"server": "http://124.222.140.243:8080",
"type": "alist"
},
{
"name": "🌨云播放",
"server": "https://quanzi.laoxianghuijia.cn",
"type": "alist"
},
{
"name": "✨星梦",
"server": "https://pan.bashroot.top",
"type": "alist"
},
{
"name": "🌊小江",
"server": "https://dyj.me",
"type": "alist"
},
{
"name": "💫触光",
"server": "https://pan.ichuguang.com",
"type": "alist"
},
{
"name": "🕵好汉吧",
"server": "https://8023.haohanba.cn",
"type": "alist"
},
{
"name": "🥗AUNEY",
"server": "http://121.227.25.116:8008",
"type": "alist"
},
{
"name": "🎡资源小站",
"server": "https://960303.xyz/",
"type": "alist"
},
{
"name": "🏝fenwe",
"server": "http://www.fenwe.tk:5244",
"type": "alist"
},
{
"name": "🎢轻弹浅唱",
"server": "https://g.xiang.lol",
"type": "alist"
}
],
"homepage": "https://gitcode.net/qq_32394351/dr_py",
"sites": [
{
......@@ -112,6 +240,15 @@
"quickSearch": 0,
"filterable": 0
},
{
"key": "dr_库马伊",
"name": "库马伊(道长)",
"type": 1,
"api": "http://cms.nokia.press/vod?rule=库马伊",
"searchable": 1,
"quickSearch": 1,
"filterable": 0
},
{
"key": "dr_影视工厂",
"name": "影视工厂(道长)",
......@@ -352,7 +489,7 @@
{
"name": "直播",
"urls": [
"proxy://do=live&type=txt&ext=aHR0cHM6Ly9naXRjb2RlLm5ldC9xcV8yNjg5ODIzMS9UVkJveC8tL3Jhdy9tYWluL2xpdmUvMDgzMHpiLnR4dA=="
"proxy://do=live&type=txt&ext=aHR0cDovL2Ntcy5ub2tpYS5wcmVzcy9saXZlcw=="
]
}
]
......
......@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# File : log.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date : 2022/8/27
# Date : 2022/9/6
import os
import logging
......
......@@ -73,12 +73,9 @@ def copy_to_update():
# print(f'升级失败,找不到目录{dr_path}')
logger.info(f'升级失败,找不到目录{dr_path}')
return False
force_copy_files(os.path.join(dr_path, f'js'),os.path.join(base_path, f'js'))
force_copy_files(os.path.join(dr_path, f'classes'),os.path.join(base_path, f'classes'))
force_copy_files(os.path.join(dr_path, f'models'),os.path.join(base_path, f'models'))
force_copy_files(os.path.join(dr_path, f'static'),os.path.join(base_path, f'static'))
force_copy_files(os.path.join(dr_path, f'templates'),os.path.join(base_path, f'templates'))
force_copy_files(os.path.join(dr_path, f'utils'),os.path.join(base_path, f'utils'))
paths = ['js','models','controllers','libs','static','templates','utils']
for path in paths:
force_copy_files(os.path.join(dr_path, path),os.path.join(base_path, path))
return True
def download_new_version():
......
......@@ -2,14 +2,14 @@
# -*- coding: utf-8 -*-
# File : web.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date : 2022/8/25
# Date : 2022/9/6
import os
import socket
import hashlib
from werkzeug.utils import import_string
import psutil
from flask import request
from utils.log import logger
import hashlib
from time import time
from utils.system import cfg
MOBILE_UA = 'Mozilla/5.0 (Linux; Android 11; M2007J3SC Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045714 Mobile Safari/537.36'
PC_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36'
UA = 'Mozilla/5.0'
......@@ -18,88 +18,40 @@ headers = {
'Referer': 'https://www.baidu.com',
'user-agent': UA,
}
from time import time
import config as settings
def get_host_ip2(): # 获取局域网ip
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# print('8888')
s.connect(('8.8.8.8', 80)) # 114.114.114.114也是dns地址
ip = s.getsockname()[0]
finally:
s.close()
return ip
def get_host_ip_old(): # 获取局域网ip
from netifaces import interfaces, ifaddresses, AF_INET
ips = []
for ifaceName in interfaces():
addresses = ''.join([i['addr'] for i in ifaddresses(ifaceName).setdefault(AF_INET, [{'addr': ''}])])
ips.append(addresses)
real_ips = list(filter(lambda x:x and x!='127.0.0.1',ips))
# logger.info(real_ips)
jyw = list(filter(lambda x:str(x).startswith('192.168'),real_ips))
return real_ips[-1] if len(jyw) < 1 else jyw[0]
def get_host_ip(): # 获取局域网ip
netcard_info,ips = get_wlan_info()
# print(netcard_info)
real_ips = list(filter(lambda x: x and x != '127.0.0.1', ips))
jyw = list(filter(lambda x: str(x).startswith('192.168'), real_ips))
return real_ips[-1] if len(jyw) < 1 else jyw[0]
def get_wlan_info():
info = psutil.net_if_addrs()
# print(info)
netcard_info = []
ips = []
for k, v in info.items():
for item in v:
if item[0] == 2:
netcard_info.append((k, item[1]))
ips.append(item[1])
return netcard_info,ips
def getHost(mode=0,port=None):
port = port or request.environ.get('SERVER_PORT')
# hostname = socket.gethostname()
# ip = socket.gethostbyname(hostname)
# ip = request.remote_addr
# print(ip)
# mode 为0是本地,1是局域网 2是线上
if mode == 0:
host = f'http://localhost:{port}'
elif mode == 1:
REAL_IP = get_host_ip()
ip = REAL_IP
host = f'http://{ip}:{port}'
def getParmas(key=None,value=''):
"""
获取链接参数
:param key:
:return:
"""
content_type = request.headers.get('Content-Type')
args = {}
if request.method == 'POST':
if 'application/x-www-form-urlencoded' in content_type or 'multipart/form-data' in content_type:
args = request.form
elif 'application/json' in content_type:
args = request.json
elif 'text/plain' in content_type:
args = request.data
else:
args = request.args
elif request.method == 'GET':
args = request.args
if key:
return args.get(key,value)
else:
host = get_conf(settings).get('PLAY_URL','http://cms.nokia.press')
return host
def get_conf(obj):
new_conf = {}
if isinstance(obj, str):
config = import_string(obj)
for key in dir(obj):
if key.isupper():
new_conf[key] = getattr(obj, key)
# print(new_conf)
return new_conf
def get_interval(t):
interval = time() - t
interval = round(interval*1000,2)
return interval
return args
def md5(str):
return hashlib.md5(str.encode(encoding='UTF-8')).hexdigest()
def verfy_token(token=''):
if not token or len(str(token))!=32:
def verfy_token(token=None):
if not token:
cookies = request.cookies
token = cookies.get('token', '')
if not token or len(str(token)) != 32:
return False
cfg = get_conf(settings)
username = cfg.get('UNAME','')
pwd = cfg.get('PWD','')
ctoken = md5(f'{username};{pwd}')
......@@ -108,6 +60,11 @@ def verfy_token(token=''):
return False
return True
def get_interval(t):
interval = time() - t
interval = round(interval*1000,2)
return interval
def getHeaders(url):
headers = {}
if url:
......@@ -115,27 +72,4 @@ def getHeaders(url):
headers.setdefault("User-Agent", PC_UA)
headers.setdefault("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
headers.setdefault("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2")
return headers
def getAlist():
base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录
alist_path = os.path.join(base_path, 'js/alist.conf')
with open(alist_path,encoding='utf-8') as f:
data = f.read().strip()
alists = []
for i in data.split('\n'):
i = i.strip()
dt = i.split(',')
if not i.strip().startswith('#'):
obj = {
'name': dt[0],
'server': dt[1],
'type':"alist",
}
if len(dt) > 2:
obj.update({
'password': dt[2]
})
alists.append(obj)
print(f'共计{len(alists)}条alist记录')
return alists
\ No newline at end of file
return headers
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册