1
0
Fork 0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2026-03-02 02:31:35 +00:00

Normalise info for both channels and search

This commit is contained in:
Cadence Ember 2021-01-12 14:53:30 +13:00
parent ac28332ac0
commit c419aa90da
No known key found for this signature in database
GPG key ID: BC1C2C61CF521B17
3 changed files with 28 additions and 11 deletions

View file

@ -27,5 +27,29 @@ function lengthSecondsToLengthText(seconds) {
.join(":")
}
/**
* Second and Invidious don't return quite the same data. This
* function normalises them so that all the useful properties are
* available no matter the kind of instance. The video is modified
* in-place.
*
* Changes:
* - second__lengthText is added, may be [hh:]mm:ss or "LIVE"
* - publishedText may be changed to "Live now"
*/
function normaliseVideoInfo(video) {
if (!video.second__lengthText && video.lengthSeconds > 0) {
video.second__lengthText = converters.lengthSecondsToLengthText(video.lengthSeconds)
}
if (!video.second__lengthText && video.lengthSeconds === 0) {
video.second__lengthText = "LIVE"
video.liveNow = true
}
if (video.publishedText === "0 seconds ago") {
video.publishedText = "Live now"
}
}
module.exports.timeToPastText = timeToPastText
module.exports.lengthSecondsToLengthText = lengthSecondsToLengthText
module.exports.normaliseVideoInfo = normaliseVideoInfo