@@ -3,6 +3,7 @@ import type { Context } from 'hono';
33
44import type { Route } from '@/types' ;
55import got from '@/utils/got' ;
6+ import { parseRelativeDate } from '@/utils/parse-date' ;
67
78export const route : Route = {
89 path : '/latest' ,
@@ -16,10 +17,11 @@ export const route: Route = {
1617 supportBT : false ,
1718 supportPodcast : false ,
1819 supportScihub : false ,
20+ nsfw : true ,
1921 } ,
2022 radar : [
2123 {
22- source : [ 'rule34video.com/latest-updates' ] ,
24+ source : [ 'rule34video.com/latest-updates/ ' ] ,
2325 target : '/latest' ,
2426 } ,
2527 ] ,
@@ -44,7 +46,7 @@ interface VideoItem {
4446async function handler ( _ctx : Context ) {
4547 const response = await got ( {
4648 method : 'get' ,
47- url : 'https://www.rule34video.com/latest-updates' ,
49+ url : 'https://www.rule34video.com/latest-updates/ ' ,
4850 headers : {
4951 Referer : 'https://www.rule34video.com' ,
5052 } ,
@@ -57,10 +59,7 @@ async function handler(_ctx: Context) {
5759 const $el = $ ( element ) ;
5860 const title = $el . attr ( 'title' ) ?. trim ( ) || $el . find ( '.thumb_title' ) . text ( ) . trim ( ) ;
5961 const link = $el . attr ( 'href' ) ?. trim ( ) || '' ;
60- const preview =
61- $el . find ( 'img.thumb.lazy-load' ) . attr ( 'data-original' ) ||
62- $el . find ( 'img.thumb.lazy-load' ) . attr ( 'src' ) ||
63- undefined ;
62+ const preview = $el . find ( 'img.thumb.lazy-load' ) . attr ( 'data-original' ) || undefined ;
6463 const duration = $el . find ( '.time' ) . text ( ) . trim ( ) || undefined ;
6564 const added = $el . find ( '.added' ) . text ( ) . replaceAll ( / \s + / g, ' ' ) . trim ( ) || undefined ;
6665 const rating = $el . find ( '.rating' ) . text ( ) . trim ( ) || undefined ;
@@ -87,26 +86,23 @@ async function handler(_ctx: Context) {
8786 return {
8887 allowEmpty : true ,
8988 title : 'Rule34 Video Latest Updates' ,
90- link : 'https://www.rule34video.com/latest-updates' ,
89+ link : 'https://www.rule34video.com/latest-updates/ ' ,
9190 description : 'Latest updates from Rule34 Video' ,
9291 item : items . map ( ( item ) => buildDataItem ( item ) ) ,
9392 } ;
9493}
9594
9695function buildDataItem ( item : VideoItem ) {
97- const descriptionParts : string [ ] = [ ] ;
96+ let description = '' ;
9897
99- if ( item . title ) {
100- descriptionParts . push ( item . title ) ;
101- }
10298 if ( item . duration ) {
103- descriptionParts . push ( ` Duration: ${ item . duration } ` ) ;
99+ description += `<p> Duration: ${ item . duration } </p>` ;
104100 }
105101 if ( item . views ) {
106- descriptionParts . push ( ` Views: ${ item . views } ` ) ;
102+ description += `<p> Views: ${ item . views } </p>` ;
107103 }
108104 if ( item . rating ) {
109- descriptionParts . push ( ` Rating: ${ item . rating } ` ) ;
105+ description += `<p> Rating: ${ item . rating } </p>` ;
110106 }
111107
112108 const qualities : string [ ] = [ ] ;
@@ -117,53 +113,22 @@ function buildDataItem(item: VideoItem) {
117113 qualities . push ( 'Has Sound' ) ;
118114 }
119115 if ( qualities . length > 0 ) {
120- descriptionParts . push ( ` Quality: ${ qualities . join ( ', ' ) } ` ) ;
116+ description += `<p> Quality: ${ qualities . join ( ', ' ) } </p>` ;
121117 }
122118
123119 if ( item . preview ) {
124- descriptionParts . push ( `Image: ${ item . preview } ` ) ;
120+ description += `<img src=" ${ item . preview } " alt=" ${ item . title } " />` ;
125121 }
126122
127- const description = descriptionParts . join ( ' | ' ) ;
128- const pubDate = item . added ? parseRelativeDate ( item . added ) : new Date ( ) ;
123+ const pubDate = item . added ? parseRelativeDate ( item . added ) : undefined ;
129124
130125 return {
131126 title : item . title ,
132127 link : item . link ,
133128 description,
134129 image : item . preview ,
135- pubDate : pubDate . toISOString ( ) ,
130+ ... ( pubDate && { pubDate : pubDate . toISOString ( ) } ) ,
136131 guid : item . videoId ? `rule34video:${ item . videoId } ` : item . link ,
137132 category : item . isHD ? [ 'HD' ] : [ ] ,
138133 } ;
139134}
140-
141- function parseRelativeDate ( text : string ) {
142- const match = text . match ( / ( \d + ) \s + ( s e c o n d | m i n u t e | h o u r | d a y | w e e k | m o n t h | y e a r ) s ? \s + a g o / i) ;
143- if ( ! match ) {
144- return new Date ( ) ;
145- }
146-
147- const value = Number ( match [ 1 ] ) ;
148- const unit = match [ 2 ] . toLowerCase ( ) ;
149- const now = new Date ( ) ;
150-
151- switch ( unit ) {
152- case 'second' :
153- return new Date ( now . getTime ( ) - value * 1000 ) ;
154- case 'minute' :
155- return new Date ( now . getTime ( ) - value * 60 * 1000 ) ;
156- case 'hour' :
157- return new Date ( now . getTime ( ) - value * 60 * 60 * 1000 ) ;
158- case 'day' :
159- return new Date ( now . getTime ( ) - value * 24 * 60 * 60 * 1000 ) ;
160- case 'week' :
161- return new Date ( now . getTime ( ) - value * 7 * 24 * 60 * 60 * 1000 ) ;
162- case 'month' :
163- return new Date ( now . getTime ( ) - value * 30 * 24 * 60 * 60 * 1000 ) ;
164- case 'year' :
165- return new Date ( now . getTime ( ) - value * 365 * 24 * 60 * 60 * 1000 ) ;
166- default :
167- return now ;
168- }
169- }
0 commit comments