Update lib/twitter/twitter.js
Browse files- lib/twitter/twitter.js +2 -4
lib/twitter/twitter.js
CHANGED
@@ -32,17 +32,15 @@ export async function twitterdl(url) {
|
|
32 |
throw new Error("Invalid API response: Missing media data.");
|
33 |
}
|
34 |
|
35 |
-
console.log(data);
|
36 |
const json = TwitterDLResponseSchema.parse(data);
|
37 |
-
|
38 |
const videos = json.includes.media
|
39 |
.filter((m) => m.type === 'video')
|
40 |
.flatMap((m) => m.variants)
|
41 |
.filter((v) => v.content_type !== 'application/x-mpegURL');
|
42 |
|
43 |
-
const result =
|
44 |
-
return TwitterDlSchema.parse(result);
|
45 |
|
|
|
46 |
} catch (error) {
|
47 |
console.error("Error fetching Twitter video:", error.message);
|
48 |
throw new Error("Failed to fetch Twitter video. Please try again later.");
|
|
|
32 |
throw new Error("Invalid API response: Missing media data.");
|
33 |
}
|
34 |
|
|
|
35 |
const json = TwitterDLResponseSchema.parse(data);
|
|
|
36 |
const videos = json.includes.media
|
37 |
.filter((m) => m.type === 'video')
|
38 |
.flatMap((m) => m.variants)
|
39 |
.filter((v) => v.content_type !== 'application/x-mpegURL');
|
40 |
|
41 |
+
const result = Array.isArray(videos) ? videos : [videos];
|
|
|
42 |
|
43 |
+
return TwitterDlSchema.parse(result);
|
44 |
} catch (error) {
|
45 |
console.error("Error fetching Twitter video:", error.message);
|
46 |
throw new Error("Failed to fetch Twitter video. Please try again later.");
|