import _ from 'lodash'; import PropTypes from 'prop-types'; import React from 'react'; import getLanguageName from 'Utilities/String/getLanguageName'; import * as mediaInfoTypes from './mediaInfoTypes'; function formatLanguages(languages) { if (!languages) { return null; } const splitLanguages = _.uniq(languages.split('/')).map((l) => getLanguageName(l)); if (splitLanguages.length > 3) { return ( {splitLanguages.slice(0, 2).join(', ')}, {splitLanguages.length - 2} more ); } return ( {splitLanguages.join(', ')} ); } function MediaInfo(props) { const { type, audioChannels, audioCodec, audioLanguages, subtitles, videoCodec, videoDynamicRangeType } = props; if (type === mediaInfoTypes.AUDIO) { return ( { audioCodec ? audioCodec : '' } { audioCodec && audioChannels ? ' - ' : '' } { audioChannels ? audioChannels.toFixed(1) : '' } ); } if (type === mediaInfoTypes.AUDIO_LANGUAGES) { return formatLanguages(audioLanguages); } if (type === mediaInfoTypes.SUBTITLES) { return formatLanguages(subtitles); } if (type === mediaInfoTypes.VIDEO) { return ( {videoCodec} ); } if (type === mediaInfoTypes.VIDEO_DYNAMIC_RANGE_TYPE) { return ( {videoDynamicRangeType} ); } return null; } MediaInfo.propTypes = { type: PropTypes.string.isRequired, audioChannels: PropTypes.number, audioCodec: PropTypes.string, audioLanguages: PropTypes.string, subtitles: PropTypes.string, videoCodec: PropTypes.string, videoDynamicRangeType: PropTypes.string }; export default MediaInfo;