提交 54a77836 编写于 作者: H hjdhnx

增加随机图片

上级 4c911e0f
......@@ -3,6 +3,7 @@
# File : app.py
# Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
# Date : 2022/8/25
import random
from flask_sqlalchemy import SQLAlchemy
import config
......@@ -155,6 +156,17 @@ def getRules(path='cache'):
rules = {'list': rule_list, 'count': len(rule_list)}
return rules
def getPics(path='images'):
base_path = 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)
pic_list = [base_path+file for file in file_name]
# pic_list = file_name
# print(type(pic_list))
return pic_list
def getJxs(path='js'):
with open(f'{path}/解析.txt',encoding='utf-8') as f:
data = f.read().strip()
......@@ -216,6 +228,18 @@ def rules():
def rules_raw():
return render_template('raw.html',rules=getRules(),classes=getClasses())
@app.route('/pics')
def random_pics():
pics = getPics()
if len(pics) > 0:
pic = random.choice(pics)
file = open(pic, "rb").read()
response = make_response(file)
response.headers['Content-Type'] = 'image/jpeg'
return response
else:
return redirect(config.WALL_PAPER)
@app.route('/config/<int:mode>')
def config_render(mode):
# print(dict(app.config))
......
......@@ -11,7 +11,7 @@ from utils.web import *
from models import *
from utils.config import config
from utils.log import logger
from utils.encode import base64Encode,baseDecode,fetch,post
from utils.encode import base64Encode,baseDecode,fetch,post,request
from utils.safePython import safePython
from utils.parser import runPy,runJScode
from utils.htmlParser import jsoup
......@@ -22,7 +22,7 @@ from easydict import EasyDict as edict
py_ctx = {
'requests':requests,'print':print,'base64Encode':base64Encode,'baseDecode':baseDecode,
'log':logger.info,'fetch':fetch,'post':post
'log':logger.info,'fetch':fetch,'post':post,'request':request
}
class CMS:
......@@ -648,7 +648,7 @@ class CMS:
loader,_ = runJScode(jscode,ctx=ctx)
# print(loader.toString())
play_url = loader.eval('input')
logger.info('免嗅播放地址:',play_url)
logger.info(f'免嗅播放地址:{play_url}')
return play_url
......
......@@ -20,4 +20,5 @@ JSON_AS_ASCII = False # jsonify返回的中文正常显示
# PLAY_URL = 'http://localhost:5705' # 匹配远程解析服务器链接
# PLAY_URL = PLAY_URL.rstrip('/')
PLAY_DISABLE = False # 全局禁用播放解析
WALL_PAPER = "https://picsum.photos/1280/720/?blur=10" # 自定义壁纸,可注释
\ No newline at end of file
WALL_PAPER = "https://picsum.photos/1280/720/?blur=10" # 自定义壁纸,可注释
# {% if config.WALL_PAPER %}"wallpaper":"{{ config.WALL_PAPER }}",{% endif %}
\ No newline at end of file
......@@ -14,7 +14,7 @@ var rule = {
// lazy:'干饭',
// lazy:'@js:cacheUrl = d.getParse(input);print(cacheUrl);input=cacheUrl',
// lazy:'js:cacheUrl = d.getParse(input);print(cacheUrl);input=cacheUrl',
lazy:'js:cacheUrl=d.getParse(input);if(cacheUrl){input=cacheUrl}else{try{let html=fetch(input,{headers:d.headers,timeout:d.timeout,encoding:d.encoding});let ret=html.match(/var player_(.*?)=(.*?)</)[2];let url=JSON.parse(ret).url;if(url.length>10){real_url="https://player.buyaotou.xyz/?url="+url;log("免嗅地址:"+real_url);d.saveParse(input,real_url);input=real_url}}catch(e){print("网络请求发生错误:"+e.message)}}',
lazy:'js:cacheUrl=d.getParse(input);if(cacheUrl){input=cacheUrl}else{try{let html=fetch(input,{headers:d.headers,timeout:d.timeout,encoding:d.encoding});let ret=html.match(/var player_(.*?)=(.*?)</)[2];let url=JSON.parse(ret).url;if(url.length>10){real_url="https://player.buyaotou.xyz/?url="+url;d.saveParse(input,real_url);input=real_url}}catch(e){print("网络请求发生错误:"+e.message)}}',
limit:5,
推荐:'ul.stui-vodlist.clearfix;li;a&&title;.lazyload&&data-original;;a&&href',
double:true, // 推荐内容是否双层定位
......
无法预览此类型文件
......@@ -13,7 +13,7 @@ if(cacheUrl){
let url = JSON.parse(ret).url;
if(url.length > 10){
real_url = 'https://player.buyaotou.xyz/?url='+url;
log('免嗅地址:'+real_url);
// log('免嗅地址:'+real_url);
d.saveParse(input,real_url);
input = real_url;
}
......
......@@ -4,6 +4,7 @@
- [X] 1.更换js引擎,速度更快性能更好
- [X] 2.新版js支持与python互动,后期可能支持js免嗅(lazy:'@js:xxx')
- [X] 3.支持了js免嗅和常用的fetch,post方法
- [X] 4.配置uglifyjs可以把js代码压缩到一行(es5不支持多行js)
###### 2022/08/28
- [X] 1.增加linux进程启动,命令 supervisord -c manager.conf
- [X] 2.转移文本文件到txt目录
......
{
{% if config.WALL_PAPER %}"wallpaper":"{{ config.WALL_PAPER }}",{% endif %}
"wallpaper":"http://{{ host }}/pics",
"dr_count": {{rules.list|length}},
"mode": {{ mode }},
"sites": [{% for rule in rules.list %}{% if mode == 0 %}
......
......@@ -6,6 +6,7 @@
import base64
import requests
from utils.web import UC_UA
def base64Encode(text):
return base64.b64encode(text.encode("utf8")).decode("utf-8") #base64编码
......@@ -13,8 +14,7 @@ def base64Encode(text):
def baseDecode(text):
return base64.b64decode(text).decode("utf-8") #base64解码
def base_request(url,obj,method='get'):
url = str(url).replace("'", "")
def dealObj(obj):
encoding = obj.get('encoding') or 'utf-8'
encoding = str(encoding).replace("'", "")
# print(type(url),url)
......@@ -33,25 +33,50 @@ def base_request(url,obj,method='get'):
new_body = {}
for i in body:
new_body[str(i).replace("'", "")] = str(body[i]).replace("'", "")
# print(type(new_body), new_body)
return {
'encoding':encoding,
'headers':new_headers,
'timeout':timeout,
'body': new_body,
}
def base_request(url,obj,method=None):
url = str(url).replace("'", "")
if not method:
method = 'get'
# print(obj)
try:
# r = requests.get(url, headers=headers, params=body, timeout=timeout)
if method.lower() == 'get':
r = requests.get(url, headers=new_headers, params=new_body, timeout=timeout)
r = requests.get(url, headers=obj['headers'], params=obj['body'], timeout=obj['timeout'])
else:
r = requests.post(url, headers=new_headers, data=new_body, timeout=timeout)
r = requests.post(url, headers=obj['headers'], data=obj['body'], timeout=obj['timeout'])
# r = requests.get(url, timeout=timeout)
# r = requests.get(url)
# print(encoding)
r.encoding = encoding
r.encoding = obj['encoding']
# print(f'源码:{r.text}')
return r.text
except Exception as e:
print(f'{method}请求发生错误:{e}')
return ''
def fetch(url,obj):
return base_request(url,obj)
def fetch(url,obj,method=None):
if not method:
method = 'get'
obj = dealObj(obj)
print(method)
return base_request(url,obj,method)
def post(url,obj):
return base_request(url,obj,'post')
\ No newline at end of file
obj = dealObj(obj)
return base_request(url,obj,'post')
def request(url,obj,method=None):
if not method:
method = 'get'
obj = dealObj(obj)
if not obj.get('headers') or not obj['headers'].get('User-Agent'):
obj['headers']['User-Agent'] = UC_UA
return base_request(url, obj, method)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册