1
1
import { Hono } from 'hono'
2
2
import { cache } from 'hono/cache'
3
3
4
- import { grabAwemeId , getVideoInfo } from './services/tiktok'
4
+ import { scrapeVideoData } from './services/tiktok'
5
+ import { grabAwemeId } from './services/tiktok'
5
6
import { VideoResponse , ErrorResponse } from './templates'
6
7
import generateAlternate from './util/generateAlternate'
7
- import { returnHTMLResponse } from './util/ResponseHelper'
8
+ import { returnHTMLResponse } from './util/responseHelper'
9
+
10
+ import { ItemStruct } from './types/Web'
8
11
9
12
const app = new Hono ( )
10
13
11
14
app . get ( '/test/:videoId' , async ( c ) => {
12
15
const { videoId } = c . req . param ( )
13
- const awemeId = await getVideoInfo ( videoId )
16
+ const awemeId = await scrapeVideoData ( videoId )
14
17
15
18
if ( awemeId instanceof Error ) {
16
19
return new Response ( ( awemeId as Error ) . message , { status : 500 } )
@@ -62,28 +65,27 @@ async function handleVideo(c: any): Promise<Response> {
62
65
}
63
66
64
67
try {
65
- const videoInfo = await getVideoInfo ( id )
68
+ const videoInfo = await scrapeVideoData ( id )
66
69
67
70
if ( videoInfo instanceof Error ) {
68
71
const responseContent = await ErrorResponse ( ( videoInfo as Error ) . message ) ;
69
72
return returnHTMLResponse ( responseContent , 201 ) ;
70
73
}
71
74
72
75
const url = new URL ( c . req . url ) ;
73
-
74
76
if ( url . hostname . includes ( 'd.tnktok.com' ) || c . req . query ( 'isDirect' ) === 'true' ) {
75
77
if ( videoInfo . video . duration > 0 ) {
76
78
return new Response ( '' , {
77
79
status : 302 ,
78
80
headers : {
79
- 'Location' : 'https://fxtiktok-rewrite.dargy.workers.dev/generate/video/' + videoInfo . aweme_id
81
+ 'Location' : 'https://fxtiktok-rewrite.dargy.workers.dev/generate/video/' + videoInfo . id
80
82
}
81
83
} )
82
84
} else {
83
85
return new Response ( '' , {
84
86
status : 302 ,
85
87
headers : {
86
- 'Location' : 'https://fxtiktok-rewrite.dargy.workers.dev/generate/image/' + videoInfo . aweme_id
88
+ 'Location' : 'https://fxtiktok-rewrite.dargy.workers.dev/generate/image/' + videoInfo . id
87
89
}
88
90
} )
89
91
}
@@ -92,6 +94,7 @@ async function handleVideo(c: any): Promise<Response> {
92
94
return returnHTMLResponse ( responseContent ) ;
93
95
}
94
96
} catch ( e ) {
97
+ console . log ( e ) ;
95
98
const responseContent = await ErrorResponse ( ( e as Error ) . message ) ;
96
99
return returnHTMLResponse ( responseContent , 201 ) ;
97
100
}
@@ -118,20 +121,26 @@ app.get(
118
121
119
122
app . get ( '/generate/video/:videoId' , async ( c ) => {
120
123
const { videoId } = c . req . param ( )
121
- const data = await getVideoInfo ( videoId ) ;
122
124
123
- if ( data instanceof Error ) {
124
- return new Response ( ( data as Error ) . message , { status : 500 ,
125
- headers : {
126
- 'Cache-Control' : 'no-cache, no-store, must-revalidate' ,
125
+ try {
126
+ /*
127
+ const data = await scrapeVideoData(videoId);
128
+
129
+ if (!(data instanceof Error)) {
130
+ if(data.video.playAddr) {
131
+ return c.redirect(data.video.playAddr)
132
+ } else {
133
+ return new Response('No video found', { status: 404,
134
+ headers: {
135
+ 'Cache-Control': 'no-cache, no-store, must-revalidate',
136
+ }
137
+ })
127
138
}
128
- } )
129
- }
130
-
131
- if ( data . video . play_addr . url_list . length > 0 ) {
132
- return c . redirect ( data . video . play_addr . url_list [ 0 ] )
133
- } else {
134
- return new Response ( 'No video found' , { status : 404 ,
139
+ }
140
+ */
141
+ return c . redirect ( `https://tikwm.com/video/media/play/${ videoId } .mp4` ) ;
142
+ } catch ( e ) {
143
+ return new Response ( ( e as Error ) . message , { status : 500 ,
135
144
headers : {
136
145
'Cache-Control' : 'no-cache, no-store, must-revalidate' ,
137
146
}
@@ -141,16 +150,26 @@ app.get('/generate/video/:videoId', async (c) => {
141
150
142
151
app . get ( '/generate/image/:videoId' , async ( c ) => {
143
152
const { videoId } = c . req . param ( )
144
- const data = await getVideoInfo ( videoId ) ;
145
153
146
- if ( data instanceof Error ) {
147
- return new Response ( ( data as Error ) . message , { status : 500 } )
148
- }
149
-
150
- if ( data . video . cover . url_list . length > 0 ) {
151
- return c . redirect ( data . video . cover . url_list [ 0 ] )
152
- } else {
153
- return new Response ( JSON . stringify ( data ) , { status : 200 } )
154
+ try {
155
+ /*
156
+ const data = await scrapeVideoData(videoId);
157
+
158
+ if (!(data instanceof Error)) {
159
+ if(data.imagePost.images.length > 0) {
160
+ return c.redirect(data.imagePost.images[0].imageURL.urlList[0])
161
+ } else {
162
+ return new Response(JSON.stringify(data), { status: 200 })
163
+ }
164
+ }
165
+ */
166
+ return c . redirect ( `https://tikwm.com/video/cover/${ videoId } .webp` ) ;
167
+ } catch ( e ) {
168
+ return new Response ( ( e as Error ) . message , { status : 500 ,
169
+ headers : {
170
+ 'Cache-Control' : 'no-cache, no-store, must-revalidate' ,
171
+ }
172
+ } )
154
173
}
155
174
} )
156
175
0 commit comments