mirror of
https://git.sr.ht/~cadence/cloudtube
synced 2026-03-02 10:41:36 +00:00
Implement watched videos
Watched videos on your subscriptions feed will be darkened, and the option to hide all of them has been added. This only takes effect if you have enabled saving watched videos on the server in the settings menu - default is off.
This commit is contained in:
parent
c3afe77e2d
commit
e0bc0d2e81
12 changed files with 106 additions and 34 deletions
|
|
@ -22,6 +22,8 @@ module.exports = [
|
|||
channels = db.prepare(`SELECT * FROM Channels WHERE ucid IN (${template}) ORDER BY name`).all(subscriptions)
|
||||
// get refreshed status
|
||||
refreshed = db.prepare(`SELECT min(refreshed) as min, max(refreshed) as max, count(refreshed) as count FROM Channels WHERE ucid IN (${template})`).get(subscriptions)
|
||||
// get watched videos
|
||||
const watchedVideos = user.getWatchedVideos()
|
||||
// get videos
|
||||
if (subscriptions.length) {
|
||||
hasSubscriptions = true
|
||||
|
|
@ -29,12 +31,15 @@ module.exports = [
|
|||
videos = db.prepare(`SELECT * FROM Videos WHERE authorId IN (${template}) ORDER BY published DESC LIMIT 60`).all(subscriptions)
|
||||
.map(video => {
|
||||
video.publishedText = timeToPastText(video.published * 1000)
|
||||
console.log(watchedVideos, video.videoId)
|
||||
video.watched = watchedVideos.includes(video.videoId)
|
||||
return video
|
||||
})
|
||||
}
|
||||
}
|
||||
const instanceOrigin = user.getSettingsOrDefaults().instance
|
||||
return render(200, "pug/subscriptions.pug", {hasSubscriptions, videos, channels, refreshed, timeToPastText, instanceOrigin})
|
||||
const settings = user.getSettingsOrDefaults()
|
||||
const instanceOrigin = settings.instance
|
||||
return render(200, "pug/subscriptions.pug", {settings, hasSubscriptions, videos, channels, refreshed, timeToPastText, instanceOrigin})
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
15
api/video.js
15
api/video.js
|
|
@ -37,22 +37,35 @@ function formatOrder(format) {
|
|||
|
||||
async function renderVideo(videoPromise, {user, id, instanceOrigin}) {
|
||||
try {
|
||||
// resolve video
|
||||
const video = await videoPromise
|
||||
if (!video) throw new Error("The instance returned null.")
|
||||
if (video.error) throw new InstanceError(video.error, video.identifier)
|
||||
// video data additional processing
|
||||
// process stream list ordering
|
||||
for (const format of video.formatStreams.concat(video.adaptiveFormats)) {
|
||||
if (!format.second__height && format.resolution) format.second__height = +format.resolution.slice(0, -1)
|
||||
if (!format.second__order) format.second__order = formatOrder(format)
|
||||
}
|
||||
// process length text
|
||||
for (const rec of video.recommendedVideos) {
|
||||
if (!rec.second__lengthText && rec.lengthSeconds > 0) {
|
||||
rec.second__lengthText = converters.lengthSecondsToLengthText(rec.lengthSeconds)
|
||||
}
|
||||
}
|
||||
// get subscription data
|
||||
const subscribed = user.isSubscribed(video.authorId)
|
||||
// process watched videos
|
||||
user.addWatchedVideoMaybe(video.videoId)
|
||||
const watchedVideos = user.getWatchedVideos()
|
||||
if (watchedVideos.length) {
|
||||
for (const rec of video.recommendedVideos) {
|
||||
rec.watched = watchedVideos.includes(rec.videoId)
|
||||
}
|
||||
}
|
||||
return render(200, "pug/video.pug", {video, subscribed, instanceOrigin})
|
||||
} catch (e) {
|
||||
// show an appropriate error message
|
||||
// these should probably be split out to their own files
|
||||
let message = pug.render("pre= error", {error: e.stack || e.toString()})
|
||||
if (e instanceof fetch.FetchError) {
|
||||
const template = `
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue