Skip to content

Commit

Permalink
local API: Add support for PageHeader hashtag header (FreeTubeApp#3896)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue committed Aug 20, 2023
1 parent 3d08bd7 commit 3236ce8
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/renderer/views/Hashtag/Hashtag.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,26 @@ export default defineComponent({
getLocalHashtag: async function(hashtag) {
try {
const hashtagData = await getHashtagLocal(hashtag)
this.hashtag = hashtagData.header.hashtag
this.videos = hashtagData.contents.contents.filter(item =>
item.type !== 'ContinuationItem'
).map(item =>
parseLocalListVideo(item.content)
)

const header = hashtagData.header
if (header) {
switch (header.type) {
case 'HashtagHeader':
this.hashtag = header.hashtag.toString()
break
case 'PageHeader':
this.hashtag = header.content.title.text
break
default:
console.error(`Unknown hashtag header type: ${header.type}, falling back to query parameter.`)
this.hashtag = `#${hashtag}`
}
} else {
console.error(' Hashtag header missing, probably a layout change, falling back to query parameter.')
this.hashtag = `#${hashtag}`
}

this.videos = hashtagData.videos.map(parseLocalListVideo)
this.apiUsed = 'local'
this.hashtagContinuationData = hashtagData.has_continuation ? hashtagData : null
this.isLoading = false
Expand All @@ -124,12 +138,8 @@ export default defineComponent({

getLocalHashtagMore: async function() {
try {
const continuation = await this.hashtagContinuationData.getContinuationData()
const newVideos = continuation.on_response_received_actions[0].contents.filter(item =>
item.type !== 'ContinuationItem'
).map(item =>
parseLocalListVideo(item.content)
)
const continuation = await this.hashtagContinuationData.getContinuation()
const newVideos = continuation.videos.map(parseLocalListVideo)
this.hashtagContinuationData = continuation.has_continuation ? continuation : null
this.videos = this.videos.concat(newVideos)
} catch (error) {
Expand Down

0 comments on commit 3236ce8

Please sign in to comment.