|
|
|
|
@ -5,6 +5,7 @@ import concat from 'lodash/concat' |
|
|
|
|
import type { Episodes } from 'requests/getMatchPlaylists' |
|
|
|
|
|
|
|
|
|
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' |
|
|
|
|
@ -32,7 +33,11 @@ const getFullMatchChapters = (url: string, playlist: MatchPlaylistOption) => { |
|
|
|
|
/** |
|
|
|
|
* Формирует эпизоды плейлистов матча и игроков |
|
|
|
|
* */ |
|
|
|
|
const getPlaylistChapters = (url: string, episodes: Episodes) => reduce( |
|
|
|
|
const getPlaylistChapters = ( |
|
|
|
|
profile: MatchInfo, |
|
|
|
|
url: string, |
|
|
|
|
episodes: Episodes, |
|
|
|
|
) => reduce( |
|
|
|
|
episodes, |
|
|
|
|
( |
|
|
|
|
acc: Chapters, |
|
|
|
|
@ -41,15 +46,20 @@ const getPlaylistChapters = (url: string, episodes: Episodes) => reduce( |
|
|
|
|
) => { |
|
|
|
|
if (episode.s >= episode.e) return acc |
|
|
|
|
|
|
|
|
|
const bound = profile!.video_bounds!.filter( |
|
|
|
|
(ep: VideoBound) => Number(ep.h) === Number(episode.h), |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
const episodeDuration = (episode.e - episode.s) * 1000 |
|
|
|
|
const prevVideoEndMs = last(acc)?.endMs || 0 |
|
|
|
|
const prevVideoEndMs = (last(acc)?.endMs ?? bound[0].s * 1000) || 0 |
|
|
|
|
|
|
|
|
|
const nextChapter: Chapter = { |
|
|
|
|
duration: episodeDuration, |
|
|
|
|
endMs: prevVideoEndMs + episodeDuration, |
|
|
|
|
endOffsetMs: episode.e * 1000, |
|
|
|
|
endOffsetMs: prevVideoEndMs + episode.e * 1000, |
|
|
|
|
index, |
|
|
|
|
startMs: prevVideoEndMs, |
|
|
|
|
startOffsetMs: episode.s * 1000, |
|
|
|
|
startMs: 0, |
|
|
|
|
startOffsetMs: prevVideoEndMs + episode.s * 1000, |
|
|
|
|
url, |
|
|
|
|
} |
|
|
|
|
return concat(acc, nextChapter) |
|
|
|
|
@ -58,6 +68,7 @@ const getPlaylistChapters = (url: string, episodes: Episodes) => reduce( |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type Args = { |
|
|
|
|
profile: MatchInfo, |
|
|
|
|
selectedPlaylist?: PlaylistOption, |
|
|
|
|
url: string, |
|
|
|
|
} |
|
|
|
|
@ -66,6 +77,7 @@ type Args = { |
|
|
|
|
* Формирует список эпизодов из выбранного плейлиста для плеера |
|
|
|
|
*/ |
|
|
|
|
export const buildChapters = ({ |
|
|
|
|
profile, |
|
|
|
|
selectedPlaylist, |
|
|
|
|
url, |
|
|
|
|
}: Args): Chapters => { |
|
|
|
|
@ -73,5 +85,9 @@ export const buildChapters = ({ |
|
|
|
|
if (selectedPlaylist.id === FULL_GAME_KEY) { |
|
|
|
|
return getFullMatchChapters(url, selectedPlaylist) |
|
|
|
|
} |
|
|
|
|
return getPlaylistChapters(url, selectedPlaylist.episodes) |
|
|
|
|
return getPlaylistChapters( |
|
|
|
|
profile, |
|
|
|
|
url, |
|
|
|
|
selectedPlaylist.episodes, |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|