From c7ebf22f72c8def4fb1e4a14269145d8822ea093 Mon Sep 17 00:00:00 2001 From: Matthew Origer Date: Wed, 18 Jan 2023 14:47:48 -0600 Subject: [PATCH] Commit for review and suggestions https://github.com/FreeTubeApp/FreeTube/issues/2476 --- package.json | 4 +- .../components/ft-list-video/ft-list-video.js | 2 +- src/renderer/views/Channel/Channel.js | 61 +++++++++++++++++++ src/renderer/views/Channel/Channel.vue | 27 ++++++++ src/renderer/views/Watch/Watch.js | 2 +- static/locales/en-US.yaml | 2 + yarn.lock | 13 ++-- 7 files changed, 100 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 423c712bea09e..eeba645f08ca4 100644 --- a/package.json +++ b/package.json @@ -77,8 +77,8 @@ "vue-observe-visibility": "^1.0.0", "vue-router": "^3.6.5", "vuex": "^3.6.2", - "youtubei.js": "^2.8.0", - "yt-channel-info": "^3.2.1" + "youtubei.js": "^2.9.0", + "yt-channel-info": "http://github.com/freetubeapp/yt-channel-info.git#1e80fc79bdc86355ca48425f03bc8a64d7451133" }, "devDependencies": { "@babel/core": "^7.20.12", 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 5f80427690003..f70420a8ebccd 100644 --- a/src/renderer/components/ft-list-video/ft-list-video.js +++ b/src/renderer/components/ft-list-video/ft-list-video.js @@ -393,7 +393,7 @@ export default Vue.extend({ this.publishedText = this.data.publishedText } - if (typeof (this.data.publishedText) !== 'undefined' && this.data.publishedText !== null && !this.isLive) { + if (this.data.publishedText && !this.isLive) { // produces a string according to the template in the locales string this.uploadedTime = toLocalePublicationString({ publishText: this.publishedText, diff --git a/src/renderer/views/Channel/Channel.js b/src/renderer/views/Channel/Channel.js index 748801c02c6dd..b8e70ec55b9c9 100644 --- a/src/renderer/views/Channel/Channel.js +++ b/src/renderer/views/Channel/Channel.js @@ -54,6 +54,7 @@ export default Vue.extend({ lastSearchQuery: '', relatedChannels: [], latestVideos: [], + latestShorts: [], latestPlaylists: [], searchResults: [], shownElementList: [], @@ -189,6 +190,7 @@ export default Vue.extend({ this.searchPage = 2 this.relatedChannels = [] this.latestVideos = [] + this.latestShorts = [] this.latestPlaylists = [] this.searchResults = [] this.shownElementList = [] @@ -198,9 +200,11 @@ export default Vue.extend({ if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') { this.getChannelInfoInvidious() this.getPlaylistsInvidious() + this.getShortsInvidious() } else { this.getChannelInfoLocal() this.getChannelVideosLocal() + this.getChannelShortsLocal() this.getPlaylistsLocal() } }, @@ -215,9 +219,11 @@ export default Vue.extend({ case 'invidious': this.latestVideosPage = 1 this.channelInvidiousNextPage() + this.getShortsInvidious() break default: this.getChannelVideosLocal() + this.getChannelShortsLocal() } }, @@ -247,9 +253,11 @@ export default Vue.extend({ if (!process.env.IS_ELECTRON || this.backendPreference === 'invidious') { this.getChannelInfoInvidious() this.getPlaylistsInvidious() + this.getShortsInvidious() } else { this.getChannelInfoLocal() this.getChannelVideosLocal() + this.getChannelShortsLocal() this.getPlaylistsLocal() } }, @@ -352,6 +360,31 @@ export default Vue.extend({ } }) }, + getChannelShortsLocal: function () { + this.isElementListLoading = true + const expectedId = this.originalId + ytch.getChannelShorts({ channelId: this.id, channelIdType: this.idType, sortBy: this.videoSortBy }).then((response) => { + if (expectedId !== this.originalId) { + return + } + + this.latestShorts = response.items + this.videoContinuationString = response.continuation + this.isElementListLoading = false + }).catch((err) => { + console.error(err) + const errorMessage = this.$t('Local API Error (Click to copy)') + showToast(`${errorMessage}: ${err}`, 10000, () => { + copyToClipboard(err) + }) + if (this.backendPreference === 'local' && this.backendFallback) { + showToast(this.$t('Falling back to Invidious API')) + this.getChannelInfoInvidious() + } else { + this.isLoading = false + } + }) + }, channelLocalNextPage: function () { ytch.getChannelVideosMore({ continuation: this.videoContinuationString }).then((response) => { @@ -509,6 +542,34 @@ export default Vue.extend({ }) }, + getShortsInvidious: function () { + const payload = { + resource: `channels/${this.id}/shorts`, + id: '', + params: { + sort_by: this.playlistSortBy + } + } + this.invidiousAPICall(payload).then((response) => { + this.latestShorts = response.videos + this.videoContinuationString = response.continuation + this.isElementListLoading = false + }).catch((err) => { + console.error(err) + const errorMessage = this.$t('Invidious API Error (Click to copy)') + showToast(`${errorMessage}: ${err.responseJSON.error}`, 10000, () => { + copyToClipboard(err.responseJSON.error) + }) + if (process.env.IS_ELECTRON && this.backendPreference === 'invidious' && this.backendFallback) { + showToast(this.$t('Falling back to Local API')) + this.getPlaylistsLocal() + } else { + this.isLoading = false + } + } + ) + }, + getPlaylistsInvidiousMore: function () { if (this.playlistContinuationString === null) { console.warn('There are no more playlists available for this channel') diff --git a/src/renderer/views/Channel/Channel.vue b/src/renderer/views/Channel/Channel.vue index 3d25f9a7ff9f9..c42efdc11c820 100644 --- a/src/renderer/views/Channel/Channel.vue +++ b/src/renderer/views/Channel/Channel.vue @@ -92,6 +92,19 @@ > {{ $t("Channel.Videos.Videos").toUpperCase() }} +
+ + +

+ {{ $t("Channel.Shorts.This channel does not currently have any shorts") }} +

+
= 3) { await this.createLocalStoryboardUrls(result.storyboards.boards[2]) } } diff --git a/static/locales/en-US.yaml b/static/locales/en-US.yaml index 602e253089ded..e46596651d203 100644 --- a/static/locales/en-US.yaml +++ b/static/locales/en-US.yaml @@ -512,6 +512,8 @@ Channel: Your search results have returned 0 results: Your search results have returned 0 results Sort By: Sort By + Shorts: + Shorts: Shorts Videos: Videos: Videos This channel does not currently have any videos: This channel does not currently diff --git a/yarn.lock b/yarn.lock index 788c41027b88f..16eaf1d7946ac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9174,19 +9174,18 @@ yocto-queue@^0.1.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== -youtubei.js@^2.8.0: - version "2.8.0" - resolved "https://registry.yarnpkg.com/youtubei.js/-/youtubei.js-2.8.0.tgz#f0170f390791cde733facf615f3cf0e2470c31de" - integrity sha512-UEH3wP1Wmrmnh2wJohhg+rAq94bF2EqGnlnph2z91kZ+I1tQzlZD09Zc7QNqCYV0t2G4Cl2Lu+DqXrdhf1/SoQ== +youtubei.js@^2.9.0: + version "2.9.0" + resolved "https://registry.yarnpkg.com/youtubei.js/-/youtubei.js-2.9.0.tgz#17426dfb0555169cddede509d50d3db62c102270" + integrity sha512-paxfeQGwxGw0oPeKdC96jNalS0OnYQ5xdJY27k3J+vamzVcwX6Ky+idALW6Ej9aUC7FISbchBsEVg0Wa7wgGyA== dependencies: "@protobuf-ts/runtime" "^2.7.0" jintr "^0.3.1" linkedom "^0.14.12" undici "^5.7.0" -yt-channel-info@^3.2.1: +"yt-channel-info@http://github.com/freetubeapp/yt-channel-info.git#1e80fc79bdc86355ca48425f03bc8a64d7451133": version "3.2.1" - resolved "https://registry.yarnpkg.com/yt-channel-info/-/yt-channel-info-3.2.1.tgz#7b8d5c335a54edd7f41f2db561ff23dd37f854a5" - integrity sha512-drGySe+MqoYMhZzkJpapG5pCfAEBSsCaOZXDzZz4nfQfYhXQGUU11IJ9HpDZmnari1vEWrUasjeu2hwZujZYmw== + resolved "http://github.com/freetubeapp/yt-channel-info.git#1e80fc79bdc86355ca48425f03bc8a64d7451133" dependencies: axios "^1.1.2"