ffplayout/plugins/helpers.js

35 lines
1.0 KiB
JavaScript
Raw Normal View History

2020-04-24 13:55:51 +02:00
export default ({ app }, inject) => {
2020-04-30 17:11:26 +02:00
inject('processPlaylist', (dayStart, list) => {
const [h, m, s] = dayStart.split(':')
2020-04-24 13:55:51 +02:00
let begin = parseFloat(h) * 3600 + parseFloat(m) * 60 + parseFloat(s)
for (const item of list) {
item.begin = begin
if (!item.category) {
item.category = ''
}
begin += (item.out - item.in)
}
return list
})
// convert time (00:00:00) string to seconds
inject('timeToSeconds', (time) => {
const t = time.split(':')
return parseInt(t[0]) * 3600 + parseInt(t[1]) * 60 + parseInt(t[2])
})
inject('secToHMS', (sec) => {
let hours = Math.floor(sec / 3600)
sec %= 3600
let minutes = Math.floor(sec / 60)
let seconds = sec % 60
minutes = String(minutes).padStart(2, '0')
hours = String(hours).padStart(2, '0')
seconds = String(parseInt(seconds)).padStart(2, '0')
return hours + ':' + minutes + ':' + seconds
})
}