Local Video Search Results, List-Video Parsers

Added:
Local Video Search Results - The results returned from ytdl are now
transformed into the same format as with the Invidious API, so that no
distinction for these is require

Removed
List-Video Parsers - The differentiation between Invidious and Local
video data in yt-video-list.js is removed because of the transformation
This commit is contained in:
Luca 2020-08-22 16:21:49 +02:00
parent b99b762a39
commit 972ed2f1ca
2 changed files with 48 additions and 73 deletions

View File

@ -140,19 +140,7 @@ export default Vue.extend({
}
},
mounted: function () {
// Check if data came from Invidious or from local backend
if (typeof (this.data.descriptionHtml) !== 'undefined' ||
typeof (this.data.index) !== 'undefined' ||
typeof (this.data.authorId) !== 'undefined' ||
typeof (this.data.publishedText) !== 'undefined' ||
typeof (this.data.authorThumbnails) === 'object'
) {
this.parseInvidiousData()
} else {
this.parseLocalData()
}
this.parseVideoData()
this.checkIfWatched()
},
methods: {
@ -243,7 +231,7 @@ export default Vue.extend({
return durationText
},
parseInvidiousData: function () {
parseVideoData: function () {
this.id = this.data.videoId
this.title = this.data.title
// this.thumbnail = this.data.videoThumbnails[4].url
@ -281,61 +269,6 @@ export default Vue.extend({
}
},
parseLocalData: function () {
if (typeof (this.data.id) !== 'undefined') {
this.id = this.data.id
} else {
this.id = this.data.link.replace('https://www.youtube.com/watch?v=', '')
}
this.title = this.data.title
if (typeof (this.data.author) === 'string') {
this.channelName = this.data.author
this.channelId = this.data.ucid
this.viewCount = this.data.views
// Data is returned as a literal string named 'undefined'
if (this.data.length_seconds !== 'undefined') {
this.duration = this.calculateVideoDuration(parseInt(this.data.length_seconds))
}
} else {
this.channelName = this.data.author.name
this.duration = this.data.duration
this.description = this.data.description
this.channelId = this.data.author.ref.replace('https://www.youtube.com/user/', '')
this.channelId = this.channelId.replace('https://www.youtube.com/channel/', '')
}
if (typeof (this.data.uploaded_at) !== 'undefined' && !this.data.live) {
this.toLocalePublicationString({
publishText: this.data.uploaded_at,
templateString: this.$t('Video.Publicationtemplate'),
timeStrings: this.$t('Video.Published'),
liveStreamString: this.$t('Video.Watching'),
upcomingString: this.$t('Video.Published.Upcoming'),
isLive: this.data.live,
isUpcoming: false
}).then((data) => {
this.uploadedTime = data
}).catch((error) => {
console.error(error)
})
this.uploadedTime = this.data.uploaded_at
}
if (this.data.views !== null && typeof (this.data.views) !== 'undefined') {
this.parsedViewCount = this.data.views.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
} else if (typeof (this.data.view_count) !== 'undefined') {
const viewCount = this.data.view_count.replace(',', '')
this.parsedViewCount = viewCount.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
} else {
this.hideViews = true
}
this.isLive = this.data.live
},
checkIfWatched: function () {
const historyIndex = this.historyCache.findIndex((video) => {
return video.videoId === this.id

View File

@ -4,6 +4,7 @@ import IsEqual from 'lodash.isequal'
import FtLoader from '../../components/ft-loader/ft-loader.vue'
import FtCard from '../../components/ft-card/ft-card.vue'
import FtElementList from '../../components/ft-element-list/ft-element-list.vue'
import ytTrendScraper from 'yt-trending-scraper'
export default Vue.extend({
name: 'Search',
@ -124,12 +125,53 @@ export default Vue.extend({
return item.type === 'video' || item.type === 'channel' || item.type === 'playlist'
})
console.log(returnData)
const returnDataInvidious = []
returnData.forEach((video) => {
if (video.type === 'video') {
let authId = video.author.ref.match(/user(.)*/)
let publishDate = null
let videoDuration = null
const videoId = video.link.match(/\?v=(.)*/)[0].split('=')[1]
if (authId === null) {
authId = video.author.ref.match(/channel(.)*/)
}
if (video.uploaded_at !== null) {
publishDate = ytTrendScraper.calculate_published(video.uploaded_at, Date.now())
}
if(video.duration !== null) {
videoDuration = ytTrendScraper.calculate_length_in_seconds(video.duration)
}
returnDataInvidious.push(
{
videoId: videoId,
title: video.title,
type: 'video',
author: video.author.name,
authorId: authId,
authorUrl: video.author.ref,
videoThumbnails: video.thumbnail,
description: video.description,
viewCount: video.views,
published: publishDate,
publishedText: video.uploaded_at,
lengthSeconds: videoDuration,
liveNow: video.live,
paid: false,
premium: false,
isUpcoming: false,
timeText: video.duration,
test: "test"
}
)
} else {
returnDataInvidious.push(video)
}
})
if (payload.nextPage) {
this.shownResults = this.shownResults.concat(returnData)
this.shownResults = this.shownResults.concat(returnDataInvidious)
} else {
this.shownResults = returnData
this.shownResults = returnDataInvidious
}
this.nextPageRef = result.nextpageRef
@ -169,7 +211,7 @@ export default Vue.extend({
if (this.searchPage === 1) {
this.isLoading = true
}
console.log("DATA 2")
console.log(payload)
const searchPayload = {