@@ -57,7 +57,6 @@ def __init__(self):
5757 "supjav" : True ,
5858 "subtitlecat" : True ,
5959 "javdb" : True ,
60- "javtrailers" : True
6160 },
6261 "custom_sites" : [
6362 {"name" : "" , "url_template" : "" , "enabled" : False },
@@ -116,10 +115,6 @@ def __init__(self):
116115 'javdb' : {
117116 'name' : 'JAVDB' ,
118117 'description' : '智能跳转详情页'
119- },
120- 'javtrailers' : {
121- 'name' : 'JavTrailers' ,
122- 'description' : '智能跳转详情页'
123118 }
124119 }
125120
@@ -198,8 +193,7 @@ def create_search_sites_group(self):
198193 predefined_sites = {
199194 'supjav' : 'SupJAV (立即打开)' ,
200195 'subtitlecat' : 'SubtitleCat (立即打开)' ,
201- 'javdb' : 'JAVDB (智能跳转)' ,
202- 'javtrailers' : 'JavTrailers (智能跳转)'
196+ 'javdb' : 'JAVDB (智能跳转)'
203197 }
204198
205199 for site_id , site_name in predefined_sites .items ():
@@ -582,6 +576,10 @@ def setup_signals(self):
582576 if hasattr (self , 'copy_num_button' ):
583577 self .copy_num_button .clicked .connect (self .copy_number_to_clipboard )
584578
579+ # 连接播放预告片按钮 - 新增代码
580+ if hasattr (self , 'play_trailer_button' ):
581+ self .play_trailer_button .clicked .connect (self .play_trailer )
582+
585583 def eventFilter (self , obj , event ):
586584 """事件过滤器"""
587585 if (
@@ -1000,56 +998,12 @@ def search_javdb():
1000998 except Exception as e :
1001999 print (f"JavDB: 搜索失败: { str (e )} " )
10021000 return False
1003-
1004- def search_javtrailers ():
1005- """搜索JavTrailers"""
1006- if not predefined_sites .get ('javtrailers' , False ):
1007- return False
1008-
1009- try :
1010- search_url = f"https://javtrailers.com/search/{ num_text } "
1011- response = requests .get (search_url , headers = headers , timeout = 10 )
1012-
1013- if response .status_code == 200 :
1014- soup = BeautifulSoup (response .text , 'lxml' )
1015-
1016- # 查找搜索结果列表
1017- videos_section = soup .find ('section' , class_ = 'videos-list' )
1018- if videos_section :
1019- # 查找所有视频卡片
1020- video_links = videos_section .find_all ('a' , class_ = 'video-link' )
1021-
1022- for link in video_links :
1023- # 查找视频标题
1024- title_element = link .find ('p' , class_ = 'vid-title' )
1025- if title_element :
1026- title_text = title_element .text .strip ()
1027- # 检查标题是否以搜索的番号开头
1028- if title_text .upper ().startswith (num_text .upper () + ' ' ):
1029- # 找到匹配的番号,获取详情页链接
1030- href = link .get ('href' )
1031- if href :
1032- detail_url = f"https://javtrailers.com{ href } "
1033- webbrowser .open (detail_url )
1034- print (f"JavTrailers: 打开详情页 { detail_url } " )
1035- return True
10361001
1037- print (f"JavTrailers: 没有找到完全匹配 { num_text } 的番号" )
1038- else :
1039- print (f"JavTrailers: 搜索页面格式可能已变更" )
1040- else :
1041- print (f"JavTrailers: 访问失败,状态码: { response .status_code } " )
1042- except Exception as e :
1043- print (f"JavTrailers: 搜索失败: { str (e )} " )
1044- return False
1045-
10461002 # 在后台并发处理需要解析的网站
10471003 def background_search ():
10481004 parse_sites = []
10491005 if predefined_sites .get ('javdb' , False ):
10501006 parse_sites .append (search_javdb )
1051- if predefined_sites .get ('javtrailers' , False ):
1052- parse_sites .append (search_javtrailers )
10531007
10541008 if parse_sites :
10551009 with concurrent .futures .ThreadPoolExecutor (max_workers = 2 ) as executor :
@@ -1066,7 +1020,7 @@ def background_search():
10661020 print (f"搜索任务执行失败: { str (e )} " )
10671021
10681022 # 启动后台搜索线程(如果有需要解析的网站)
1069- if predefined_sites .get ('javdb' , False ) or predefined_sites . get ( 'javtrailers' , False ) :
1023+ if predefined_sites .get ('javdb' , False ):
10701024 threading .Thread (target = background_search , daemon = True ).start ()
10711025
10721026 # 状态反馈
@@ -1080,7 +1034,6 @@ def background_search():
10801034 # 降级到原始方式
10811035 try :
10821036 webbrowser .open (f"https://javdb.com/search?q={ num_text } &f=all" )
1083- webbrowser .open (f"https://javtrailers.com/search/{ num_text } " )
10841037 except Exception as fallback_error :
10851038 QMessageBox .critical (self , "错误" , f"所有搜索方式都失败了: { str (fallback_error )} " )
10861039
@@ -2271,6 +2224,135 @@ def restore_copy_button(self):
22712224 self .copy_num_button .setText ("📋" )
22722225 self .copy_num_button .setToolTip ("复制番号" )
22732226
2227+ def play_trailer (self ):
2228+ """播放预告片"""
2229+ if not self .current_file_path :
2230+ QMessageBox .warning (self , "警告" , "请先选择NFO文件" )
2231+ return
2232+
2233+ try :
2234+ # 获取NFO所在目录
2235+ folder = os .path .dirname (self .current_file_path )
2236+
2237+ # 获取番号
2238+ num_text = self .fields_entries ["num" ].text ().strip ()
2239+ if not num_text :
2240+ QMessageBox .warning (self , "警告" , "番号为空" )
2241+ return
2242+
2243+ # 查找包含trailer的视频文件
2244+ trailer_extensions = [".mp4" , ".mkv" , ".avi" , ".mov" , ".rm" , ".mpeg" , ".ts" , ".strm" ]
2245+ trailer_files = []
2246+
2247+ for file in os .listdir (folder ):
2248+ file_lower = file .lower ()
2249+ if "trailer" in file_lower :
2250+ for ext in trailer_extensions :
2251+ if file_lower .endswith (ext ):
2252+ trailer_files .append (os .path .join (folder , file ))
2253+ break
2254+
2255+ if trailer_files :
2256+ # 播放找到的第一个trailer文件
2257+ trailer_path = trailer_files [0 ]
2258+
2259+ if trailer_path .lower ().endswith (".strm" ):
2260+ # 处理strm文件
2261+ try :
2262+ with open (trailer_path , "r" , encoding = "utf-8" ) as f :
2263+ strm_url = f .readline ().strip ()
2264+ if strm_url :
2265+ subprocess .Popen (["mpvnet" , strm_url ])
2266+ # self.status_bar.showMessage(f"正在播放预告片: {os.path.basename(trailer_path)}", 3000)
2267+ else :
2268+ QMessageBox .critical (self , "错误" , "STRM文件内容为空或无效" )
2269+ except Exception as e :
2270+ QMessageBox .critical (self , "错误" , f"读取STRM文件失败: { str (e )} " )
2271+ else :
2272+ # 播放普通视频文件
2273+ subprocess .Popen (["mpvnet" , trailer_path ])
2274+ self .status_bar .showMessage (f"正在播放预告片: { os .path .basename (trailer_path )} " , 3000 )
2275+ else :
2276+ # 没找到trailer文件,打开javtrailers网站
2277+ self .open_javtrailers_detail (num_text )
2278+
2279+ except Exception as e :
2280+ QMessageBox .critical (self , "错误" , f"播放预告片失败: { str (e )} " )
2281+
2282+ def open_javtrailers_detail (self , num_text ):
2283+ """打开JavTrailers详情页"""
2284+ try :
2285+ import requests
2286+ from bs4 import BeautifulSoup
2287+ import threading
2288+
2289+ def search_and_open ():
2290+ try :
2291+ headers = {
2292+ 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' ,
2293+ 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' ,
2294+ 'Accept-Language' : 'zh-CN,zh;q=0.9,en;q=0.8' ,
2295+ 'Accept-Encoding' : 'gzip, deflate, br' ,
2296+ 'DNT' : '1' ,
2297+ 'Connection' : 'keep-alive' ,
2298+ 'Upgrade-Insecure-Requests' : '1' ,
2299+ }
2300+
2301+ search_url = f"https://javtrailers.com/search/{ num_text } "
2302+ response = requests .get (search_url , headers = headers , timeout = 10 )
2303+
2304+ if response .status_code == 200 :
2305+ soup = BeautifulSoup (response .text , 'lxml' )
2306+
2307+ # 查找搜索结果列表
2308+ videos_section = soup .find ('section' , class_ = 'videos-list' )
2309+ if videos_section :
2310+ # 查找所有视频卡片
2311+ video_links = videos_section .find_all ('a' , class_ = 'video-link' )
2312+
2313+ for link in video_links :
2314+ # 查找视频标题
2315+ title_element = link .find ('p' , class_ = 'vid-title' )
2316+ if title_element :
2317+ title_text = title_element .text .strip ()
2318+ # 检查标题是否以搜索的番号开头
2319+ if title_text .upper ().startswith (num_text .upper () + ' ' ):
2320+ # 找到匹配的番号,获取详情页链接
2321+ href = link .get ('href' )
2322+ if href :
2323+ detail_url = f"https://javtrailers.com{ href } "
2324+ webbrowser .open (detail_url )
2325+ print (f"JavTrailers: 打开详情页 { detail_url } " )
2326+ return True
2327+
2328+ # 没找到匹配的,打开搜索页面
2329+ webbrowser .open (search_url )
2330+ print (f"JavTrailers: 未找到匹配番号,打开搜索页面" )
2331+ else :
2332+ # 搜索页面格式可能已变更,直接打开搜索页面
2333+ webbrowser .open (search_url )
2334+ print (f"JavTrailers: 搜索页面格式可能已变更,打开搜索页面" )
2335+ else :
2336+ # 访问失败,直接打开搜索页面
2337+ webbrowser .open (search_url )
2338+ print (f"JavTrailers: 访问失败,打开搜索页面" )
2339+ except Exception as e :
2340+ # 出错时打开搜索页面
2341+ search_url = f"https://javtrailers.com/search/{ num_text } "
2342+ webbrowser .open (search_url )
2343+ print (f"JavTrailers: 搜索失败,打开搜索页面: { str (e )} " )
2344+
2345+ # 在后台线程中执行搜索
2346+ threading .Thread (target = search_and_open , daemon = True ).start ()
2347+ self .status_bar .showMessage ("正在打开JavTrailers预告片页面..." , 3000 )
2348+
2349+ except Exception as e :
2350+ # 如果导入失败或其他错误,直接打开搜索页面
2351+ search_url = f"https://javtrailers.com/search/{ num_text } "
2352+ webbrowser .open (search_url )
2353+ self .status_bar .showMessage ("已打开JavTrailers搜索页面" , 3000 )
2354+
2355+
22742356def main ():
22752357 # 在创建 QApplication 之前设置高DPI属性
22762358 if hasattr (Qt , "AA_EnableHighDpiScaling" ):
0 commit comments