import { Fragment, h, JSX, render } from 'preact'; import { useState } from 'preact/hooks'; import { getSettingsAsync, redirectDomains } from '../common/settings'; import { getFileContent, ytService } from '../common/yt'; import readme from './README.md'; /** * Parses the subscription file and queries the API for lbry channels * * @param file to read * @returns a promise with the list of channels that were found on lbry */ async function lbryChannelsFromFile(file: File) { const ext = file.name.split('.').pop()?.toLowerCase(); const content = await getFileContent(file); const ids = new Set((ext === 'xml' || ext == 'opml' ? ytService.readOpml(content) : ytService.readJson(content))) const lbryUrls = await ytService.resolveById(...Array.from(ids).map(id => ({ id, type: 'channel' } as const))); const { redirect } = await getSettingsAsync('redirect'); const urlPrefix = redirectDomains[redirect].prefix; return lbryUrls.map(channel => urlPrefix + channel); } function ConversionCard({ onSelect }: { onSelect(file: File): Promise | void }) { const [file, setFile] = useState(null as File | null); const [isLoading, setLoading] = useState(false); return

Select YouTube Subscriptions

setFile(e.currentTarget.files?.length ? e.currentTarget.files[0] : null)} />
} function YTtoLBRY() { const [lbryChannels, setLbryChannels] = useState([] as string[]); return
setLbryChannels(await lbryChannelsFromFile(file))} />
    {lbryChannels.map((x, i) =>
  • } />)}