forked from supermemoryai/supermemory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter-video-variant.test.ts
More file actions
75 lines (70 loc) · 1.94 KB
/
Copy pathtwitter-video-variant.test.ts
File metadata and controls
75 lines (70 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { describe, expect, it } from "bun:test"
import { pickBestVideoVariantUrl } from "./twitter-utils"
describe("pickBestVideoVariantUrl", () => {
it("returns an empty string when there are no variants", () => {
expect(pickBestVideoVariantUrl(undefined)).toBe("")
expect(pickBestVideoVariantUrl([])).toBe("")
})
it("picks the highest-bitrate mp4, not the first variant", () => {
const variants = [
{
url: "https://video.twimg.com/playlist.m3u8",
content_type: "application/x-mpegURL",
},
{
url: "https://video.twimg.com/low.mp4",
content_type: "video/mp4",
bitrate: 256000,
},
{
url: "https://video.twimg.com/high.mp4",
content_type: "video/mp4",
bitrate: 2176000,
},
{
url: "https://video.twimg.com/mid.mp4",
content_type: "video/mp4",
bitrate: 832000,
},
]
expect(pickBestVideoVariantUrl(variants)).toBe(
"https://video.twimg.com/high.mp4",
)
})
it("does not return the HLS playlist when mp4 renditions exist", () => {
const variants = [
{
url: "https://video.twimg.com/playlist.m3u8",
content_type: "application/x-mpegURL",
},
{
url: "https://video.twimg.com/only.mp4",
content_type: "video/mp4",
bitrate: 632000,
},
]
expect(pickBestVideoVariantUrl(variants)).toBe(
"https://video.twimg.com/only.mp4",
)
})
it("falls back to the first variant when no mp4 is present", () => {
const variants = [
{
url: "https://video.twimg.com/playlist.m3u8",
content_type: "application/x-mpegURL",
},
]
expect(pickBestVideoVariantUrl(variants)).toBe(
"https://video.twimg.com/playlist.m3u8",
)
})
it("detects mp4 by extension when content_type is absent", () => {
const variants = [
{ url: "https://video.twimg.com/240/vid.mp4?tag=12" },
{ url: "https://video.twimg.com/720/vid.mp4?tag=12", bitrate: 2176000 },
]
expect(pickBestVideoVariantUrl(variants)).toBe(
"https://video.twimg.com/720/vid.mp4?tag=12",
)
})
})