|
|
|
|
@ -1,30 +1,38 @@ |
|
|
|
|
import last from 'lodash/last' |
|
|
|
|
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 { Chapters, Chapter } from 'features/StreamPlayer/types' |
|
|
|
|
import type { MatchInfo, VideoBound } from 'requests/getMatchInfo' |
|
|
|
|
|
|
|
|
|
import type { MatchPlaylistOption, PlaylistOption } from '../../types' |
|
|
|
|
import { FULL_GAME_KEY } from '../../helpers/buildPlaylists' |
|
|
|
|
|
|
|
|
|
export const FULL_MATCH_BOUNDARY = '0' |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Формирует эпизоды плейлиста Полный матч |
|
|
|
|
* API не выдает полный матч как плейлист, формируем на фронте |
|
|
|
|
* */ |
|
|
|
|
const getFullMatchChapters = (url: string, playlist: MatchPlaylistOption) => { |
|
|
|
|
const duration = (playlist.duration ?? 0) * 1000 |
|
|
|
|
const getFullMatchChapters = ( |
|
|
|
|
profile: MatchInfo, |
|
|
|
|
url: string, |
|
|
|
|
playlist: MatchPlaylistOption, |
|
|
|
|
) => { |
|
|
|
|
const bound = find(profile?.video_bounds, { h: FULL_MATCH_BOUNDARY }) |
|
|
|
|
const durationMs = (playlist.duration ?? 0) * 1000 |
|
|
|
|
return [ |
|
|
|
|
{ |
|
|
|
|
duration, |
|
|
|
|
endMs: duration, |
|
|
|
|
endOffsetMs: duration, |
|
|
|
|
duration: durationMs, |
|
|
|
|
endMs: durationMs, |
|
|
|
|
endOffsetMs: bound ? Number(bound.e) * 1000 : durationMs, |
|
|
|
|
index: 0, |
|
|
|
|
isFullMatchChapter: true, |
|
|
|
|
startMs: 0, |
|
|
|
|
startOffsetMs: 0, |
|
|
|
|
startOffsetMs: bound ? Number(bound.s) * 1000 : 0, |
|
|
|
|
url, |
|
|
|
|
}, |
|
|
|
|
] |
|
|
|
|
@ -46,20 +54,19 @@ const getPlaylistChapters = ( |
|
|
|
|
) => { |
|
|
|
|
if (episode.s >= episode.e) return acc |
|
|
|
|
|
|
|
|
|
const bound = profile!.video_bounds!.filter( |
|
|
|
|
(ep: VideoBound) => Number(ep.h) === Number(episode.h), |
|
|
|
|
) |
|
|
|
|
const bound = find(profile?.video_bounds, { h: String(episode.h) }) |
|
|
|
|
const boundStart = bound ? Number(bound.s) : 0 |
|
|
|
|
|
|
|
|
|
const episodeDuration = (episode.e - episode.s) * 1000 |
|
|
|
|
const prevVideoEndMs = (last(acc)?.endMs ?? bound[0].s * 1000) || 0 |
|
|
|
|
const prevVideoEndMs = last(acc)?.endMs ?? 0 |
|
|
|
|
|
|
|
|
|
const nextChapter: Chapter = { |
|
|
|
|
duration: episodeDuration, |
|
|
|
|
endMs: prevVideoEndMs + episodeDuration, |
|
|
|
|
endOffsetMs: prevVideoEndMs + episode.e * 1000, |
|
|
|
|
endOffsetMs: (boundStart + episode.e) * 1000, |
|
|
|
|
index, |
|
|
|
|
startMs: 0, |
|
|
|
|
startOffsetMs: prevVideoEndMs + episode.s * 1000, |
|
|
|
|
startMs: prevVideoEndMs, |
|
|
|
|
startOffsetMs: (boundStart + episode.s) * 1000, |
|
|
|
|
url, |
|
|
|
|
} |
|
|
|
|
return concat(acc, nextChapter) |
|
|
|
|
@ -83,7 +90,11 @@ export const buildChapters = ({ |
|
|
|
|
}: Args): Chapters => { |
|
|
|
|
if (!selectedPlaylist) return [] |
|
|
|
|
if (selectedPlaylist.id === FULL_GAME_KEY) { |
|
|
|
|
return getFullMatchChapters(url, selectedPlaylist) |
|
|
|
|
return getFullMatchChapters( |
|
|
|
|
profile, |
|
|
|
|
url, |
|
|
|
|
selectedPlaylist, |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
return getPlaylistChapters( |
|
|
|
|
profile, |
|
|
|
|
|