2022-01-26 07:12:30 +04:00
|
|
|
import {Box, IconButton} from '@mui/material'
|
2021-07-15 00:58:21 +02:00
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
import {useRouter} from 'next/router'
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
Tidal,
|
|
|
|
|
Spotify,
|
|
|
|
|
Deezer,
|
2022-05-23 19:43:10 +04:00
|
|
|
Soundcloud,
|
2023-03-07 08:56:53 +04:00
|
|
|
Applemusic,
|
|
|
|
|
Peertube
|
2021-07-15 00:58:21 +02:00
|
|
|
} from '@icons-pack/react-simple-icons'
|
|
|
|
|
import {useEffect, useState} from 'react'
|
|
|
|
|
|
|
|
|
|
const kouteyAchteyIcons = {
|
|
|
|
|
Tidal: <Tidal />,
|
|
|
|
|
Deezer: <Deezer />,
|
|
|
|
|
Spotify: <Spotify />,
|
2022-05-23 19:43:10 +04:00
|
|
|
Soundcloud: <Soundcloud />,
|
|
|
|
|
Applemusic: <Applemusic />
|
2021-07-15 00:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-07 08:56:53 +04:00
|
|
|
function RannIframe({plateforme, url, titre, isMobile}) {
|
2021-07-15 00:58:21 +02:00
|
|
|
let src = ''
|
2022-05-20 02:20:09 +04:00
|
|
|
switch (plateforme) {
|
2022-01-18 09:08:26 +04:00
|
|
|
case 'Tidal': {
|
|
|
|
|
const trackArray = url.split('/')
|
|
|
|
|
const trackId = trackArray[trackArray.length - 1]
|
|
|
|
|
src = `https://embed.tidal.com/tracks/${trackId}?disableAnalytics=true`
|
|
|
|
|
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 'Deezer': {
|
|
|
|
|
const trackArray = url.split('/')
|
|
|
|
|
const trackId = trackArray[trackArray.length - 1]
|
|
|
|
|
src = `https://widget.deezer.com/widget/auto/track/${trackId}?tracklist=false`
|
|
|
|
|
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 'Spotify': {
|
|
|
|
|
const trackArray = url.split('/')
|
|
|
|
|
const trackId = trackArray[trackArray.length - 1]
|
|
|
|
|
src = `https://open.spotify.com/embed/track/${trackId}`
|
|
|
|
|
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 'Soundcloud': {
|
|
|
|
|
src = `https://w.soundcloud.com/player/?url=${url}`
|
|
|
|
|
|
|
|
|
|
break
|
|
|
|
|
}
|
2022-05-23 19:43:10 +04:00
|
|
|
|
|
|
|
|
case 'Applemusic': {
|
|
|
|
|
const embedUrl = url.replace('//music', '//embed.music')
|
|
|
|
|
src = embedUrl
|
|
|
|
|
|
|
|
|
|
break
|
|
|
|
|
}
|
2022-01-18 09:08:26 +04:00
|
|
|
// No default
|
2021-07-15 00:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div style={{marginTop: 5}}>
|
2022-05-20 02:20:09 +04:00
|
|
|
{plateforme === 'Tidal' && (
|
2021-07-15 00:58:21 +02:00
|
|
|
<iframe
|
|
|
|
|
src={src}
|
|
|
|
|
allowFullScreen='allowfullscreen'
|
|
|
|
|
frameBorder='0'
|
|
|
|
|
width={`${isMobile ? '100%' : '50%'}`}
|
|
|
|
|
height='96px'
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
2023-03-07 08:56:53 +04:00
|
|
|
{plateforme === 'Gade' && (
|
|
|
|
|
<iframe
|
|
|
|
|
src={`${url}?subtitle=fr&warningTitle=0&peertubeLink=0`}
|
|
|
|
|
allowFullScreen='allowfullscreen'
|
|
|
|
|
title={titre}
|
|
|
|
|
frameBorder='0'
|
|
|
|
|
height={isMobile ? '' : '315'}
|
|
|
|
|
width={isMobile ? '' : '560'}
|
|
|
|
|
sandbox='allow-same-origin allow-scripts allow-popups'
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
2022-05-20 02:20:09 +04:00
|
|
|
{plateforme === 'Deezer' && (
|
2021-07-15 00:58:21 +02:00
|
|
|
<iframe
|
|
|
|
|
title='deezer-widget'
|
|
|
|
|
frameBorder='0'
|
|
|
|
|
src={src}
|
|
|
|
|
allow='encrypted-media; clipboard-write'
|
|
|
|
|
allowtransparency='true'
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
2022-05-20 02:20:09 +04:00
|
|
|
{plateforme === 'Spotify' && (
|
2021-07-15 00:58:21 +02:00
|
|
|
<iframe
|
|
|
|
|
src={src}
|
|
|
|
|
width={`${isMobile ? '100%' : '50%'}`}
|
|
|
|
|
height='80'
|
|
|
|
|
frameBorder='0'
|
|
|
|
|
allowtransparency='true'
|
|
|
|
|
allow='encrypted-media'
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
2022-05-20 02:20:09 +04:00
|
|
|
{plateforme === 'Soundcloud' && (
|
2021-07-15 00:58:21 +02:00
|
|
|
<iframe
|
|
|
|
|
src={src}
|
|
|
|
|
width={`${isMobile ? '100%' : '50%'}`}
|
|
|
|
|
height='166'
|
|
|
|
|
scrolling='no'
|
|
|
|
|
frameBorder='no'
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
2022-05-23 19:43:10 +04:00
|
|
|
{plateforme === 'Applemusic' && (
|
|
|
|
|
<iframe
|
|
|
|
|
src={src}
|
|
|
|
|
width={`${isMobile ? '100%' : '50%'}`}
|
|
|
|
|
height='175'
|
|
|
|
|
frameBorder='0'
|
|
|
|
|
allowtransparency='true'
|
|
|
|
|
allow='encrypted-media'
|
|
|
|
|
sandbox='allow-forms allow-popups allow-same-origin allow-scripts allow-storage-access-by-user-activation allow-top-navigation-by-user-activation'
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2021-07-15 00:58:21 +02:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-20 02:20:09 +04:00
|
|
|
function EntegreMizik({parole, isMobile}) {
|
2021-07-15 00:58:21 +02:00
|
|
|
const [chwaMizik, meteChwaMizik] = useState(null)
|
|
|
|
|
const router = useRouter()
|
2023-03-07 08:56:53 +04:00
|
|
|
const {streamAudio, slug, okiMizikID, gadeEmbed, titre} = parole
|
|
|
|
|
|
2022-05-23 19:43:10 +04:00
|
|
|
const filteredKouteyAchtey = streamAudio.filter(({plateforme}) => plateforme === 'Tidal' || plateforme === 'Spotify' || plateforme === 'Deezer' || plateforme === 'Soundcloud' || plateforme === 'Applemusic')
|
2021-07-15 00:58:21 +02:00
|
|
|
|
2023-03-07 08:56:53 +04:00
|
|
|
const handleClick = (plateforme, url, titre = null) => {
|
2022-05-20 02:20:09 +04:00
|
|
|
if (chwaMizik && chwaMizik.plateforme === plateforme) {
|
2021-07-15 00:58:21 +02:00
|
|
|
return meteChwaMizik(null)
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-07 08:56:53 +04:00
|
|
|
meteChwaMizik({plateforme, url, titre})
|
2021-07-15 00:58:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-03-13 01:38:45 +04:00
|
|
|
if (router.asPath === `/paroles/${slug}` || router.asPath === `/paroles/${slug}#${slug}`) {
|
2021-07-15 00:58:21 +02:00
|
|
|
meteChwaMizik(null)
|
|
|
|
|
}
|
|
|
|
|
}, [router, slug])
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box align='center'>
|
2023-06-11 19:24:26 +04:00
|
|
|
{!okiMizikID && filteredKouteyAchtey.map(({id, plateforme, url}) => (
|
2023-03-07 08:56:53 +04:00
|
|
|
<IconButton
|
2023-06-11 19:24:26 +04:00
|
|
|
key={id}
|
2023-03-07 08:56:53 +04:00
|
|
|
aria-label='player'
|
|
|
|
|
size='large'
|
2023-06-11 19:24:26 +04:00
|
|
|
onClick={() => handleClick(plateforme, url)}
|
2023-03-07 08:56:53 +04:00
|
|
|
>
|
2023-06-11 19:24:26 +04:00
|
|
|
{kouteyAchteyIcons[plateforme]}
|
2023-03-07 08:56:53 +04:00
|
|
|
</IconButton>
|
2023-06-11 19:24:26 +04:00
|
|
|
))}
|
2023-03-07 08:56:53 +04:00
|
|
|
|
2023-06-11 19:24:26 +04:00
|
|
|
{!okiMizikID && gadeEmbed && (
|
2022-01-19 07:06:26 +04:00
|
|
|
<IconButton
|
|
|
|
|
aria-label='player'
|
|
|
|
|
size='large'
|
2023-06-11 19:24:26 +04:00
|
|
|
onClick={() => handleClick('Gade', gadeEmbed, titre)}
|
2022-01-19 07:06:26 +04:00
|
|
|
>
|
2023-06-11 19:24:26 +04:00
|
|
|
<Peertube />
|
2022-01-18 09:08:26 +04:00
|
|
|
</IconButton>
|
2023-06-11 19:24:26 +04:00
|
|
|
)}
|
2021-07-15 00:58:21 +02:00
|
|
|
|
|
|
|
|
{chwaMizik && (
|
2023-03-07 08:56:53 +04:00
|
|
|
<RannIframe plateforme={chwaMizik.plateforme} url={chwaMizik.url} titre={chwaMizik.titre} isMobile={isMobile} />
|
2021-07-15 00:58:21 +02:00
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EntegreMizik.propTypes = {
|
2022-05-20 02:20:09 +04:00
|
|
|
parole: PropTypes.object.isRequired,
|
2021-07-15 00:58:21 +02:00
|
|
|
isMobile: PropTypes.bool.isRequired
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RannIframe.propTypes = {
|
2022-05-20 02:20:09 +04:00
|
|
|
plateforme: PropTypes.string.isRequired,
|
2021-07-15 00:58:21 +02:00
|
|
|
url: PropTypes.string.isRequired,
|
2023-03-07 08:56:53 +04:00
|
|
|
titre: PropTypes.string,
|
2021-07-15 00:58:21 +02:00
|
|
|
isMobile: PropTypes.bool.isRequired
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-07 08:56:53 +04:00
|
|
|
RannIframe.defaultProp = {
|
|
|
|
|
titre: null
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-15 00:58:21 +02:00
|
|
|
export default EntegreMizik
|