diff --git a/src/renderer/components/ft-list-video/ft-list-video.js b/src/renderer/components/ft-list-video/ft-list-video.js index da3825f7..8f38e1b0 100644 --- a/src/renderer/components/ft-list-video/ft-list-video.js +++ b/src/renderer/components/ft-list-video/ft-list-video.js @@ -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 diff --git a/src/renderer/main.js b/src/renderer/main.js index dc79120d..1222c3cb 100644 --- a/src/renderer/main.js +++ b/src/renderer/main.js @@ -23,7 +23,7 @@ Vue.component('font-awesome-icon', FontAwesomeIcon) Vue.use(VueI18n) // List of locales approved for use -const activeLocales = ['en-US', 'de-DE', 'pt-PT', 'fi', 'pt-BR', 'vi', 'zh-CN', 'zh-TW'] +const activeLocales = ['en-US', 'de-DE', 'fi', 'fr-FR', 'pt-BR', 'pt-PT', 'ru', 'vi', 'zh-CN', 'zh-TW'] const messages = {} // Take active locales and load respective YAML file diff --git a/src/renderer/views/Search/Search.js b/src/renderer/views/Search/Search.js index ca69def5..96540404 100644 --- a/src/renderer/views/Search/Search.js +++ b/src/renderer/views/Search/Search.js @@ -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,52 @@ 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 + } + ) + } 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 +210,6 @@ export default Vue.extend({ if (this.searchPage === 1) { this.isLoading = true } - console.log(payload) const searchPayload = { diff --git a/static/locales/pt_BR.yaml b/static/locales/pt-BR.yaml similarity index 100% rename from static/locales/pt_BR.yaml rename to static/locales/pt-BR.yaml