mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
Added CSV support for subscribtion converter
This commit is contained in:
parent
6cc149a5c6
commit
dfdfe6778a
2 changed files with 19 additions and 4 deletions
|
@ -57,7 +57,7 @@ export const ytService = {
|
||||||
*/
|
*/
|
||||||
readOpml(opmlContents: string): string[] {
|
readOpml(opmlContents: string): string[] {
|
||||||
const opml = new DOMParser().parseFromString(opmlContents, 'application/xml');
|
const opml = new DOMParser().parseFromString(opmlContents, 'application/xml');
|
||||||
|
opmlContents = ''
|
||||||
return Array.from(opml.querySelectorAll('outline > outline'))
|
return Array.from(opml.querySelectorAll('outline > outline'))
|
||||||
.map(outline => outline.getAttribute('xmlUrl'))
|
.map(outline => outline.getAttribute('xmlUrl'))
|
||||||
.filter((url): url is string => !!url)
|
.filter((url): url is string => !!url)
|
||||||
|
@ -73,9 +73,22 @@ export const ytService = {
|
||||||
*/
|
*/
|
||||||
readJson(jsonContents: string): string[] {
|
readJson(jsonContents: string): string[] {
|
||||||
const subscriptions: YtSubscription[] = JSON.parse(jsonContents);
|
const subscriptions: YtSubscription[] = JSON.parse(jsonContents);
|
||||||
|
jsonContents = ''
|
||||||
return subscriptions.map(sub => sub.snippet.resourceId.channelId);
|
return subscriptions.map(sub => sub.snippet.resourceId.channelId);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads an array of YT channel IDs from the YT subscriptions CSV file
|
||||||
|
*
|
||||||
|
* @param csvContent a CSV file as a string
|
||||||
|
* @returns the channel IDs
|
||||||
|
*/
|
||||||
|
readCsv(csvContent: string): string[] {
|
||||||
|
const rows = csvContent.split('\n')
|
||||||
|
csvContent = ''
|
||||||
|
return rows.map((row) => row.substr(0, row.indexOf(',')))
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts the channelID from a YT URL.
|
* Extracts the channelID from a YT URL.
|
||||||
*
|
*
|
||||||
|
|
|
@ -14,9 +14,11 @@ import readme from './README.md'
|
||||||
*/
|
*/
|
||||||
async function lbryChannelsFromFile(file: File) {
|
async function lbryChannelsFromFile(file: File) {
|
||||||
const ext = file.name.split('.').pop()?.toLowerCase();
|
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 ids = new Set((
|
||||||
|
ext === 'xml' || ext == 'opml' ? ytService.readOpml :
|
||||||
|
ext === 'csv' ? ytService.readCsv :
|
||||||
|
ytService.readJson)(await getFileContent(file)))
|
||||||
const lbryUrls = await ytService.resolveById(...Array.from(ids).map(id => ({ id, type: 'channel' } as const)));
|
const lbryUrls = await ytService.resolveById(...Array.from(ids).map(id => ({ id, type: 'channel' } as const)));
|
||||||
const { platform } = await getSettingsAsync('platform');
|
const { platform } = await getSettingsAsync('platform');
|
||||||
const urlPrefix = platformSettings[platform].domainPrefix;
|
const urlPrefix = platformSettings[platform].domainPrefix;
|
||||||
|
|
Loading…
Add table
Reference in a new issue