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
11 changes: 6 additions & 5 deletions src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,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))

Expand Down Expand Up @@ -609,8 +609,8 @@ export function parseLocalListVideo(video) {
author: video.author.name,
authorId: video.author.id,
ChunkyProgrammer marked this conversation as resolved.
Show resolved Hide resolved
description: video.description,
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,
ChunkyProgrammer marked this conversation as resolved.
Show resolved Hide resolved
lengthSeconds: isNaN(video.duration.seconds) ? '' : video.duration.seconds,
liveNow: video.is_live,
isUpcoming: video.is_upcoming || video.is_premiere,
Expand All @@ -623,6 +623,7 @@ export function parseLocalListVideo(video) {
*/
function parseListItem(item) {
switch (item.type) {
case 'Movie':
case 'Video':
return parseLocalListVideo(item)
case 'Channel': {
Expand Down Expand Up @@ -689,8 +690,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
Expand Down
26 changes: 22 additions & 4 deletions src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,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
Expand All @@ -293,10 +293,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') {
Expand Down