improve error handling for youtube requests, skip video category check if unnecessary

This commit is contained in:
2025-07-15 10:42:49 +02:00
parent 2308356c1b
commit b9c098cde3

View File

@ -66,7 +66,11 @@ export class TimelineReader {
const youtubeVideoUrl = new URL(`https://www.googleapis.com/youtube/v3/videos?${searchParams}`);
const resp = await fetch(youtubeVideoUrl);
const respObj = await resp.json();
if (!respObj.items.length) {
if (respObj.error) {
this.logger.warn('YT API error', respObj.error);
return false;
}
if (!respObj.items?.length) {
this.logger.warn('Could not find video with id', videoId);
return false;
}
@ -76,7 +80,7 @@ export class TimelineReader {
this.logger.warn('Could not load snippet for video', videoId, item);
return false;
}
if (item.snippet.tags?.includes('music')) {
if (item.snippet?.tags?.includes('music')) {
return true;
}
@ -159,8 +163,14 @@ export class TimelineReader {
if (!odesliInfo || !odesliInfo.entitiesByUniqueId || !odesliInfo.entityUniqueId) {
return null;
}
const spotify: Platform = 'spotify';
const tidal: Platform = 'tidal';
const deezer: Platform = 'deezer';
const tidalId = odesliInfo.linksByPlatform[tidal]?.entityUniqueId;
const tidalUri = tidalId ? odesliInfo.entitiesByUniqueId[tidalId].id : undefined;
const info = odesliInfo.entitiesByUniqueId[odesliInfo.entityUniqueId];
//this.logger.debug('odesli response', info);
const platform: Platform = 'youtube';
if (info.platforms.includes(platform)) {
const youtubeId =
@ -175,16 +185,16 @@ export class TimelineReader {
);
return null;
}
const isMusic = await this.isMusicVideo(youtubeId);
// If it is on tidal or deezer, it's probably music
// Do not check spotify, they carry too much other stuff (podcasts, audiobooks, etc)
let isMusic = odesliInfo.linksByPlatform[tidal] || odesliInfo.linksByPlatform[deezer];
// If not, check the YT API
isMusic = isMusic || (await this.isMusicVideo(youtubeId));
if (!isMusic) {
this.logger.debug('Probably not a music video', youtubeId);
return null;
}
}
const spotify: Platform = 'spotify';
const tidal: Platform = 'tidal';
const tidalId = odesliInfo.linksByPlatform[tidal]?.entityUniqueId;
const tidalUri = tidalId ? odesliInfo.entitiesByUniqueId[tidalId].id : undefined;
const songInfo = {
...info,