Skip to content

Commit

Permalink
Merge pull request #93 from tv2/SOF-1765/reinstate-showstyle-variant-…
Browse files Browse the repository at this point in the history
…parsing

SOF/reinstate showstyle variant parsing
  • Loading branch information
KvelaGorrrrnio authored Jan 10, 2024
2 parents 8e3706d + 71b7406 commit 80c74c8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ RUN apk add --no-cache tzdata git
COPY . /opt/sofie-inews-gateway
WORKDIR /opt/sofie-inews-gateway
RUN yarn install --production
EXPOSE 3007
CMD ["yarn", "start"]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tv2media/inews-gateway",
"version": "46.3.1-staging",
"version": "46.3.2-staging",
"description": "",
"main": "dist/index.js",
"contributors": [
Expand Down
60 changes: 60 additions & 0 deletions src/helpers/ResolveRundownIntoPlaylist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export function ResolveRundownIntoPlaylist(
let klarOnAirStoryFound = false

for (const segment of segments) {
if (shouldLookForShowstyleVariant(segment, resolvedRundown)) {
const showstyleVariantsForSegment = getOrderedShowstyleVariants(segment)
if (showstyleVariantsForSegment.length > 0) {
setShowstyleVariant(resolvedRundown, showstyleVariantsForSegment[0])
}
}

resolvedRundown.segments.push(segment.externalId)

const isFloated = segment.iNewsStory.meta.float ?? false
Expand All @@ -51,6 +58,59 @@ export function ResolveRundownIntoPlaylist(
return { resolvedRundown, untimedSegments }
}

function shouldLookForShowstyleVariant(segment: UnrankedSegment, rundown: ResolvedPlaylistRundown): boolean {
const isFloated: boolean = !!segment.iNewsStory.meta.float ?? false
const hasShowstyleVariant: boolean = rundown.payload?.showstyleVariant !== undefined
return !isFloated && !hasShowstyleVariant
}

function getOrderedShowstyleVariants(segment: UnrankedSegment): string[] {
const cueOrder: number[] = getCueOrder(segment)
const orderedShowstyleVariants: string[] = []
cueOrder.forEach((cueIndex: number) => {
const parsedProfile: string | null = parseShowstyleVariant(segment.iNewsStory.cues[cueIndex] ?? [])
if (parsedProfile) {
orderedShowstyleVariants.push(parsedProfile)
}
})
return orderedShowstyleVariants
}

function parseShowstyleVariant(cue: string[]): string | null {
const numberOfCueLines: number = cue.length

// Kommando cue (ignoring timing)
const showstyleVariantPattern: RegExp = /^\s*SOFIE\s*=\s*SHOWSTYLEVARIANT/i
if (numberOfCueLines >= 2 && showstyleVariantPattern.test(cue![0])) {
return cue![1].trim()
}
return null
}

/**
*
* @param segment The segment for which the cue order should be retrieved
* @returns A list of indicies representing the cue order.
*/
function getCueOrder(segment: UnrankedSegment): number[] {
const body = segment.iNewsStory.body ?? ''
const refPattern = /<a\s+idref="(?<id>\d+)"\s*\/?>/gi
const order: number[] = []
let match: RegExpExecArray | null
while ((match = refPattern.exec(body))) {
let id = parseInt(match.groups!.id, 10)
order.push(id)
}
return order
}

function setShowstyleVariant(rundown: ResolvedPlaylistRundown, showstyleVariant: string) {
rundown.payload = {
...(rundown.payload ?? null),
showstyleVariant,
}
}

function isKlarOnAir(segment: UnrankedSegment): boolean {
const klarOnAirPattern = /klar[\s-]*on[\s-]*air/im
return !!segment.name?.match(klarOnAirPattern)
Expand Down

0 comments on commit 80c74c8

Please sign in to comment.