diff --git a/src/scripts/tabOnUpdated.ts b/src/scripts/tabOnUpdated.ts index ae767b9..17e1bb5 100644 --- a/src/scripts/tabOnUpdated.ts +++ b/src/scripts/tabOnUpdated.ts @@ -1,42 +1,9 @@ -import { appRedirectUrl, parseProtocolUrl } from '../common/lbry-url' -import { getExtensionSettingsAsync, getSourcePlatfromSettingsFromHostname, TargetPlatformName } from '../common/settings' -import { YtIdResolverDescriptor, ytService } from '../common/yt' +import { TargetPlatformName } from '../common/settings' +import { YtIdResolverDescriptor } from '../common/yt' export interface UpdateContext { descriptor: YtIdResolverDescriptor /** LBRY URL fragment */ lbryPathname: string redirect: boolean targetPlatform: TargetPlatformName -} - -async function resolveYT(descriptor: YtIdResolverDescriptor) { - const lbryProtocolUrl: string | null = await ytService.resolveById([descriptor]).then(a => a[0]); - const segments = parseProtocolUrl(lbryProtocolUrl || '', { encode: true }); - if (segments.length === 0) return; - return segments.join('/'); -} - -const ctxFromURLOnGoingPromise: Record> = {} -async function ctxFromURL(href: string): Promise { - if (!href) return; - - const url = new URL(href); - if (!getSourcePlatfromSettingsFromHostname(url.hostname)) return - if (!(url.pathname.startsWith('/watch') || url.pathname.startsWith('/channel'))) return - - const descriptor = ytService.getId(href); - if (!descriptor) return; // couldn't get the ID, so we're done - - // Don't create a new Promise for same ID until on going one is over. - const promise = ctxFromURLOnGoingPromise[descriptor.id] ?? (ctxFromURLOnGoingPromise[descriptor.id] = (async () => { - // NOTE: API call cached by resolveYT method automatically - const res = await resolveYT(descriptor) - if (!res) return // couldn't find it on lbry, so we're done - - const { redirect, targetPlatform } = await getExtensionSettingsAsync() - return { descriptor, lbryPathname: res, redirect, targetPlatform } - })()) - await promise - delete ctxFromURLOnGoingPromise[descriptor.id] - return await promise } \ No newline at end of file diff --git a/src/tools/YTtoLBRY.tsx b/src/tools/YTtoLBRY.tsx index 1c053da..ac38427 100644 --- a/src/tools/YTtoLBRY.tsx +++ b/src/tools/YTtoLBRY.tsx @@ -22,7 +22,7 @@ async function lbryChannelsFromFile(file: File) { const lbryUrls = await ytService.resolveById( Array.from(ids).map(id => ({ id, type: 'channel' } as const)), (progress) => render(, document.getElementById('root')!)); - const { targetPlatform: platform } = await getExtensionSettingsAsync('targetPlatform'); + const { targetPlatform: platform } = await getExtensionSettingsAsync(); const urlPrefix = targetPlatformSettings[platform].domainPrefix; return lbryUrls.map(channel => urlPrefix + channel); }