Skip to content

Commit bcc17ba

Browse files
committed
Replace the video match algorithm
1 parent 014da12 commit bcc17ba

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

src/app/conf/2025/schedule/[id]/session-video.tsx

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,40 @@ import { findBestMatch } from "string-similarity"
44
import { ScheduleSession } from "@/app/conf/2023/types"
55

66
import { videos } from "../../_videos"
7+
import { speakers, schedule } from "../../_data"
8+
import { getEventTitle } from "../../utils"
9+
10+
const sessionIdByTitle = Object.create(null)
11+
for (const session of schedule) {
12+
const speakerNames = (session.speakers || []).map(speaker => {
13+
const s = speakers.find(s => s.username === speaker.username)
14+
if (!s) {
15+
throw new Error(
16+
`Speaker "${speaker.username}" not found for "${session.name}"`,
17+
)
18+
}
19+
return s.name
20+
})
21+
22+
const eventTitle = getEventTitle(session, speakerNames)
23+
const title = `${eventTitle} ${speakerNames.join(" ")}`
24+
25+
sessionIdByTitle[title] = session.id
26+
}
27+
28+
const videoBySessionId = Object.create(null)
29+
for (const video of videos) {
30+
const result = findBestMatch(video.title, Object.keys(sessionIdByTitle))
31+
if (result.ratings[result.bestMatchIndex].rating < 0.17) {
32+
console.warn(
33+
`Could not find suitable schedule item for video "${video.title}"`,
34+
)
35+
continue
36+
}
37+
const recordingTitle = result.bestMatch.target
38+
const sessionId = sessionIdByTitle[recordingTitle]
39+
videoBySessionId[sessionId] = video
40+
}
741

842
export interface SessionVideoProps {
943
video: {
@@ -25,27 +59,6 @@ export function SessionVideo({ video, className }: SessionVideoProps) {
2559
)
2660
}
2761

28-
export function findVideo(event: ScheduleSession, eventTitle: string) {
29-
if (videos.length === 0) {
30-
return null
31-
}
32-
33-
const result = findBestMatch(
34-
`${eventTitle} ${event.speakers!.map(e => e.name).join(" ")}`,
35-
videos.map(e => e.title),
36-
)
37-
38-
if (result.ratings[result.bestMatchIndex].rating < 0.17) {
39-
return null
40-
}
41-
42-
const recordingTitle = result.bestMatch
43-
44-
const video = videos.find(e => e.title === recordingTitle.target)
45-
46-
if (!video) {
47-
throw new Error(`Video "${recordingTitle.target}" not found`)
48-
}
49-
50-
return video
62+
export function findVideo(event: ScheduleSession, _eventTitle: string) {
63+
return videoBySessionId[event.id]
5164
}

0 commit comments

Comments
 (0)