|
|
|
|
@ -3,8 +3,11 @@ import find from 'lodash/find' |
|
|
|
|
import reduce from 'lodash/reduce' |
|
|
|
|
import concat from 'lodash/concat' |
|
|
|
|
|
|
|
|
|
import type { Episodes } from 'requests/getMatchPlaylists' |
|
|
|
|
import type { MatchInfo } from 'requests/getMatchInfo' |
|
|
|
|
import type { |
|
|
|
|
MatchInfo, |
|
|
|
|
MatchScore, |
|
|
|
|
Episodes, |
|
|
|
|
} from 'requests' |
|
|
|
|
|
|
|
|
|
import type { Chapters, Chapter } from 'features/StreamPlayer/types' |
|
|
|
|
|
|
|
|
|
@ -13,16 +16,25 @@ import { FULL_GAME_KEY } from '../../helpers/buildPlaylists' |
|
|
|
|
|
|
|
|
|
export const FULL_MATCH_BOUNDARY = '0' |
|
|
|
|
|
|
|
|
|
type GetFullMatchChaptersArgs = { |
|
|
|
|
matchScore?: MatchScore, |
|
|
|
|
playlist: MatchPlaylistOption, |
|
|
|
|
profile: MatchInfo, |
|
|
|
|
url: string, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Формирует эпизоды плейлиста Полный матч |
|
|
|
|
* API не выдает полный матч как плейлист, формируем на фронте |
|
|
|
|
* */ |
|
|
|
|
const getFullMatchChapters = ( |
|
|
|
|
profile: MatchInfo, |
|
|
|
|
url: string, |
|
|
|
|
playlist: MatchPlaylistOption, |
|
|
|
|
) => { |
|
|
|
|
const bound = find(profile?.video_bounds, { h: FULL_MATCH_BOUNDARY }) |
|
|
|
|
const getFullMatchChapters = ({ |
|
|
|
|
matchScore, |
|
|
|
|
playlist, |
|
|
|
|
profile, |
|
|
|
|
url, |
|
|
|
|
}: GetFullMatchChaptersArgs) => { |
|
|
|
|
const videoBounds = matchScore?.video_bounds || profile?.video_bounds |
|
|
|
|
const bound = find(videoBounds, { h: FULL_MATCH_BOUNDARY }) |
|
|
|
|
|
|
|
|
|
const durationMs = (bound && !profile?.live) |
|
|
|
|
? ((playlist.duration ?? 0) - Number(bound.s)) * 1000 |
|
|
|
|
@ -42,14 +54,22 @@ const getFullMatchChapters = ( |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type GetPlaylistChaptersArgs = { |
|
|
|
|
episodes: Episodes, |
|
|
|
|
matchScore?: MatchScore, |
|
|
|
|
profile: MatchInfo, |
|
|
|
|
url: string, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Формирует эпизоды плейлистов матча и игроков |
|
|
|
|
* */ |
|
|
|
|
const getPlaylistChapters = ( |
|
|
|
|
profile: MatchInfo, |
|
|
|
|
url: string, |
|
|
|
|
episodes: Episodes, |
|
|
|
|
) => reduce( |
|
|
|
|
const getPlaylistChapters = ({ |
|
|
|
|
episodes, |
|
|
|
|
matchScore, |
|
|
|
|
profile, |
|
|
|
|
url, |
|
|
|
|
}: GetPlaylistChaptersArgs) => reduce( |
|
|
|
|
episodes, |
|
|
|
|
( |
|
|
|
|
acc: Chapters, |
|
|
|
|
@ -58,7 +78,8 @@ const getPlaylistChapters = ( |
|
|
|
|
) => { |
|
|
|
|
if (episode.s >= episode.e) return acc |
|
|
|
|
|
|
|
|
|
const bound = find(profile?.video_bounds, { h: String(episode.h) }) |
|
|
|
|
const videoBounds = matchScore?.video_bounds || profile?.video_bounds |
|
|
|
|
const bound = find(videoBounds, { h: String(episode.h) }) |
|
|
|
|
const boundStart = bound ? Number(bound.s) : 0 |
|
|
|
|
|
|
|
|
|
const episodeDuration = (episode.e - episode.s) * 1000 |
|
|
|
|
@ -79,6 +100,7 @@ const getPlaylistChapters = ( |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type Args = { |
|
|
|
|
matchScore?: MatchScore, |
|
|
|
|
profile: MatchInfo, |
|
|
|
|
selectedPlaylist?: PlaylistOption, |
|
|
|
|
url: string, |
|
|
|
|
@ -88,21 +110,24 @@ type Args = { |
|
|
|
|
* Формирует список эпизодов из выбранного плейлиста для плеера |
|
|
|
|
*/ |
|
|
|
|
export const buildChapters = ({ |
|
|
|
|
matchScore, |
|
|
|
|
profile, |
|
|
|
|
selectedPlaylist, |
|
|
|
|
url, |
|
|
|
|
}: Args): Chapters => { |
|
|
|
|
if (!selectedPlaylist) return [] |
|
|
|
|
if (selectedPlaylist.id === FULL_GAME_KEY) { |
|
|
|
|
return getFullMatchChapters( |
|
|
|
|
return getFullMatchChapters({ |
|
|
|
|
matchScore, |
|
|
|
|
playlist: selectedPlaylist, |
|
|
|
|
profile, |
|
|
|
|
url, |
|
|
|
|
selectedPlaylist, |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
return getPlaylistChapters( |
|
|
|
|
return getPlaylistChapters({ |
|
|
|
|
episodes: selectedPlaylist.episodes, |
|
|
|
|
matchScore, |
|
|
|
|
profile, |
|
|
|
|
url, |
|
|
|
|
selectedPlaylist.episodes, |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|