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

Add support for viewing movie trailers with local api #4391

Merged
5 changes: 4 additions & 1 deletion src/renderer/components/ft-list-video/ft-list-video.vue
Original file line number Diff line number Diff line change
@@ -112,7 +112,10 @@
>
<span>{{ channelName }}</span>
</router-link>
<template v-if="!isLive && !isUpcoming && !isPremium && !hideViews">
<span v-else-if="channelName !== null">
{{ channelName }}
</span>
<template v-if="!isLive && !isUpcoming && !isPremium && !hideViews && viewCount != null">
<span class="viewCount">
<template v-if="channelId !== null"> • </template>
{{ $tc('Global.Counts.View Count', viewCount, {count: parsedViewCount}) }}
59 changes: 41 additions & 18 deletions src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
@@ -457,7 +457,7 @@ function handleSearchResponse(response) {

const results = response.results
.filter((item) => {
return item.type === 'Video' || item.type === 'Channel' || item.type === 'Playlist' || item.type === 'HashtagTile'
return item.type === 'Video' || item.type === 'Channel' || item.type === 'Playlist' || item.type === 'HashtagTile' || item.type === 'Movie'
})
.map((item) => parseListItem(item))

@@ -537,22 +537,44 @@ export function parseLocalPlaylistVideo(video) {
}

/**
* @param {import('youtubei.js').YTNodes.Video} video
* @param {import('youtubei.js').YTNodes.Video | import('youtubei.js').YTNodes.Movie} item
*/
export function parseLocalListVideo(video) {
return {
type: 'video',
videoId: video.id,
title: video.title.text,
author: video.author.name,
authorId: video.author.id,
description: video.description,
viewCount: extractNumberFromString(video.view_count.text),
publishedText: video.published.isEmpty() ? null : video.published.text,
lengthSeconds: isNaN(video.duration.seconds) ? '' : video.duration.seconds,
liveNow: video.is_live,
isUpcoming: video.is_upcoming || video.is_premiere,
premiereDate: video.upcoming
export function parseLocalListVideo(item) {
if (item.type === 'Movie') {
/** @type {import('youtubei.js').YTNodes.Movie} */
const movie = item

return {
type: 'video',
videoId: movie.id,
title: movie.title.text,
author: movie.author.name,
authorId: movie.author.id !== 'N/A' ? movie.author.id : null,
description: movie.description_snippet?.text,
viewCount: null,
publishedText: null,
lengthSeconds: isNaN(movie.duration.seconds) ? '' : movie.duration.seconds,
liveNow: false,
isUpcoming: false,
premiereDate: null
}
} else {
/** @type {import('youtubei.js').YTNodes.Video} */
const video = item
return {
type: 'video',
videoId: video.id,
title: video.title.text,
author: video.author.name,
authorId: video.author.id,
description: video.description,
viewCount: video.view_count == null ? null : extractNumberFromString(video.view_count.text),
publishedText: (video.published == null || video.published.isEmpty()) ? null : video.published.text,
lengthSeconds: isNaN(video.duration.seconds) ? '' : video.duration.seconds,
liveNow: video.is_live,
isUpcoming: video.is_upcoming || video.is_premiere,
premiereDate: video.upcoming
}
}
}

@@ -561,6 +583,7 @@ export function parseLocalListVideo(video) {
*/
function parseListItem(item) {
switch (item.type) {
case 'Movie':
case 'Video':
return parseLocalListVideo(item)
case 'Channel': {
@@ -627,8 +650,8 @@ export function parseLocalWatchNextVideo(video) {
title: video.title.text,
author: video.author.name,
authorId: video.author.id,
viewCount: extractNumberFromString(video.view_count.text),
publishedText: video.published.isEmpty() ? null : video.published.text,
viewCount: video.view_count == null ? null : extractNumberFromString(video.view_count.text),
publishedText: (video.published == null || video.published.isEmpty()) ? null : video.published.text,
lengthSeconds: isNaN(video.duration.seconds) ? '' : video.duration.seconds,
liveNow: video.is_live,
isUpcoming: video.is_premiere
26 changes: 22 additions & 4 deletions src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
@@ -307,7 +307,7 @@ export default defineComponent({
this.isFamilyFriendly = result.basic_info.is_family_safe

const recommendedVideos = result.watch_next_feed
?.filter((item) => item.type === 'CompactVideo')
?.filter((item) => item.type === 'CompactVideo' || item.type === 'CompactMovie')
.map(parseLocalWatchNextVideo) ?? []

// place watched recommended videos last
@@ -324,10 +324,28 @@ export default defineComponent({

let playabilityStatus = result.playability_status
let bypassedResult = null
if (playabilityStatus.status === 'LOGIN_REQUIRED') {
let streamingVideoId = this.videoId
let trailerIsNull = false

// if widevine support is added then we should check if playabilityStatus.status is UNPLAYABLE too
if (result.has_trailer) {
bypassedResult = result.getTrailerInfo()
/**
* @type {import ('youtubei.js').YTNodes.PlayerLegacyDesktopYpcTrailer}
*/
const trailerScreen = result.playability_status.error_screen
streamingVideoId = trailerScreen.video_id
// if the trailer is null then it is likely age restricted.
trailerIsNull = bypassedResult == null
if (!trailerIsNull) {
playabilityStatus = bypassedResult.playability_status
}
}

if (playabilityStatus.status === 'LOGIN_REQUIRED' || trailerIsNull) {
// try to bypass the age restriction
bypassedResult = await getLocalVideoInfo(this.videoId, true)
playabilityStatus = result.playability_status
bypassedResult = await getLocalVideoInfo(streamingVideoId, true)
playabilityStatus = bypassedResult.playability_status
}

if (playabilityStatus.status === 'UNPLAYABLE') {