@@ -138,25 +138,43 @@ def is_float(s):
138
138
cached_translation_pdf = check_cached_translation_pdf (arxiv_id )
139
139
if cached_translation_pdf and allow_cache : return cached_translation_pdf , arxiv_id
140
140
141
- url_tar = url_ .replace ('/abs/' , '/e-print/' )
142
- translation_dir = pj (ARXIV_CACHE_DIR , arxiv_id , 'e-print' )
143
141
extract_dst = pj (ARXIV_CACHE_DIR , arxiv_id , 'extract' )
142
+ translation_dir = pj (ARXIV_CACHE_DIR , arxiv_id , 'e-print' )
143
+ dst = pj (translation_dir , arxiv_id + '.tar' )
144
144
os .makedirs (translation_dir , exist_ok = True )
145
-
146
145
# <-------------- download arxiv source file ------------->
147
- dst = pj (translation_dir , arxiv_id + '.tar' )
148
- if os .path .exists (dst ):
149
- yield from update_ui_lastest_msg ("调用缓存" , chatbot = chatbot , history = history ) # 刷新界面
146
+
147
+ def fix_url_and_download ():
148
+ for url_tar in [url_ .replace ('/abs/' , '/e-print/' ), url_ .replace ('/abs/' , '/src/' )]:
149
+ # for url_tar in [url_.replace('/abs/', '/src/'), url_.replace('/abs/', '/e-print/')]:
150
+ proxies = get_conf ('proxies' )
151
+ r = requests .get (url_tar , proxies = proxies )
152
+ if r .status_code == 200 :
153
+ with open (dst , 'wb+' ) as f :
154
+ f .write (r .content )
155
+ return True
156
+ return False
157
+
158
+ if os .path .exists (dst ) and allow_cache :
159
+ yield from update_ui_lastest_msg (f"调用缓存 { arxiv_id } " , chatbot = chatbot , history = history ) # 刷新界面
160
+ success = True
150
161
else :
151
- yield from update_ui_lastest_msg ("开始下载" , chatbot = chatbot , history = history ) # 刷新界面
152
- proxies = get_conf ('proxies' )
153
- r = requests .get (url_tar , proxies = proxies )
154
- with open (dst , 'wb+' ) as f :
155
- f .write (r .content )
162
+ yield from update_ui_lastest_msg (f"开始下载 { arxiv_id } " , chatbot = chatbot , history = history ) # 刷新界面
163
+ success = fix_url_and_download ()
164
+ yield from update_ui_lastest_msg (f"下载完成 { arxiv_id } " , chatbot = chatbot , history = history ) # 刷新界面
165
+
166
+
167
+ if not success :
168
+ yield from update_ui_lastest_msg (f"下载失败 { arxiv_id } " , chatbot = chatbot , history = history )
169
+ raise tarfile .ReadError (f"论文下载失败 { arxiv_id } " )
170
+
156
171
# <-------------- extract file ------------->
157
- yield from update_ui_lastest_msg ("下载完成" , chatbot = chatbot , history = history ) # 刷新界面
158
172
from toolbox import extract_archive
159
- extract_archive (file_path = dst , dest_dir = extract_dst )
173
+ try :
174
+ extract_archive (file_path = dst , dest_dir = extract_dst )
175
+ except tarfile .ReadError :
176
+ os .remove (dst )
177
+ raise tarfile .ReadError (f"论文下载失败" )
160
178
return extract_dst , arxiv_id
161
179
162
180
0 commit comments