Skip to content

Commit

Permalink
refactor: extract metadata utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed Mar 14, 2024
1 parent 55f89fe commit 0dd1447
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 42 deletions.
38 changes: 0 additions & 38 deletions packages/common/src/utils/media.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { Playlist, PlaylistItem } from '../../types/playlist';
import { CONTENT_TYPE } from '../constants';

import { formatDuration, formatVideoSchedule } from './formatting';

type RequiredProperties<T, P extends keyof T> = T & Required<Pick<T, P>>;

type DeprecatedPlaylistItem = {
Expand Down Expand Up @@ -51,39 +49,3 @@ export const getLegacySeriesPlaylistIdFromEpisodeTags = (item: PlaylistItem | un

export const isLiveChannel = (item: PlaylistItem): item is RequiredProperties<PlaylistItem, 'contentType' | 'liveChannelsId'> =>
item.contentType?.toLowerCase() === CONTENT_TYPE.liveChannel && !!item.liveChannelsId;

export const createVideoMetadata = (media: PlaylistItem, episodesLabel?: string) => {
const metaData = [];
const duration = formatDuration(media.duration);

if (media.pubdate) metaData.push(String(new Date(media.pubdate * 1000).getFullYear()));
if (!episodesLabel && duration) metaData.push(duration);
if (episodesLabel) metaData.push(episodesLabel);
if (media.genre) metaData.push(media.genre);
if (media.rating) metaData.push(media.rating);

return metaData;
};

export const createPlaylistMetadata = (playlist: Playlist, episodesLabel?: string) => {
const metaData = [];

if (episodesLabel) metaData.push(episodesLabel);
if (playlist.genre) metaData.push(playlist.genre as string);
if (playlist.rating) metaData.push(playlist.rating as string);

return metaData;
};

export const createLiveEventMetadata = (media: PlaylistItem, locale: string) => {
const metaData = [];
const scheduled = formatVideoSchedule(locale, media.scheduledStart, media.scheduledEnd);
const duration = formatDuration(media.duration);

if (scheduled) metaData.push(scheduled);
if (duration) metaData.push(duration);
if (media.genre) metaData.push(media.genre);
if (media.rating) metaData.push(media.rating);

return metaData;
};
37 changes: 37 additions & 0 deletions packages/common/src/utils/metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { Playlist, PlaylistItem } from '../../types/playlist';

import { formatDuration, formatVideoSchedule } from './formatting';

export const createVideoMetadata = (media: PlaylistItem, episodesLabel?: string) => {
const metaData = [];
const duration = formatDuration(media.duration);

if (media.pubdate) metaData.push(String(new Date(media.pubdate * 1000).getFullYear()));
if (!episodesLabel && duration) metaData.push(duration);
if (episodesLabel) metaData.push(episodesLabel);
if (media.genre) metaData.push(media.genre);
if (media.rating) metaData.push(media.rating);

return metaData;
};
export const createPlaylistMetadata = (playlist: Playlist, episodesLabel?: string) => {
const metaData = [];

if (episodesLabel) metaData.push(episodesLabel);
if (playlist.genre) metaData.push(playlist.genre as string);
if (playlist.rating) metaData.push(playlist.rating as string);

return metaData;
};
export const createLiveEventMetadata = (media: PlaylistItem, locale: string) => {
const metaData = [];
const scheduled = formatVideoSchedule(locale, media.scheduledStart, media.scheduledEnd);
const duration = formatDuration(media.duration);

if (scheduled) metaData.push(scheduled);
if (duration) metaData.push(duration);
if (media.genre) metaData.push(media.genre);
if (media.rating) metaData.push(media.rating);

return metaData;
};
2 changes: 1 addition & 1 deletion packages/ui-react/src/pages/LegacySeries/LegacySeries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { PlaylistItem } from '@jwp/ott-common/types/playlist';
import { useWatchHistoryStore } from '@jwp/ott-common/src/stores/WatchHistoryStore';
import { useConfigStore } from '@jwp/ott-common/src/stores/ConfigStore';
import { useAccountStore } from '@jwp/ott-common/src/stores/AccountStore';
import { createPlaylistMetadata, createVideoMetadata } from '@jwp/ott-common/src/utils/media';
import { createPlaylistMetadata, createVideoMetadata } from '@jwp/ott-common/src/utils/metadata';
import { formatSeriesMetaString } from '@jwp/ott-common/src/utils/formatting';
import { legacySeriesURL } from '@jwp/ott-common/src/utils/urlFormatting';
import useEntitlement from '@jwp/ott-hooks-react/src/useEntitlement';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { PlaylistItem } from '@jwp/ott-common/types/playlist';
import { useConfigStore } from '@jwp/ott-common/src/stores/ConfigStore';
import { useAccountStore } from '@jwp/ott-common/src/stores/AccountStore';
import { MediaStatus } from '@jwp/ott-common/src/utils/liveEvent';
import { createLiveEventMetadata } from '@jwp/ott-common/src/utils/media';
import { createLiveEventMetadata } from '@jwp/ott-common/src/utils/metadata';
import { mediaURL } from '@jwp/ott-common/src/utils/urlFormatting';
import { generateMovieJSONLD } from '@jwp/ott-common/src/utils/structuredData';
import useMedia from '@jwp/ott-hooks-react/src/useMedia';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { shallow } from '@jwp/ott-common/src/utils/compare';
import type { PlaylistItem } from '@jwp/ott-common/types/playlist';
import { useConfigStore } from '@jwp/ott-common/src/stores/ConfigStore';
import { useAccountStore } from '@jwp/ott-common/src/stores/AccountStore';
import { createVideoMetadata } from '@jwp/ott-common/src/utils/media';
import { createVideoMetadata } from '@jwp/ott-common/src/utils/metadata';
import { mediaURL } from '@jwp/ott-common/src/utils/urlFormatting';
import { generateMovieJSONLD } from '@jwp/ott-common/src/utils/structuredData';
import useMedia from '@jwp/ott-hooks-react/src/useMedia';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useConfigStore } from '@jwp/ott-common/src/stores/ConfigStore';
import { useAccountStore } from '@jwp/ott-common/src/stores/AccountStore';
import { generateEpisodeJSONLD } from '@jwp/ott-common/src/utils/structuredData';
import { getEpisodesInSeason, getFiltersFromSeries } from '@jwp/ott-common/src/utils/series';
import { createVideoMetadata } from '@jwp/ott-common/src/utils/media';
import { createVideoMetadata } from '@jwp/ott-common/src/utils/metadata';
import { formatSeriesMetaString } from '@jwp/ott-common/src/utils/formatting';
import { buildLegacySeriesUrlFromMediaItem, mediaURL } from '@jwp/ott-common/src/utils/urlFormatting';
import { VideoProgressMinMax } from '@jwp/ott-common/src/constants';
Expand Down

0 comments on commit 0dd1447

Please sign in to comment.