11import { load } from 'cheerio' ;
2- import { renderToString } from 'hono/jsx/dom/server' ;
32
43import type { Route } from '@/types' ;
54import cache from '@/utils/cache' ;
@@ -81,33 +80,12 @@ async function handler(ctx) {
8180 async ( ) => {
8281 const captchaPage = await ofetch ( redirectResponse . url ) ;
8382 const $captcha = load ( captchaPage ) ;
84-
85- const cookieResponse = await ofetch . raw ( redirectResponse . url , {
86- method : 'POST' ,
87- headers : {
88- 'Content-Type' : 'application/x-www-form-urlencoded' ,
89- Cookie : `safe18_tok=${ $captcha ( 'form#s18f input[name="tok"]' ) . attr ( 'value' ) || '' } ` ,
90- } ,
91- body : new URLSearchParams (
92- Object . fromEntries (
93- $captcha ( 'form#s18f input' )
94- . toArray ( )
95- . map ( ( el ) => [ el . attribs . name , el . attribs . value ] )
96- . filter ( ( [ name , value ] ) => name !== null && value !== null )
97- )
98- ) . toString ( ) ,
99- redirect : 'manual' ,
100- } ) ;
101-
102- const safe18Pass = cookieResponse . headers
103- . getSetCookie ( )
104- ?. find ( ( cookie ) => cookie . startsWith ( 'safe18_pass=' ) )
105- ?. split ( ';' ) [ 0 ]
106- . split ( '=' ) [ 1 ] ;
107-
83+ // Extract the value of safeid from the $captcha HTML content
84+ const safeidMatch = $captcha . html ( ) ?. match ( / v a r \s + s a f e i d \s * = \s * ' ( [ ^ ' ] + ) ' / ) ;
85+ const safeid = safeidMatch ? safeidMatch [ 1 ] : undefined ;
10886 return {
10987 url : redirectResponse . url ,
110- safe18Pass ,
88+ safeid ,
11189 } ;
11290 } ,
11391 86400 , // fixed cookie duration: 24 hours
@@ -117,7 +95,7 @@ async function handler(ctx) {
11795
11896 const response = await ofetch . raw ( currentUrl , {
11997 headers : {
120- cookie : `safe18_pass =${ redirected . safe18Pass } ` ,
98+ cookie : `_safe =${ redirected . safeid } ` ,
12199 } ,
122100 } ) ;
123101
@@ -147,7 +125,7 @@ async function handler(ctx) {
147125 cache . tryGet ( item . guid , async ( ) => {
148126 const detailResponse = await ofetch ( item . link , {
149127 headers : {
150- cookie : `safe18_pass =${ redirected . safe18Pass } ` ,
128+ cookie : `_safe =${ redirected . safeid } ` ,
151129 } ,
152130 } ) ;
153131
@@ -167,33 +145,40 @@ async function handler(ctx) {
167145 item . author = content ( '.fl.black' ) . first ( ) . text ( ) ;
168146 item . pubDate = timezone ( parseDate ( content ( 'span.fl.gray' ) . first ( ) . attr ( 'title' ) ) , + 8 ) ;
169147
170- const downloadLink = content ( '#read_tpc' ) . first ( ) . find ( 'a' ) . last ( ) ;
148+ const readTpc = content ( '#read_tpc' ) . first ( ) ;
171149 const copyLink = content ( '#copytext' ) ?. first ( ) ?. text ( ) ;
172- if ( new URL ( downloadLink . text ( ) ) . hostname === 'bt.azvmw.com' ) {
173- const torrentResponse = await ofetch ( downloadLink . text ( ) ) ;
174-
175- const torrent = load ( torrentResponse ) ;
176-
177- item . enclosure_type = 'application/x-bittorrent' ;
178- const ahref = torrent ( '.uk-button' ) . last ( ) . attr ( 'href' ) ;
179- item . enclosure_url = ahref ?. startsWith ( 'http' ) ? ahref : `https://bt.azvmw.com/${ ahref } ` ;
180-
181- const magnet = torrent ( '.uk-button' ) . first ( ) . attr ( 'href' ) ;
182-
183- downloadLink . replaceWith ( renderToString ( < DownloadLinks magnet = { magnet } torrent = { item . enclosure_url } /> ) ) ;
184- } else if ( copyLink ?. startsWith ( 'magnet' ) ) {
185- // copy link
186- item . enclosure_url = copyLink ;
187- item . enclosure_type = 'x-scheme-handler/magnet' ;
150+ const readTpcHtml = readTpc . html ( ) ?? '' ;
151+ const magnetText = readTpc . find ( '.magnet-text' ) . first ( ) . text ( ) . trim ( ) ;
152+
153+ // Extract enclosure: rmdown.com (fetch page for magnet) | magnet from 哈希校验 | copyLink
154+ const rmdownLink = readTpc . find ( 'a[href*="rmdown.com/link.php"]' ) . first ( ) . attr ( 'href' ) ;
155+ const enclosureHref = rmdownLink ?. startsWith ( 'http' ) ? rmdownLink : rmdownLink ? `https://www.rmdown.com/${ rmdownLink } ` : null ;
156+
157+ if ( enclosureHref ) {
158+ const rmdownPage = await cache . tryGet ( `2048:rmdown:${ enclosureHref } ` , ( ) => ofetch ( enclosureHref ) ) ;
159+ const btihMatch = rmdownPage . match ( / C o d e : \s * ( [ a - f A - F 0 - 9 ] { 40 } ) / ) ;
160+ const magnetUrl = btihMatch ? `magnet:?xt=urn:btih:${ btihMatch [ 1 ] } ` : null ;
161+ if ( magnetUrl ) {
162+ item . enclosure_url = magnetUrl ;
163+ item . enclosure_type = 'x-scheme-handler/magnet' ;
164+ }
165+ }
166+ if ( ! item . enclosure_url ) {
167+ const hashMatch = readTpcHtml . match ( / 哈 希 校 验 [ ^ ; ] * ; \s * ( [ a - f A - F 0 - 9 ] { 40 } ) \s * [ ; ; ] / ) ;
168+ const magnetFromHash = hashMatch ? `magnet:?xt=urn:btih:${ hashMatch [ 1 ] } ` : null ;
169+ const magnetFromText = magnetText . match ( / m a g n e t : \? x t = u r n : b t i h : [ ^ \s " ' < > ] + / ) ?. [ 0 ] ;
170+ const magnetLink = magnetFromText ?? readTpcHtml . match ( / m a g n e t : \? x t = u r n : b t i h : [ ^ \s " ' < > ] + / ) ?. [ 0 ] ?? magnetFromHash ?? copyLink ;
171+ if ( magnetLink ?. startsWith ( 'magnet' ) ) {
172+ item . enclosure_url = magnetLink ;
173+ item . enclosure_type = 'x-scheme-handler/magnet' ;
174+ }
188175 }
189-
190- const desp = content ( '#read_tpc' ) . first ( ) ;
191176
192177 content ( '.showhide img' ) . each ( function ( ) {
193- desp . append ( `<br><img style="max-width: 100%;" src="${ content ( this ) . attr ( 'src' ) } ">` ) ;
178+ readTpc . append ( `<br><img style="max-width: 100%;" src="${ content ( this ) . attr ( 'src' ) } ">` ) ;
194179 } ) ;
195180
196- item . description = desp . html ( ) ;
181+ item . description = readTpc . html ( ) ;
197182
198183 return item ;
199184 } )
@@ -206,9 +191,3 @@ async function handler(ctx) {
206191 item : items ,
207192 } ;
208193}
209-
210- const DownloadLinks = ( { magnet, torrent } : { magnet ?: string ; torrent ?: string } ) => (
211- < >
212- < a href = { magnet } > 磁力連結</ a > | < a href = { torrent } > 下載檔案</ a >
213- </ >
214- ) ;
0 commit comments