diff --git a/src/features/MatchPage/components/FinishedMatch/helpers.tsx b/src/features/MatchPage/components/FinishedMatch/helpers.tsx new file mode 100644 index 00000000..9639a342 --- /dev/null +++ b/src/features/MatchPage/components/FinishedMatch/helpers.tsx @@ -0,0 +1,137 @@ +import map from 'lodash/map' +import last from 'lodash/last' +import uniq from 'lodash/uniq' +import filter from 'lodash/filter' +import reduce from 'lodash/reduce' +import concat from 'lodash/concat' +import orderBy from 'lodash/orderBy' +import isEmpty from 'lodash/isEmpty' +import groupBy from 'lodash/groupBy' + +import type { + Videos, + Episodes, + Episode, +} from 'requests' + +import type { Chapters, Urls } from 'features/MultiSourcePlayer/types' + +import type { PlaylistOption } from '../../types' +import { FULL_GAME_KEY } from '../../helpers/buildPlaylists' + +const getUniquePeriods = (videos: Videos) => uniq(map(videos, ({ period }) => period)) + +type Video = { + duration: number, + period: number, + urls: Urls, +} + +const getVideoByPeriod = (videos: Videos, period: number) => { + const videosWithSamePeriod = filter(videos, { period }) + if (isEmpty(videosWithSamePeriod)) return null + + const urls = reduce( + videosWithSamePeriod, + (acc: Urls, video) => ({ + ...acc, + [video.quality]: video.url, + }), + {}, + ) + const [video] = videosWithSamePeriod + return { + duration: video.duration, + period: video.period, + urls, + } +} + +const getVideoByPeriods = (videos: Videos, periods: Array) => ( + reduce( + periods, + (acc: Array