Skip to content

Commit 81bb72a

Browse files
committed
Support multiple creators in YT->Nebula
Since YT playlists are represented as separate creators on Nebula, it makes sense to support this to search in all the related channels
1 parent 4e3a230 commit 81bb72a

1 file changed

Lines changed: 31 additions & 26 deletions

File tree

src/scripts/background_script.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -134,35 +134,39 @@ const getNebulaVideo = async (message: { [key: string]: any; }): Promise<nebulav
134134
if (!channelID && !channelName) throw 'not enough information';
135135

136136
const creators = await loadCreators();
137-
const creator = creators.find(c => c.channel === channelID || c.name === channelName || c.name === channelNice || c.nebulaAlt === channelName);
138-
console.debug('creator:', creator, '\nchannelID:', channelID, '\nvideoTitle:', videoTitle);
139-
if (!creator) return;
140-
141-
// try search the channel's newest videos locally
142-
if (creator.nebula) {
143-
try {
144-
const video = await creatorHasNebulaVideo(creator.nebula, videoTitle, videoFetchNebula);
145-
return {
146-
is: 'video',
147-
confidence: video.confidence,
148-
link: video.video,
149-
};
150-
} catch (err) {
151-
console.error(err);
137+
const matches = creators.filter(c => c.channel === channelID || c.name === channelName || c.name === channelNice || c.nebulaAlt === channelName);
138+
console.debug('creators:', matches, '\nchannelID:', channelID, '\nvideoTitle:', videoTitle);
139+
if (!matches) return;
140+
141+
for (const creator of matches) {
142+
// try search the channel's newest videos locally
143+
if (creator.nebula) {
144+
try {
145+
const video = await creatorHasNebulaVideo(creator.nebula, videoTitle, videoFetchNebula);
146+
return {
147+
is: 'video',
148+
confidence: video.confidence,
149+
link: video.video,
150+
};
151+
} catch (err) {
152+
console.error(err);
153+
}
152154
}
153155
}
154156

155-
// try search the alternative channel's newest videos locally
156-
if (creator.nebulaAlt && creator.nebula !== creator.nebulaAlt) {
157-
try {
158-
const video = await creatorHasNebulaVideo(creator.nebulaAlt, videoTitle, videoFetchNebula);
159-
return {
160-
is: 'video',
161-
confidence: video.confidence,
162-
link: video.video,
163-
};
164-
} catch (err) {
165-
console.error(err);
157+
for (const creator of matches) {
158+
// try search the alternative channel's newest videos locally
159+
if (creator.nebulaAlt && creator.nebula !== creator.nebulaAlt) {
160+
try {
161+
const video = await creatorHasNebulaVideo(creator.nebulaAlt, videoTitle, videoFetchNebula);
162+
return {
163+
is: 'video',
164+
confidence: video.confidence,
165+
link: video.video,
166+
};
167+
} catch (err) {
168+
console.error(err);
169+
}
166170
}
167171
}
168172

@@ -179,6 +183,7 @@ const getNebulaVideo = async (message: { [key: string]: any; }): Promise<nebulav
179183
}
180184

181185
// last resort: link to channel
186+
const creator = matches[0];
182187
if (!creator.nebula && !creator.nebulaAlt) return;
183188
return {
184189
is: 'channel',

0 commit comments

Comments
 (0)