Skip to content

Commit 71ee0c0

Browse files
committed
[fix]:[][修复了有时无法正常获取英文名称的BUG]
[refactor]:[][规范了部分变量名,完善了提示信息]
1 parent 6e66a92 commit 71ee0c0

16 files changed

Lines changed: 2454 additions & 2462 deletions

src/api/api.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
# # 从请求URL中获取参数
1212
# settings_json = get_settings_json()
1313
# return jsonify({
14-
# "data": {
15-
# "settings": settings_json
14+
# 'data': {
15+
# 'settings': settings_json
1616
# },
17-
# "message": "获取设置信息成功。",
18-
# "statusCode": "OK"
17+
# 'message': '获取设置信息成功。',
18+
# 'statusCode': 'OK'
1919
# })
2020
# except Exception as e:
2121
# return jsonify({
22-
# "data": {
23-
# "settings": ""
22+
# 'data': {
23+
# 'settings': ''
2424
# },
25-
# "message": f"获取设置信息失败:{e}。",
26-
# "statusCode": "GENERAL_ERROR"
25+
# 'message': f'获取设置信息失败:{e}。',
26+
# 'statusCode': 'GENERAL_ERROR'
2727
# }), 400
2828
#
2929
#
@@ -35,15 +35,15 @@
3535
# request_body = request.json
3636
# update_settings_json(request_body)
3737
# return jsonify({
38-
# "data": {},
39-
# "message": "更新设置信息成功。",
40-
# "statusCode": "OK"
38+
# 'data': {},
39+
# 'message': '更新设置信息成功。',
40+
# 'statusCode': 'OK'
4141
# })
4242
# except Exception as e:
4343
# return jsonify({
44-
# "data": {},
45-
# "message": f"更新设置信息失败:{e}。",
46-
# "statusCode": "GENERAL_ERROR"
44+
# 'data': {},
45+
# 'message': f'更新设置信息失败:{e}。',
46+
# 'statusCode': 'GENERAL_ERROR'
4747
# }), 400
4848
#
4949
#

src/api/startapi.py

Lines changed: 776 additions & 781 deletions
Large diffs are not rendered by default.

src/core/autofeed.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
def get_auto_feed_link(main_title, second_title, description, media_info, file_name, team, source, category,
88
torrent_url):
9-
auto_feed_link = str(get_settings("auto_feed_link"))
10-
torrent_name = file_name + '.torrent' # 种子名称
11-
print("变量初始化完成")
9+
auto_feed_link = str(get_settings('auto_feed_link'))
10+
torrent_name = f'{file_name}.torrent' # 种子名称
11+
print('变量初始化完成')
1212
name = main_title
1313
small_descr = second_title
1414
descr = description
@@ -60,13 +60,13 @@ def get_auto_feed_link(main_title, second_title, description, media_info, file_n
6060
if '#separator#' in auto_feed_link:
6161
string_to_encode = auto_feed_link.split('#separator#')[-1]
6262
string_encoded = base64encoding(string_to_encode)
63-
auto_feed_link = auto_feed_link.replace(string_to_encode, "") + string_encoded
64-
print("获取到auto_feed_link:" + auto_feed_link)
63+
auto_feed_link = auto_feed_link.replace(string_to_encode, '') + string_encoded
64+
print('获取到auto_feed_link:' + auto_feed_link)
6565
return True, auto_feed_link
6666
else:
67-
return False, "您设置的auto_feed_link不符合规则"
67+
return False, '您设置的auto_feed_link不符合规则'
6868

69-
# "https://example.com/upload.php#seperator#name#linkstr#{主标题}#linkstr#small_descr#linkstr#{副标题}#linkstr#url
69+
# 'https://example.com/upload.php#seperator#name#linkstr#{主标题}#linkstr#small_descr#linkstr#{副标题}#linkstr#url
7070
# #linkstr#{IMDB}#linkstr#dburl#linkstr{豆瓣}#linkstr#descr#linkstr#{简介}[quote]{MediaInfo}[/quote]#linkstr#log_info
7171
# #linkstr##linkstr#tracklist#linkstr##linkstr#music_type#linkstr##linkstr#music_media#linkstr##linkstr#edition_info
7272
# #linkstr##linkstr#music_name#linkstr##linkstr#music_author#linkstr##linkstr#animate_info#linkstr##linkstr#anidb
@@ -76,4 +76,4 @@ def get_auto_feed_link(main_title, second_title, description, media_info, file_n
7676
# #origin_site#linkstr#{小组}#linkstr#origin_url#linkstr##linkstr#golden_torrent#linkstr#false#linkstr#mediainfo_cmct#linkstr#
7777
# #linkstr#imgs_cmct#linkstr##linkstr#full_mediainfo#linkstr##linkstr#subtitles#linkstr##linkstr#youtube_url#linkstr#
7878
# #linkstr#ptp_poster#linkstr##linkstr#comparisons#linkstr##linkstr#version_info#linkstr##linkstr#multi_mediainfo
79-
# #linkstr##linkstr#labels#linkstr#100"
79+
# #linkstr##linkstr#labels#linkstr#100'

src/core/mediainfo.py

Lines changed: 140 additions & 140 deletions
Large diffs are not rendered by default.

src/core/picturebed.py

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@
1010
def upload_picture(picture_bed_api_url, picture_bed_api_token, picture_path):
1111
print(picture_bed_api_url, picture_bed_api_token, picture_path)
1212
if not os.path.exists(picture_path): # 检测是否存在图片
13-
print("图片文件路径不存在")
14-
return False, "图片文件路径不存在"
13+
print('图片文件路径不存在')
14+
return False, '图片文件路径不存在'
1515
else:
16-
print("开始获取图床类型")
16+
print('开始获取图床类型')
1717
# 去除URL的中的' '、' '和'\n',针对用户错误输入的优化
1818
picture_bed_api_url = picture_bed_api_url.replace(' ', '')
1919
picture_bed_api_url = picture_bed_api_url.replace(' ', '')
2020
picture_bed_api_url = picture_bed_api_url.replace('\n', '')
2121
get_picture_bed_type_success, picture_bed_type = get_picture_bed_type(picture_bed_api_url)
2222
if get_picture_bed_type_success:
23-
print(f"获取到图床的类型:{picture_bed_type}")
24-
if picture_bed_type == "lsky-pro":
23+
print(f'获取到图床的类型:{picture_bed_type}')
24+
if picture_bed_type == 'lsky-pro':
2525
return lsky_pro_picture_bed(picture_bed_api_url, picture_bed_api_token, picture_path)
26-
elif picture_bed_type == "bohe":
26+
elif picture_bed_type == 'bohe':
2727
return bohe_picture_bed(picture_bed_api_url, picture_bed_api_token, picture_path)
28-
elif picture_bed_type == "chevereto":
28+
elif picture_bed_type == 'chevereto':
2929
return chevereto_picture_bed(picture_bed_api_url, picture_bed_api_token, picture_path)
30-
elif picture_bed_type == "freeimage":
30+
elif picture_bed_type == 'freeimage':
3131
return freeimage_picture_bed(picture_bed_api_url, picture_bed_api_token, picture_path)
32-
elif picture_bed_type == "imgbb":
32+
elif picture_bed_type == 'imgbb':
3333
return imgbb_picture_bed(picture_bed_api_url, picture_bed_api_token, picture_path)
34-
elif picture_bed_type == "pixhost":
35-
return pixhost_picture_bed(picture_bed_api_url, picture_bed_api_token, picture_path)
34+
elif picture_bed_type == 'pixhost':
35+
return pixhost_picture_bed(picture_bed_api_url, picture_path)
3636
else:
37-
return False, "你错误更改了图床配置文件?冒号前面的类型是不能随便改的!如果需要支持更多新类型的图床请提Issues,前提是图床支持API上传!"
37+
return False, '你错误更改了图床配置文件?冒号前面的类型是不能随便改的!如果需要支持更多新类型的图床请提Issues,前提是图床支持API上传!'
3838
else:
3939
return False, picture_bed_type
4040

@@ -43,48 +43,48 @@ def upload_picture(picture_bed_api_url, picture_bed_api_token, picture_path):
4343
def lsky_pro_picture_bed(api_url, api_token, frame_path):
4444
print('接受到上传兰空图床请求')
4545
url = api_url
46-
files = {'file': (frame_path, open(frame_path, 'rb'), "image/png")}
46+
files = {'file': (frame_path, open(frame_path, 'rb'), 'image/png')}
4747
headers = {'Authorization': api_token, 'Accept': 'json'}
4848
data = {}
4949
print('值已经获取')
5050

5151
try:
5252
# 发送POST请求
53-
print("开始发送上传图床的请求")
53+
print('开始发送上传图床的请求')
5454
res = requests.post(url, headers=headers, data=data, files=files)
55-
print("已成功发送上传图床的请求")
55+
print('已成功发送上传图床的请求')
5656
except requests.RequestException as e:
57-
print("请求过程中出现错误:", e)
58-
return False, "请求过程中出现错误:" + str(e)
57+
print(f'请求过程中出现错误:{str(e)}')
58+
return False, f'请求过程中出现错误:{str(e)}'
5959

6060
try:
6161
data = json.loads(res.text)
6262
# 提取所需的URL
63-
image_url = data["data"]["links"]["bbcode"]
64-
print(image_url)
65-
return True, image_url
63+
image_bbs_url = data['data']['links']['bbcode']
64+
print(image_bbs_url)
65+
return True, image_bbs_url
6666
except KeyError as e:
67-
print(False, "图床响应结果缺少所需的值:" + str(e))
68-
return False, "图床响应结果缺少所需的值:" + str(e) + str(res)
67+
print(f'图床响应结果缺少所需的值:{str(e)}{str(res)}')
68+
return False, f'图床响应结果缺少所需的值:{str(e)}{str(res)}'
6969
except json.JSONDecodeError as e:
70-
print(False, "处理返回的JSON过程中出现错误:" + str(e))
71-
return False, "处理返回的JSON过程中出现错误:" + str(e) + str(res)
70+
print(f'处理返回的JSON过程中出现错误:{str(e)}{str(res)}')
71+
return False, f'处理返回的JSON过程中出现错误:{str(e)}{str(res)}'
7272

7373

7474
# 薄荷图床
7575
def bohe_picture_bed(api_url, api_token, frame_path):
76-
print("开始上传薄荷图床")
76+
print('开始上传薄荷图床')
7777
url = api_url
78-
files = {'uploadedFile': (frame_path, open(frame_path, 'rb'), "image/png")}
78+
files = {'uploadedFile': (frame_path, open(frame_path, 'rb'), 'image/png')}
7979
data = {'api_token': api_token, 'image_compress': 0, 'image_compress_level': 80}
8080

8181
try:
8282
# 发送POST请求
8383
res = requests.post(url, data=data, files=files)
84-
print("已成功发送上传图床的请求")
84+
print('已成功发送上传图床的请求')
8585
except requests.RequestException as e:
86-
print("请求过程中出现错误:", e)
87-
return False, "请求过程中出现错误:" + str(e)
86+
print(f'请求过程中出现错误:{str(e)}')
87+
return False, f'请求过程中出现错误:{str(e)}'
8888

8989
# 关闭文件流,避免资源泄露
9090
files['uploadedFile'][1].close()
@@ -93,73 +93,73 @@ def bohe_picture_bed(api_url, api_token, frame_path):
9393
try:
9494
api_response = json.loads(res.text)
9595
except json.JSONDecodeError:
96-
print("响应不是有效的JSON格式")
97-
return False, "响应不是有效的JSON格式"
96+
print('响应不是有效的JSON格式')
97+
return False, '响应不是有效的JSON格式'
9898

9999
# 打印提取的url
100-
status_code = api_response.get("statusCode", "")
101-
result_data = api_response.get("resultData", "")
102-
103-
if status_code == "200":
104-
bbs_url = str(api_response.get("bbsurl", ""))
105-
return True, bbs_url
106-
elif status_code == "":
107-
return False, "未接受到响应"
100+
status_code = api_response.get('statusCode', '')
101+
result_data = api_response.get('resultData', '')
102+
103+
if status_code == '200':
104+
image_bbs_url = str(api_response.get('bbsurl', ''))
105+
return True, image_bbs_url
106+
elif status_code == '':
107+
return False, '未接受到响应'
108108
else:
109-
return False, f"API响应出错了,错误码:{status_code},错误提示:{result_data}"
109+
return False, f'API响应出错了,错误码:{status_code},错误提示:{result_data}'
110110

111111

112112
# chevereto图床
113113
def chevereto_picture_bed(api_url, api_token, frame_path):
114114
print('接受到上传chevereto图床请求')
115115
url = api_url
116-
data = {'expiration': 'PT5M', 'X-API-Key': api_token, "key": api_token}
117-
files = {'source': (frame_path, open(frame_path, 'rb'), "image/png")}
116+
data = {'expiration': 'PT5M', 'X-API-Key': api_token, 'key': api_token}
117+
files = {'source': (frame_path, open(frame_path, 'rb'), 'image/png')}
118118
print('值已经获取')
119119

120120
try:
121121
# 发送POST请求
122-
print("开始发送上传图床的请求")
122+
print('开始发送上传图床的请求')
123123
res = requests.post(url, data=data, files=files)
124-
print("已成功发送上传图床的请求")
124+
print('已成功发送上传图床的请求')
125125
except requests.RequestException as e:
126-
print("请求过程中出现错误:", e)
127-
return False, "请求过程中出现错误:" + str(e)
126+
print(f'请求过程中出现错误:{str(e)}')
127+
return False, f'请求过程中出现错误:{str(e)}'
128128

129129
try:
130130
print(res.text)
131131
data = json.loads(res.text)
132132
# 提取所需的URL
133-
image_url = data["image"]["url"]
133+
image_url = data['image']['url']
134134
print(image_url)
135-
return True, '[img]' + image_url + '[/img]'
135+
return True, f'[img]{image_url}[/img]'
136136
except KeyError as e:
137-
print(False, "图床响应结果缺少所需的值:" + str(e))
138-
return False, "图床响应结果缺少所需的值:" + str(e) + str(res)
137+
print(f'图床响应结果缺少所需的值:{str(e)}{str(res)}')
138+
return False, f'图床响应结果缺少所需的值:{str(e)}{str(res)}'
139139
except json.JSONDecodeError as e:
140-
print(False, "处理返回的JSON过程中出现错误:" + str(e))
141-
return False, "处理返回的JSON过程中出现错误:" + str(e) + str(res)
140+
print(f'处理返回的JSON过程中出现错误:{str(e)}{str(res)}')
141+
return False, f'处理返回的JSON过程中出现错误:{str(e)}{str(res)}'
142142

143143

144144
# freeimage图床
145145
def freeimage_picture_bed(api_url, api_token, frame_path):
146146
print('接受到上传freeimage图床请求')
147147
url = api_url
148148
data = {'key': api_token, 'format': 'txt'}
149-
files = {'source': (frame_path, open(frame_path, 'rb'), "image/png")}
149+
files = {'source': (frame_path, open(frame_path, 'rb'), 'image/png')}
150150
print('值已经获取')
151151

152152
try:
153153
# 发送POST请求
154-
print("开始发送上传图床的请求")
154+
print('开始发送上传图床的请求')
155155
res = requests.post(url, data=data, files=files)
156-
print("已成功发送上传图床的请求")
156+
print('已成功发送上传图床的请求')
157157
except requests.RequestException as e:
158-
print("请求过程中出现错误:", e)
159-
return False, "请求过程中出现错误:" + str(e)
158+
print('请求过程中出现错误:', e)
159+
return False, '请求过程中出现错误:' + str(e)
160160

161161
print(res.text)
162-
if res.text[:4] == "http":
162+
if res.text[:4] == 'http':
163163
bbs_url = '[img]' + res.text + '[/img]'
164164
print(bbs_url)
165165
return True, bbs_url
@@ -172,61 +172,61 @@ def imgbb_picture_bed(api_url, api_token, frame_path):
172172
print('接受到上传imgbb图床请求')
173173
url = api_url
174174
data = {'expiration': '600', 'key': api_token}
175-
files = {'image': (frame_path, open(frame_path, 'rb'), "image/png")}
175+
files = {'image': (frame_path, open(frame_path, 'rb'), 'image/png')}
176176
print('值已经获取')
177177

178178
try:
179179
# 发送POST请求
180-
print("开始发送上传图床的请求")
180+
print('开始发送上传图床的请求')
181181
res = requests.post(url, data=data, files=files)
182-
print("已成功发送上传图床的请求")
182+
print('已成功发送上传图床的请求')
183183
except requests.RequestException as e:
184-
print("请求过程中出现错误:", e)
185-
return False, "请求过程中出现错误:" + str(e)
184+
print('请求过程中出现错误:', e)
185+
return False, '请求过程中出现错误:' + str(e)
186186

187187
try:
188188
data = json.loads(res.text)
189189
# 提取所需的URL
190-
image_url = data["data"]["image"]["url"]
190+
image_url = data['data']['image']['url']
191191
print(image_url)
192-
return True, '[img]' + image_url + '[/img]'
192+
return True, f'[img]{image_url}[/img]'
193193
except KeyError as e:
194-
print(False, "图床响应结果缺少所需的值:" + str(e))
195-
return False, "图床响应结果缺少所需的值:" + str(e) + str(res)
194+
print(f'图床响应结果缺少所需的值:{str(e)}{str(res)}')
195+
return False, f'图床响应结果缺少所需的值:{str(e)}{str(res)}'
196196
except json.JSONDecodeError as e:
197-
print(False, "处理返回的JSON过程中出现错误:" + str(e))
198-
return False, "处理返回的JSON过程中出现错误:" + str(e) + str(res)
197+
print(f'处理返回的JSON过程中出现错误:{str(e)}{str(res)}')
198+
return False, f'处理返回的JSON过程中出现错误:{str(e)}{str(res)}'
199199

200200

201201
# pixhost图床
202-
def pixhost_picture_bed(api_url, api_token, frame_path):
202+
def pixhost_picture_bed(api_url, frame_path):
203203
print('接受到上传pixhost图床请求')
204204
url = api_url
205-
files = {'img': (frame_path, open(frame_path, 'rb'), "image/jpeg")}
205+
files = {'img': (frame_path, open(frame_path, 'rb'), 'image/jpeg')}
206206
data = {'content_type': 0, 'max_th_size': 420}
207207
headers = {'Accept': 'application/json'}
208208
print('值已经获取')
209209

210210
try:
211211
# 发送POST请求
212-
print("开始发送上传图床的请求")
212+
print('开始发送上传图床的请求')
213213
res = requests.post(url, headers=headers, data=data, files=files)
214-
print("已成功发送上传图床的请求")
214+
print('已成功发送上传图床的请求')
215215
except requests.RequestException as e:
216-
print("请求过程中出现错误:", e)
217-
return False, "请求过程中出现错误:" + str(e)
216+
print('请求过程中出现错误:', e)
217+
return False, '请求过程中出现错误:' + str(e)
218218

219219
try:
220220
data = json.loads(res.text)
221221
# 提取所需的URL
222-
image_url = data["th_url"]
223-
image_url = image_url.replace("//t", "//img")
224-
image_url = image_url.replace("/thumbs/", "/images/")
222+
image_url = data['th_url']
223+
image_url = image_url.replace('//t', '//img')
224+
image_url = image_url.replace('/thumbs/', '/images/')
225225
print(image_url)
226-
return True, '[img]' + image_url + '[/img]'
226+
return True, f'[img]{image_url}[/img]'
227227
except KeyError as e:
228-
print(False, "图床响应结果缺少所需的值:" + str(e))
229-
return False, "图床响应结果缺少所需的值:" + str(e) + str(res)
228+
print(f'图床响应结果缺少所需的值:{str(e)}{str(res)}')
229+
return False, f'图床响应结果缺少所需的值:{str(e)}{str(res)}'
230230
except json.JSONDecodeError as e:
231-
print(False, "处理返回的JSON过程中出现错误:" + str(e))
232-
return False, "处理返回的JSON过程中出现错误:" + str(e) + str(res)
231+
print(f'处理返回的JSON过程中出现错误:{str(e)}{str(res)}')
232+
return False, f'处理返回的JSON过程中出现错误:{str(e)}{str(res)}'

0 commit comments

Comments
 (0)