mirror of
https://git.sr.ht/~cadence/cloudtube
synced 2024-11-10 02:27:29 +00:00
Normalise info for both channels and search
This commit is contained in:
parent
ac28332ac0
commit
c419aa90da
@ -2,6 +2,7 @@ const {render} = require("pinski/plugins")
|
|||||||
const constants = require("../utils/constants")
|
const constants = require("../utils/constants")
|
||||||
const {fetchChannel} = require("../utils/youtube")
|
const {fetchChannel} = require("../utils/youtube")
|
||||||
const {getUser} = require("../utils/getuser")
|
const {getUser} = require("../utils/getuser")
|
||||||
|
const converters = require("../utils/converters")
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
{
|
{
|
||||||
@ -12,10 +13,11 @@ module.exports = [
|
|||||||
const data = await fetchChannel(id, settings.instance)
|
const data = await fetchChannel(id, settings.instance)
|
||||||
const subscribed = user.isSubscribed(id)
|
const subscribed = user.isSubscribed(id)
|
||||||
const instanceOrigin = settings.instance
|
const instanceOrigin = settings.instance
|
||||||
// apply watched status
|
// normalise info, apply watched status
|
||||||
const watchedVideos = user.getWatchedVideos()
|
const watchedVideos = user.getWatchedVideos()
|
||||||
if (data.latestVideos) {
|
if (data.latestVideos) {
|
||||||
data.latestVideos.forEach(video => {
|
data.latestVideos.forEach(video => {
|
||||||
|
converters.normaliseVideoInfo(video)
|
||||||
video.watched = watchedVideos.includes(video.videoId)
|
video.watched = watchedVideos.includes(video.videoId)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -13,16 +13,7 @@ module.exports = [
|
|||||||
const results = await fetch(fetchURL.toString()).then(res => res.json())
|
const results = await fetch(fetchURL.toString()).then(res => res.json())
|
||||||
|
|
||||||
for (const video of results) {
|
for (const video of results) {
|
||||||
if (!video.second__lengthText && video.lengthSeconds > 0) {
|
converters.normaliseVideoInfo(video)
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(200, "pug/search.pug", {query, results, instanceOrigin})
|
return render(200, "pug/search.pug", {query, results, instanceOrigin})
|
||||||
|
@ -27,5 +27,29 @@ function lengthSecondsToLengthText(seconds) {
|
|||||||
.join(":")
|
.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.timeToPastText = timeToPastText
|
||||||
module.exports.lengthSecondsToLengthText = lengthSecondsToLengthText
|
module.exports.lengthSecondsToLengthText = lengthSecondsToLengthText
|
||||||
|
module.exports.normaliseVideoInfo = normaliseVideoInfo
|
||||||
|
Loading…
Reference in New Issue
Block a user