ffplayout/pages/player.vue

509 lines
17 KiB
Vue
Raw Normal View History

2020-04-07 17:56:46 +02:00
<template>
2024-04-08 17:07:03 +02:00
<div class="h-full">
2024-04-16 18:13:28 +02:00
<PlayerControl />
2024-04-08 17:07:03 +02:00
<div class="flex justify-end p-1">
2024-05-15 08:53:25 +02:00
<div class="h-[32px]">
<VueDatePicker
2024-05-15 08:53:25 +02:00
v-if="!configStore.playout.playlist.infinit && configStore.playout.processing.mode !== 'folder'"
v-model="listDate"
:clearable="false"
:hide-navigation="['time']"
:action-row="{ showCancel: false, showSelect: false, showPreview: false }"
:format="calendarFormat"
model-type="yyyy-MM-dd"
auto-apply
2024-04-14 00:01:45 +02:00
:locale="locale"
2024-04-09 17:21:13 +02:00
:dark="colorMode.value === 'dark'"
2024-04-17 12:32:07 +02:00
input-class-name="input input-sm !input-bordered !w-[300px] text-right !pe-3"
required
/>
2023-01-11 10:54:25 +01:00
</div>
</div>
<div class="p-1 min-h-[260px] h-[calc(100vh-800px)] xl:h-[calc(100vh-480px)]">
2024-05-15 08:53:25 +02:00
<splitpanes
v-if="configStore.playout.processing.mode === 'playlist'"
class="border border-my-gray rounded shadow"
>
<pane
v-if="width > 768"
class="relative h-full !bg-base-300 rounded-s"
min-size="0"
max-size="80"
size="20"
>
<MediaBrowser :preview="setPreviewData" />
2024-04-08 17:07:03 +02:00
</pane>
<pane>
<PlaylistTable ref="playlistTable" :edit-item="editPlaylistItem" :preview="setPreviewData" />
2024-04-08 17:07:03 +02:00
</pane>
</splitpanes>
2024-05-15 08:53:25 +02:00
<div v-else class="h-full border border-b-2 border-my-gray rounded shadow">
<MediaBrowser :preview="setPreviewData" />
</div>
2024-04-08 17:07:03 +02:00
</div>
2023-01-11 10:54:25 +01:00
2024-05-15 08:53:25 +02:00
<div v-if="configStore.playout.processing.mode === 'playlist'" class="h-16 join flex justify-end p-3">
2024-04-14 00:01:45 +02:00
<button class="btn btn-sm btn-primary join-item" :title="$t('player.copy')" @click="showCopyModal = true">
2023-01-11 10:54:25 +01:00
<i class="bi-files" />
2024-04-08 17:07:03 +02:00
</button>
<button
v-if="!configStore.playout.playlist.loop"
2024-04-08 17:07:03 +02:00
class="btn btn-sm btn-primary join-item"
2024-04-14 00:01:45 +02:00
:title="$t('player.loop')"
2023-01-11 10:54:25 +01:00
@click="loopClips()"
>
<i class="bi-view-stacked" />
2024-04-08 17:07:03 +02:00
</button>
<button
class="btn btn-sm btn-primary join-item"
2024-04-14 00:01:45 +02:00
:title="$t('player.remote')"
2024-04-08 17:07:03 +02:00
@click="showSourceModal = true"
2023-01-11 10:54:25 +01:00
>
<i class="bi-file-earmark-plus" />
2024-04-08 17:07:03 +02:00
</button>
<button
class="btn btn-sm btn-primary join-item"
2024-04-14 00:01:45 +02:00
:title="$t('player.import')"
2024-04-08 21:33:28 +02:00
@click="showImportModal = true"
2023-01-11 10:54:25 +01:00
>
<i class="bi-file-text" />
2024-04-08 17:07:03 +02:00
</button>
<button
class="btn btn-sm btn-primary join-item"
2024-04-14 00:01:45 +02:00
:title="$t('player.generate')"
2024-04-08 21:33:28 +02:00
@click="mediaStore.getTree('', true), (showPlaylistGenerator = true)"
>
2023-01-11 10:54:25 +01:00
<i class="bi-sort-down-alt" />
2024-04-08 17:07:03 +02:00
</button>
<button
class="btn btn-sm btn-primary join-item"
:title="$t('player.reset')"
@click=";(playlistStore.playlist.length = 0), playlistTable.getPlaylist()"
>
2023-01-11 10:54:25 +01:00
<i class="bi-arrow-counterclockwise" />
2024-04-08 17:07:03 +02:00
</button>
<button
class="btn btn-sm btn-primary join-item"
2024-04-14 00:01:45 +02:00
:title="$t('player.save')"
2024-04-08 21:33:28 +02:00
@click=";(targetDate = listDate), savePlaylist(true)"
2024-04-08 17:07:03 +02:00
>
2024-04-08 21:33:28 +02:00
<i class="bi-download" />
</button>
2024-04-14 21:52:31 +02:00
<button
class="btn btn-sm btn-primary join-item"
:title="$t('player.deletePlaylist')"
@click="showDeleteModal = true"
>
2023-01-11 10:54:25 +01:00
<i class="bi-trash" />
2024-04-08 17:07:03 +02:00
</button>
</div>
2024-04-16 18:13:28 +02:00
<GenericModal
:show="showPreviewModal"
:title="`${$t('media.preview')}: ${previewName}`"
:hide-buttons="true"
:modal-action="closePlayer"
>
2024-04-08 17:07:03 +02:00
<div class="w-[1024px] max-w-full aspect-video">
<VideoPlayer v-if="isVideo && previewOpt" reference="previewPlayer" :options="previewOpt" />
<img v-else :src="previewUrl" class="img-fluid" :alt="previewName" />
2023-01-11 10:54:25 +01:00
</div>
2024-04-16 18:13:28 +02:00
</GenericModal>
2023-01-11 10:54:25 +01:00
<GenericModal :show="showCopyModal" :title="$t('player.copyTo')" :modal-action="savePlaylist">
<VueDatePicker
v-model="targetDate"
:clearable="false"
:hide-navigation="['time']"
:action-row="{ showCancel: false, showSelect: false, showPreview: false }"
:format="calendarFormat"
model-type="yyyy-MM-dd"
auto-apply
:locale="locale"
:dark="colorMode.value === 'dark'"
input-class-name="input input-sm !input-bordered !w-[full text-right !pe-3"
required
/>
</GenericModal>
<GenericModal :show="showSourceModal" :title="$t('player.addEdit')" :modal-action="processSource">
2024-04-08 17:07:03 +02:00
<div>
<label class="form-control w-auto mt-auto">
2024-04-08 17:07:03 +02:00
<div class="label">
<span class="label-text">{{ $t('player.title') }}</span>
2023-01-11 10:54:25 +01:00
</div>
<input v-model.number="newSource.title" type="text" class="input input-sm input-bordered w-auto" />
</label>
2024-05-06 14:01:26 +02:00
<label class="form-control w-auto mt-auto">
<div class="label">
2024-05-06 14:01:26 +02:00
<span class="label-text">{{ $t('player.duration') }}</span>
</div>
2024-05-06 14:01:26 +02:00
<TimePicker v-model="newSource.duration" />
2024-04-08 17:07:03 +02:00
</label>
<label class="form-control w-auto mt-auto">
2024-04-08 17:07:03 +02:00
<div class="label">
2024-05-06 14:01:26 +02:00
<span class="label-text">{{ $t('player.in') }}</span>
2023-01-11 10:54:25 +01:00
</div>
2024-05-06 14:01:26 +02:00
<TimePicker v-model="newSource.in" />
2024-04-08 17:07:03 +02:00
</label>
2023-01-11 10:54:25 +01:00
<label class="form-control w-auto mt-auto">
2024-04-08 17:07:03 +02:00
<div class="label">
2024-05-06 14:01:26 +02:00
<span class="label-text">{{ $t('player.out') }}</span>
2023-01-11 10:54:25 +01:00
</div>
2024-05-06 14:01:26 +02:00
<TimePicker v-model="newSource.out" />
2024-04-08 17:07:03 +02:00
</label>
<label class="form-control w-auto mt-auto">
2024-04-08 17:07:03 +02:00
<div class="label">
<span class="label-text">{{ $t('player.file') }}</span>
2024-04-08 17:07:03 +02:00
</div>
<input v-model="newSource.source" type="text" class="input input-sm input-bordered w-auto" />
2024-04-08 17:07:03 +02:00
</label>
<label class="form-control w-auto mt-auto">
2024-04-08 17:07:03 +02:00
<div class="label">
<span class="label-text">{{ $t('player.audio') }}</span>
2024-04-08 17:07:03 +02:00
</div>
<input v-model="newSource.audio" type="text" class="input input-sm input-bordered w-auto" />
2024-04-08 17:07:03 +02:00
</label>
<label class="form-control w-auto mt-auto">
2024-04-08 17:07:03 +02:00
<div class="label">
<span class="label-text">{{ $t('player.customFilter') }}</span>
2024-04-08 17:07:03 +02:00
</div>
<input v-model="newSource.custom_filter" type="text" class="input input-sm input-bordered w-auto" />
2024-04-08 17:07:03 +02:00
</label>
<div class="form-control">
<label class="cursor-pointer label">
<span class="label-text">{{ $t('player.ad') }}</span>
2024-05-06 15:03:50 +02:00
<input
type="checkbox"
class="checkbox checkbox-sm"
:checked="newSource.category === 'advertisement'"
@click="isAd"
/>
2024-04-08 17:07:03 +02:00
</label>
2023-01-11 10:54:25 +01:00
</div>
</div>
2024-04-16 18:13:28 +02:00
</GenericModal>
2023-01-11 10:54:25 +01:00
<GenericModal :show="showImportModal" :title="$t('player.import')" :modal-action="importPlaylist">
2024-04-08 21:33:28 +02:00
<input
type="file"
class="file-input file-input-sm file-input-bordered w-full"
multiple
2024-04-16 18:13:28 +02:00
@change="onFileChange"
/>
2024-04-16 18:13:28 +02:00
</GenericModal>
2023-01-11 10:54:25 +01:00
2024-04-16 18:13:28 +02:00
<GenericModal :show="showDeleteModal" title="Delete Program" :modal-action="deletePlaylist">
2024-04-08 21:33:28 +02:00
<span>
{{ $t('player.deleteFrom') }} <strong>{{ listDate }}</strong>
2024-04-08 21:33:28 +02:00
</span>
2024-04-16 18:13:28 +02:00
</GenericModal>
<PlaylistGenerator
v-if="showPlaylistGenerator"
:close="closeGenerator"
:switch-class="playlistTable.classSwitcher"
/>
2020-04-07 17:56:46 +02:00
</div>
</template>
2023-01-11 10:54:25 +01:00
<script setup lang="ts">
2023-03-22 16:01:58 +01:00
import { storeToRefs } from 'pinia'
2023-01-11 10:54:25 +01:00
const colorMode = useColorMode()
2024-04-16 14:07:50 +02:00
const { locale, t } = useI18n()
2023-01-11 10:54:25 +01:00
const { $_, $dayjs } = useNuxtApp()
const { width } = useWindowSize({ initialWidth: 800 })
const { mediaType } = stringFormatter()
2023-01-11 10:54:25 +01:00
const { processPlaylist, genUID } = playlistOperations()
const authStore = useAuth()
const configStore = useConfig()
const indexStore = useIndex()
const mediaStore = useMedia()
const playlistStore = usePlaylist()
useHead({
2024-04-16 14:07:50 +02:00
title: `${t('button.player')} | ffplayout`,
2023-01-11 10:54:25 +01:00
})
2024-04-08 21:33:28 +02:00
const { listDate } = storeToRefs(usePlaylist())
2023-03-22 16:01:58 +01:00
2023-01-11 10:54:25 +01:00
const targetDate = ref($dayjs().utcOffset(configStore.utcOffset).format('YYYY-MM-DD'))
const playlistTable = ref()
2023-01-11 10:54:25 +01:00
const editId = ref(-1)
const textFile = ref()
2024-04-08 17:07:03 +02:00
const showPreviewModal = ref(false)
const showSourceModal = ref(false)
2024-04-08 21:33:28 +02:00
const showImportModal = ref(false)
const showCopyModal = ref(false)
const showDeleteModal = ref(false)
const showPlaylistGenerator = ref(false)
2024-04-08 17:07:03 +02:00
2023-01-11 10:54:25 +01:00
const previewName = ref('')
const previewUrl = ref('')
const previewOpt = ref()
const isVideo = ref(false)
2024-04-08 21:33:28 +02:00
2023-01-11 10:54:25 +01:00
const newSource = ref({
begin: 0,
2024-05-05 21:46:22 +02:00
title: null,
2023-01-11 10:54:25 +01:00
in: 0,
out: 0,
duration: 0,
category: '',
custom_filter: '',
source: '',
audio: '',
uid: '',
2023-01-11 10:54:25 +01:00
} as PlaylistItem)
2024-05-15 08:53:25 +02:00
onMounted(() => {
if (configStore.onetimeInfo && configStore.playout.playlist.infinit) {
indexStore.msgAlert('warning', t('player.infinitInfo'), 7)
configStore.onetimeInfo = false
}
})
const calendarFormat = (date: Date) => {
2024-04-15 17:39:41 +02:00
return $dayjs(date).locale(locale.value).format('dddd - LL')
}
2024-04-08 21:42:12 +02:00
function closeGenerator() {
showPlaylistGenerator.value = false
}
2023-01-11 10:54:25 +01:00
function closePlayer() {
2024-04-08 17:07:03 +02:00
showPreviewModal.value = false
2023-01-11 10:54:25 +01:00
isVideo.value = false
}
2023-01-11 10:54:25 +01:00
function setPreviewData(path: string) {
let fullPath = path
const storagePath = configStore.playout.storage.path
2023-08-06 23:27:10 +02:00
const lastIndex = storagePath.lastIndexOf('/')
2023-01-11 10:54:25 +01:00
if (!path.includes('/')) {
const parent = mediaStore.folderTree.parent ? mediaStore.folderTree.parent : ''
fullPath = `/${parent}/${mediaStore.folderTree.source}/${path}`.replace(/\/[/]+/g, '/')
2023-08-06 23:27:10 +02:00
} else if (lastIndex !== -1) {
2024-04-16 14:07:50 +02:00
fullPath = path.replace(storagePath.substring(0, lastIndex), '')
2023-01-11 10:54:25 +01:00
}
2022-07-06 16:22:27 +02:00
2023-01-11 10:54:25 +01:00
previewName.value = fullPath.split('/').slice(-1)[0]
showPreviewModal.value = true
if (path.match(/^http/)) {
previewUrl.value = path
} else {
2024-02-09 11:21:52 +01:00
previewUrl.value = encodeURIComponent(
2024-06-12 09:17:44 +02:00
`/file/${configStore.configChannel[configStore.configID].id}${fullPath}`
2024-02-09 11:21:52 +01:00
).replace(/%2F/g, '/')
}
2022-07-06 16:22:27 +02:00
2023-01-11 10:54:25 +01:00
const ext = previewName.value.split('.').slice(-1)[0].toLowerCase()
const fileType =
mediaType(previewName.value) === 'audio'
? `audio/${ext}`
: mediaType(previewName.value) === 'live'
? 'application/x-mpegURL'
: `video/${ext}`
if (configStore.playout.storage.extensions.includes(`${ext}`)) {
2023-01-11 10:54:25 +01:00
isVideo.value = true
previewOpt.value = {
liveui: false,
controls: true,
suppressNotSupportedError: true,
autoplay: false,
preload: 'auto',
sources: [
{
type: fileType,
src: previewUrl.value,
},
],
2020-04-07 17:56:46 +02:00
}
2023-01-11 10:54:25 +01:00
} else {
isVideo.value = false
2020-04-07 17:56:46 +02:00
}
}
2020-04-17 15:02:11 +02:00
2024-04-08 17:07:03 +02:00
function processSource(process: boolean) {
showSourceModal.value = false
if (process) {
if (editId.value === -1) {
playlistStore.playlist.push(newSource.value)
} else {
playlistStore.playlist[editId.value] = newSource.value
}
processPlaylist(listDate.value, playlistStore.playlist, false)
playlistTable.value.classSwitcher()
2023-01-11 10:54:25 +01:00
}
2020-04-22 17:19:41 +02:00
2023-01-11 10:54:25 +01:00
editId.value = -1
newSource.value = {
begin: 0,
title: '',
2023-01-11 10:54:25 +01:00
in: 0,
out: 0,
duration: 0,
category: '',
custom_filter: '',
source: '',
audio: '',
uid: genUID(),
2023-01-11 10:54:25 +01:00
}
2020-04-22 17:19:41 +02:00
}
2023-01-11 10:54:25 +01:00
function editPlaylistItem(i: number) {
editId.value = i
showSourceModal.value = true
2020-04-22 17:19:41 +02:00
2023-01-11 10:54:25 +01:00
newSource.value = {
begin: playlistStore.playlist[i].begin,
title: playlistStore.playlist[i].title,
2023-01-11 10:54:25 +01:00
in: playlistStore.playlist[i].in,
out: playlistStore.playlist[i].out,
duration: playlistStore.playlist[i].duration,
category: playlistStore.playlist[i].category,
custom_filter: playlistStore.playlist[i].custom_filter,
source: playlistStore.playlist[i].source,
audio: playlistStore.playlist[i].audio,
uid: playlistStore.playlist[i].uid,
2023-01-11 10:54:25 +01:00
}
2020-04-22 17:19:41 +02:00
}
2023-01-11 10:54:25 +01:00
function isAd(evt: any) {
if (evt.target.checked) {
newSource.value.category = 'advertisement'
} else {
newSource.value.category = ''
}
2020-04-22 17:19:41 +02:00
}
2023-01-11 10:54:25 +01:00
function loopClips() {
const tempList = []
let length = 0
while (length < configStore.playlistLength && playlistStore.playlist.length > 0) {
2023-01-11 10:54:25 +01:00
for (const item of playlistStore.playlist) {
if (length < configStore.playlistLength) {
item.uid = genUID()
2023-01-11 10:54:25 +01:00
tempList.push($_.cloneDeep(item))
length += item.out - item.in
} else {
break
}
}
}
playlistStore.playlist = processPlaylist(listDate.value, tempList, false)
}
2024-04-15 21:19:45 +02:00
function onFileChange(evt: any) {
const files = evt.target.files || evt.dataTransfer.files
if (!files.length) {
return
}
textFile.value = files
}
2024-04-08 21:33:28 +02:00
async function importPlaylist(imp: boolean) {
showImportModal.value = false
2023-01-11 10:54:25 +01:00
2024-04-08 21:33:28 +02:00
if (imp) {
if (!textFile.value || !textFile.value[0]) {
return
2023-01-11 10:54:25 +01:00
}
2024-04-08 21:33:28 +02:00
const formData = new FormData()
formData.append(textFile.value[0].name, textFile.value[0])
playlistStore.isLoading = true
2024-04-08 21:33:28 +02:00
await $fetch(
2024-06-12 09:17:44 +02:00
`/api/file/${configStore.configChannel[configStore.configID].id}/import/?file=${textFile.value[0].name}&date=${
2024-04-14 00:01:45 +02:00
listDate.value
}`,
2024-04-08 21:33:28 +02:00
{
method: 'PUT',
headers: authStore.authHeader,
body: formData,
}
)
.then(async (response) => {
indexStore.msgAlert('success', String(response), 2)
await playlistStore.getPlaylist(listDate.value)
playlistTable.value.classSwitcher()
2024-04-08 21:33:28 +02:00
})
.catch((e: string) => {
indexStore.msgAlert('error', e, 4)
2024-04-08 21:33:28 +02:00
})
}
2023-01-11 10:54:25 +01:00
playlistStore.isLoading = false
2023-01-11 10:54:25 +01:00
textFile.value = null
}
2024-04-08 21:33:28 +02:00
async function savePlaylist(save: boolean) {
showCopyModal.value = false
2024-04-08 21:33:28 +02:00
if (save) {
if (playlistStore.playlist.length === 0) {
return
}
2023-01-11 10:54:25 +01:00
const saveList = processPlaylist(listDate.value, $_.cloneDeep(playlistStore.playlist), true)
2024-04-08 21:33:28 +02:00
2024-06-12 09:17:44 +02:00
await $fetch(`/api/playlist/${configStore.configChannel[configStore.configID].id}/`, {
2024-04-08 21:33:28 +02:00
method: 'POST',
2024-04-16 14:07:50 +02:00
headers: { ...configStore.contentType, ...authStore.authHeader },
2024-04-08 21:33:28 +02:00
body: JSON.stringify({
2024-06-12 09:17:44 +02:00
channel: configStore.configChannel[configStore.configID].name,
2024-04-08 21:33:28 +02:00
date: targetDate.value,
program: saveList,
}),
2023-01-11 10:54:25 +01:00
})
2024-04-08 21:33:28 +02:00
.then((response: any) => {
playlistTable.value.classSwitcher()
indexStore.msgAlert('success', response, 2)
2024-04-08 21:33:28 +02:00
})
.catch((e: any) => {
if (e.status === 409) {
indexStore.msgAlert('warning', e.data, 2)
2024-04-08 21:33:28 +02:00
} else {
indexStore.msgAlert('error', e, 4)
2024-04-08 21:33:28 +02:00
}
})
}
2020-05-12 12:12:18 +02:00
}
2024-04-08 21:33:28 +02:00
async function deletePlaylist(del: boolean) {
showDeleteModal.value = false
2024-04-08 21:33:28 +02:00
if (del) {
2024-06-12 09:17:44 +02:00
await $fetch(`/api/playlist/${configStore.configChannel[configStore.configID].id}/${listDate.value}`, {
2024-04-08 21:33:28 +02:00
method: 'DELETE',
2024-04-16 14:07:50 +02:00
headers: { ...configStore.contentType, ...authStore.authHeader },
2024-04-08 21:33:28 +02:00
}).then(() => {
playlistStore.playlist = []
playlistTable.value.classSwitcher()
indexStore.msgAlert('warning', t('player.deleteSuccess'), 2)
2024-04-08 21:33:28 +02:00
})
}
}
2023-01-11 10:54:25 +01:00
</script>