Skip to content

Commit 06df4b7

Browse files
authored
Add custom title rule for YouTube (#2267)
1 parent a634b05 commit 06df4b7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

api/resolvers/item.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import { verifyHmac } from './wallet'
2828
import { parse } from 'tldts'
2929
import { shuffleArray } from '@/lib/rand'
3030

31-
metadataRuleSets.title.rules.unshift(['h1 > yt-formatted-string.ytd-watch-metadata', el => el.getAttribute('title')])
32-
3331
function commentsOrderByClause (me, models, sort) {
3432
const sharedSortsArray = []
3533
sharedSortsArray.push('("Item"."pinId" IS NOT NULL) DESC')
@@ -597,7 +595,13 @@ export default {
597595
const response = await fetch(ensureProtocol(url), { redirect: 'follow' })
598596
const html = await response.text()
599597
const doc = domino.createWindow(html).document
600-
const metadata = getMetadata(doc, url, { title: metadataRuleSets.title, publicationDate: publicationDateRuleSet })
598+
const titleRuleSet = {
599+
rules: [
600+
['h1 > yt-formatted-string.ytd-watch-metadata', el => el.getAttribute('title')],
601+
...metadataRuleSets.title.rules
602+
]
603+
}
604+
const metadata = getMetadata(doc, url, { title: titleRuleSet, publicationDate: publicationDateRuleSet })
601605
const dateHint = ` (${metadata.publicationDate?.getFullYear()})`
602606
const moreThanOneYearAgo = metadata.publicationDate && metadata.publicationDate < datePivot(new Date(), { years: -1 })
603607

0 commit comments

Comments
 (0)