Skip to content

Commit

Permalink
✨ Report video loading error
Browse files Browse the repository at this point in the history
  • Loading branch information
moisout committed Jun 22, 2024
1 parent 8a2efca commit 611b119
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 20 deletions.
12 changes: 7 additions & 5 deletions client/app/components/message/MessageBoxContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ const messagesStore = useMessagesStore();

<template>
<div class="messages-container">
<MessageBox
v-for="message in messagesStore.visibleMessages"
:key="message.id"
:message="message"
/>
<ClientOnly>
<MessageBox
v-for="message in messagesStore.visibleMessages"
:key="message.id"
:message="message"
/>
</ClientOnly>
</div>
</template>

Expand Down
4 changes: 2 additions & 2 deletions client/app/composables/videoplayer/mediaSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const useMediaSession = ({
if (navigator && 'mediaSession' in navigator) {
navigator.mediaSession.metadata = new MediaMetadata({
title: video.title,
artist: video.author.name,
artwork: video.thumbnails.map(thumbnail => {
artist: video.author?.name,
artwork: video.thumbnails?.map(thumbnail => {
return {
src: proxyUrl(thumbnail.url),
sizes: `${thumbnail.width}x${thumbnail.height}`,
Expand Down
6 changes: 3 additions & 3 deletions client/app/pages/watch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ const {
videoData.description = videoData.description.replace('https://www.youtube.com', '');
}
if (videoData.ageRestricted) {
if (videoData.availability?.status !== 'OK') {
messagesStore.createMessage({
type: 'error',
title: 'Age restricted content',
message: 'This video is age restricted. Viewing may not be possible.'
title: 'Video is unplayable',
message: videoData.availability?.reason ?? 'Unplayable for unknown reason'
});
}
Expand Down
5 changes: 4 additions & 1 deletion client/app/store/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type MessageType } from '~/types/MessageType';
import { defineStore } from 'pinia';
import { type MessageType } from '~/types/MessageType';

export const useMessagesStore = defineStore('messages', {
state: () => ({
Expand All @@ -19,6 +19,9 @@ export const useMessagesStore = defineStore('messages', {
this.messages.find(m => m.id === id).dismissed = true;
},
createMessage(messageData: Omit<MessageType, 'dismissed' | 'id'>) {
if (messageData.type === 'info') {
messageData.dismissDelay = 5000;
}
this.addMessage({
...messageData,
id: this.allMessages.length + 1,
Expand Down
8 changes: 7 additions & 1 deletion server/src/core/videos/videos.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ export class VideosService {

return video;
} catch (error) {
throw new InternalServerErrorException(error);
if (error?.message) {
throw new InternalServerErrorException(error.message);
}
if (error?.info?.reason) {
throw new InternalServerErrorException(error.info.reason);
}
throw new InternalServerErrorException('Error fetching video information');
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { VTVideoInfoDto } from 'server/mapper/dto/vt-video-info.dto';
import { VideoInfoSourceApproximation } from './video-info-source-approximation';
import {
extractAgeRestricted,
extractAuthor,
extractAvailability,
extractCaptions,
extractCategory,
extractChapters,
Expand Down Expand Up @@ -52,7 +52,7 @@ export const toVTVideoInfoDto = (
live: extractLive(videoInfo),
unlisted: extractUnlisted(videoInfo),
familyFriendly: extractFamilyFriendly(videoInfo),
ageRestricted: extractAgeRestricted(videoInfo),
availability: extractAvailability(videoInfo),
likeCount: extractLikeCount(videoInfo),
category: extractCategory(videoInfo),
previewThumbnails: extractPreviewThumbnails(videoInfo),
Expand Down
15 changes: 15 additions & 0 deletions server/src/mapper/converter/video-info/vt-video-info.extractors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ export const extractAgeRestricted = (videoInfo: VideoInfoSourceApproximation) =>
return !!videoInfo?.playability_status?.reason.includes('age');
};

export const extractAvailability = (videoInfo: VideoInfoSourceApproximation) => {
let playabilityReason = videoInfo?.playability_status?.reason;
if ((videoInfo?.playability_status?.error_screen as any)?.subreason) {
playabilityReason += ` - ${(videoInfo?.playability_status?.error_screen as any)?.subreason}`;
}

if (playabilityReason.includes('confirm your age')) {
playabilityReason = "This video is age-restricted. It can't be played on ViewTube.";
}
return {
status: videoInfo?.playability_status?.status,
reason: playabilityReason
};
};

export const extractLikeCount = (videoInfo: VideoInfoSourceApproximation) => {
return videoInfo?.basic_info?.like_count;
};
Expand Down
6 changes: 3 additions & 3 deletions server/src/mapper/dto/vt-video-info.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export class VTVideoInfoDto {
watching?: number;
unlisted: boolean;
familyFriendly: boolean;
ageRestricted?: boolean;
unavailable?: {
// reason
availability: {
status?: string;
reason?: string;
};
likeCount: number;
category: string;
Expand Down
2 changes: 1 addition & 1 deletion server/src/metadata.ts

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions shared/src/api.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,10 @@ export interface components {
watching?: number;
unlisted: boolean;
familyFriendly: boolean;
ageRestricted?: boolean;
availability: {
status?: string;
reason?: string;
};
likeCount: number;
category: string;
previewThumbnails: components["schemas"]["VTPreviewThumbnailDto"][];
Expand Down Expand Up @@ -1460,7 +1463,6 @@ export interface operations {
parameters: {
query: {
url: string;
local: boolean;
};
};
responses: {
Expand Down

0 comments on commit 611b119

Please sign in to comment.