@@ -4,6 +4,40 @@ import { findBestMatch } from "string-similarity"
4
4
import { ScheduleSession } from "@/app/conf/2023/types"
5
5
6
6
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
+ }
7
41
8
42
export interface SessionVideoProps {
9
43
video : {
@@ -25,27 +59,6 @@ export function SessionVideo({ video, className }: SessionVideoProps) {
25
59
)
26
60
}
27
61
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 ]
51
64
}
0 commit comments