Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate the Playlist page to youtubei.js #2903

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/renderer/components/playlist-info/playlist-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ export default Vue.extend({
this.infoSource = this.data.infoSource

// Causes errors if not put inside of a check
if (typeof (this.data.viewCount) !== 'undefined') {
if (typeof (this.data.viewCount) !== 'undefined' && !isNaN(this.data.viewCount)) {
absidue marked this conversation as resolved.
Show resolved Hide resolved
absidue marked this conversation as resolved.
Show resolved Hide resolved
this.viewCount = this.hideViews ? null : Intl.NumberFormat(this.currentLocale).format(this.data.viewCount)
}

if (typeof (this.data.videoCount) !== 'undefined') {
if (typeof (this.data.videoCount) !== 'undefined' && !isNaN(this.data.videoCount)) {
absidue marked this conversation as resolved.
Show resolved Hide resolved
absidue marked this conversation as resolved.
Show resolved Hide resolved
this.videoCount = Intl.NumberFormat(this.currentLocale).format(this.data.videoCount)
}

Expand Down
5 changes: 5 additions & 0 deletions src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ export async function getLocalSearchSuggestions(query) {
export function clearLocalSearchSuggestionsSession() {
searchSuggestionsSession = null
}

export async function getLocalPlaylist(id) {
const innertube = await createInnertube()
return await innertube.getPlaylist(id)
}
8 changes: 8 additions & 0 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,11 @@ export async function getPicturesPath() {
return null
}
}

export function extractNumberFromString(str) {
if (typeof str === 'string') {
return parseInt(str.replace(/\D+/, ''))
} else {
return NaN
}
}
40 changes: 18 additions & 22 deletions src/renderer/views/Playlist/Playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import FtCard from '../../components/ft-card/ft-card.vue'
import PlaylistInfo from '../../components/playlist-info/playlist-info.vue'
import FtListVideo from '../../components/ft-list-video/ft-list-video.vue'
import i18n from '../../i18n/index'
import { getLocalPlaylist } from '../../helpers/api/local'
import { extractNumberFromString } from '../../helpers/utils'

export default Vue.extend({
name: 'Playlist',
Expand Down Expand Up @@ -64,18 +66,18 @@ export default Vue.extend({
getPlaylistLocal: function () {
this.isLoading = true

this.ytGetPlaylistInfo(this.playlistId).then((result) => {
getLocalPlaylist(this.playlistId).then((result) => {
this.infoData = {
id: result.id,
title: result.title,
description: result.description ? result.description : '',
id: this.playlistId,
title: result.info.title,
description: result.info.description ?? '',
firstVideoId: result.items[0].id,
viewCount: result.views,
videoCount: result.estimatedItemCount,
lastUpdated: result.lastUpdated ? result.lastUpdated : '',
channelName: result.author ? result.author.name : '',
channelThumbnail: result.author ? result.author.bestAvatar.url : '',
channelId: result.author ? result.author.channelID : '',
viewCount: extractNumberFromString(result.info.views),
videoCount: extractNumberFromString(result.info.total_items),
lastUpdated: result.info.last_updated ?? '',
channelName: result.info.author?.name ?? '',
channelThumbnail: result.info.author?.best_thumbnail?.url ?? '',
channelId: result.info.author?.id,
infoSource: 'local'
}

Expand All @@ -86,18 +88,13 @@ export default Vue.extend({
})

this.playlistItems = result.items.map((video) => {
if (typeof video.author !== 'undefined') {
const channelName = video.author.name
const channelId = video.author.channelID ? video.author.channelID : channelName
video.author = channelName
video.authorId = channelId
} else {
video.author = ''
video.authorId = ''
return {
videoId: video.id,
title: video.title,
author: video.author.name,
authorId: video.author.id,
lengthSeconds: isNaN(video.duration.seconds) ? '' : video.duration.seconds
}
video.videoId = video.id
video.lengthSeconds = video.duration
return video
})

this.isLoading = false
Expand Down Expand Up @@ -177,7 +174,6 @@ export default Vue.extend({
},

...mapActions([
'ytGetPlaylistInfo',
'invidiousGetPlaylistInfo',
'updateSubscriptionDetails'
])
Expand Down