Skip to content

Commit

Permalink
Local API: Extract playlists on the auto-generated "Music" channel (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue committed Jun 11, 2024
1 parent 27d2687 commit eddee49
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,24 @@ export function parseLocalListPlaylist(playlist, channelId = undefined, channelN
}
}

/**
* @param {import('youtubei.js').YTNodes.CompactStation} compactStation
* @param {string} channelId
* @param {string} channelName
*/
export function parseLocalCompactStation(compactStation, channelId, channelName) {
return {
type: 'playlist',
dataSource: 'local',
title: compactStation.title.text,
thumbnail: compactStation.thumbnail[1].url,
channelName,
channelId,
playlistId: compactStation.endpoint.payload.playlistId,
videoCount: extractNumberFromString(compactStation.video_count.text)
}
}

/**
* @param {YT.Search} response
*/
Expand Down
23 changes: 20 additions & 3 deletions src/renderer/views/Channel/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
parseLocalChannelShorts,
parseLocalChannelVideos,
parseLocalCommunityPosts,
parseLocalCompactStation,
parseLocalListPlaylist,
parseLocalListVideo,
parseLocalSubscriberCount
Expand Down Expand Up @@ -666,9 +667,25 @@ export default defineComponent({
this.getChannelReleasesLocal()
}

if (!this.hideChannelPlaylists && channel.has_playlists) {
tabs.push('playlists')
this.getChannelPlaylistsLocal()
if (!this.hideChannelPlaylists) {
if (channel.has_playlists) {
tabs.push('playlists')
this.getChannelPlaylistsLocal()
} else if (channelId === 'UC-9-kyTW8ZkZNDHQJ6FgpwQ') {
// Special handling for "The Music Channel" (https://youtube.com/music)
tabs.push('playlists')
const playlists = channel.playlists.map(playlist => parseLocalListPlaylist(playlist))

const compactStations = channel.memo.get('CompactStation')
if (compactStations) {
for (const compactStation of compactStations) {
playlists.push(parseLocalCompactStation(compactStation, channelId, channelName))
}
}

this.showPlaylistSortBy = false
this.latestPlaylists = playlists
}
}

if (!this.hideChannelCommunity && channel.has_community) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/views/Playlist/Playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export default defineComponent({
this.playlistDescription = result.info.description ?? ''
this.firstVideoId = result.items[0].id
this.playlistThumbnail = result.info.thumbnails[0].url
this.viewCount = extractNumberFromString(result.info.views)
this.viewCount = result.info.views.toLowerCase() === 'no views' ? 0 : extractNumberFromString(result.info.views)
this.videoCount = extractNumberFromString(result.info.total_items)
this.lastUpdated = result.info.last_updated ?? ''
this.channelName = channelName ?? ''
Expand Down

0 comments on commit eddee49

Please sign in to comment.