Skip to content

Commit 2c557f0

Browse files
committed
[#75] Consider manual entries for channels
1 parent ae28d33 commit 2c557f0

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/scripts/helpers/api/request.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,18 @@ export const searchVideos = async (text: string, num = Infinity) => {
9797
Array.prototype.push.apply(vids, body.results);
9898
}
9999
return vids;
100+
};
101+
102+
export const getChannels = async (num = Infinity) => {
103+
const channels: Nebula.Channel[] = [];
104+
const req = new URL(`https://content.api.${getApiBase()}/video_channels/`);
105+
req.searchParams.set('page_size', `${Math.min(100, num)}`);
106+
let url = req.toString();
107+
108+
while (url && channels.length < num) {
109+
const body = await request<Nebula.PagedRequest<Nebula.Channel>>(url);
110+
url = body.next;
111+
Array.prototype.push.apply(channels, body.results);
112+
}
113+
return channels;
100114
};

src/scripts/options.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { marked } from 'marked';
2+
import { loadCreators } from './background';
23
import { purgeCache } from './background/ext';
4+
import { getChannels } from './helpers/api';
35
import { buildModal } from './helpers/modal';
46
import { BrowserMessage, getBrowserInstance, getFromStorage, notification, setToStorage } from './helpers/sharedExt';
57
import { load, saveDirect } from './options/form';
@@ -166,4 +168,16 @@ document.querySelector('[href="#load"]').addEventListener('click', async e => {
166168
else document.querySelector('html').removeAttribute('data-theme');
167169
}
168170
});
169-
})();
171+
})();
172+
173+
if (__DEV__) {
174+
(window as any).checkChannels = async () => {
175+
const channels = await getChannels();
176+
const creators = await loadCreators();
177+
for (let channel of channels) {
178+
const match = creators.find(c => c.nebula === channel.slug || c.nebulaAlt === channel.slug);
179+
if (match) continue;
180+
console.warn('Creator', channel.slug, '(', channel.title, ') has no entry in creators list');
181+
}
182+
};
183+
}

src/scripts/page/offscreen.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1+
import type { Creator } from '../background';
2+
13
export const getInformation = async () => {
24
const res = await fetch('https://talent.nebula.tv/creators/');
35
const body = await res.text();
6+
const res2 = await fetch('https://raw.githubusercontent.com/cpiber/NebulaEnhance/refs/heads/master/channels.json');
7+
const additional: Creator[] = await res2.json();
48
const parser = new DOMParser();
59
const doc = parser.parseFromString(body, 'text/html');
6-
return Array.from(doc.querySelectorAll('#creator-wall .youtube-creator')).map(c => ({
10+
const nebula = Array.from(doc.querySelectorAll('#creator-wall .youtube-creator')).map(c => ({
711
name: c.querySelector('img').alt,
812
nebula: c.querySelector<HTMLAnchorElement>('.link.nebula')?.href?.split('/')?.pop(),
913
nebulaAlt: new URL(c.querySelector<HTMLAnchorElement>('h3 a').href).pathname.split('/')[1],
1014
channel: c.getAttribute('data-video'),
1115
uploads: c.getAttribute('data-video') ? 'UU' + c.getAttribute('data-video').substring(2) : undefined,
1216
}));
17+
return nebula.concat(...additional);
1318
};

0 commit comments

Comments
 (0)