1
0
Fork 0
mirror of https://git.sr.ht/~cadence/cloudtube synced 2026-05-26 12:32:25 +00:00

Implement video filters

This commit is contained in:
Cadence Ember 2021-05-12 00:29:44 +12:00
parent aa953dc796
commit db7ccabb3b
No known key found for this signature in database
GPG key ID: BC1C2C61CF521B17
19 changed files with 790 additions and 9 deletions

View file

@ -1,5 +1,6 @@
const constants = require("./constants")
const pug = require("pug")
const {Matcher} = require("./matcher")
function timeToPastText(timestamp) {
const difference = Date.now() - timestamp
@ -162,6 +163,24 @@ function subscriberCountToText(count) {
return preroundedCountToText(count) + " subscribers"
}
function applyVideoFilters(videos, filters) {
const originalCount = videos.length
for (const filter of filters) {
if (filter.type === "channel-id") {
videos = videos.filter(v => v.authorId !== filter.data)
} else if (filter.type === "channel-name") {
videos = videos.filter(v => v.author !== filter.data)
} else if (filter.type === "title") {
const matcher = new Matcher(filter.data)
matcher.compilePattern()
videos = videos.filter(v => !matcher.match(v.title))
}
}
const filteredCount = originalCount - videos.length
//TODO: actually display if things were filtered, and give the option to disable filters one time
return {videos, filteredCount}
}
module.exports.timeToPastText = timeToPastText
module.exports.lengthSecondsToLengthText = lengthSecondsToLengthText
module.exports.normaliseVideoInfo = normaliseVideoInfo
@ -169,3 +188,4 @@ module.exports.rewriteVideoDescription = rewriteVideoDescription
module.exports.tToMediaFragment = tToMediaFragment
module.exports.viewCountToText = viewCountToText
module.exports.subscriberCountToText = subscriberCountToText
module.exports.applyVideoFilters = applyVideoFilters