Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475import {type I18n} from '@lingui/core'import {plural} from '@lingui/core/macro'import psl from 'psl'
export function displayDuration(i18n: I18n, durationInMinutes: number) { const roundedDurationInMinutes = Math.round(durationInMinutes) const hours = Math.floor(roundedDurationInMinutes / 60) const minutes = roundedDurationInMinutes % 60 const minutesString = i18n._( plural(minutes, {one: '# minute', other: '# minutes'}), ) return hours > 0 ? i18n._( minutes > 0 ? plural(hours, { one: `# hour ${minutesString}`, other: `# hours ${minutesString}`, }) : plural(hours, { one: '# hour', other: '# hours', }), ) : minutesString}
const serviceUrlToNameMap: Record<string, string> = { 'twitch.tv': 'Twitch', 'youtube.com': 'YouTube', 'nba.com': 'NBA', 'nba.smart.link': 'nba.smart.link', 'espn.com': 'ESPN', 'stream.place': 'Streamplace', 'skylight.social': 'Skylight', 'bluecast.app': 'Bluecast', 'substack.com': 'Substack', 'beehiiv.com': 'Beehiiv',}
export function getLiveServiceNames(domains: Set<string>) { const names = Array.from( new Set( Array.from(domains.values()) .map(d => sanitizeLiveNowHost(d)) .map(d => serviceUrlToNameMap[d] || d), ), ) return { names, formatted: names.join(', '), }}
export function sanitizeLiveNowHost(hostname: string) { // special case this one if (hostname === 'nba.smart.link') { return hostname } const parsed = psl.parse(hostname) if ('error' in parsed || !parsed.listed || !parsed.domain) { // fall back to dumb version return hostname.replace(/^www\./, '') } return parsed.domain}
/** * Extracts the apex domain from a given URL, for use when matching allowed * Live Now hosts. */export function getLiveNowHost(url: string) { const {hostname} = new URL(url) return sanitizeLiveNowHost(hostname)}