forked from Outils-PeerTube/peertube-plugin-auto-import-ytb
.
This commit is contained in:
parent
8558c555e5
commit
f21f752cbb
1353
package-lock.json
generated
1353
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -31,6 +31,6 @@
|
||||||
"staticDirs": {},
|
"staticDirs": {},
|
||||||
"translations": {},
|
"translations": {},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"listener-rss-agregator": "0.0.2"
|
"listener-rss-agregator": "file:/tmp/tmp.lX4jI4rkxi/listener-rss-agregator"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
103
src/main.ts
103
src/main.ts
|
@ -1,63 +1,98 @@
|
||||||
import { ManageListener } from 'listener-rss-agregator';
|
import { ListenerRssAggregator } from 'listener-rss-agregator';
|
||||||
|
import { ListenerRSSInfos } from 'listener-rss';
|
||||||
|
type ListenerData = {
|
||||||
|
ChannelId: number;
|
||||||
|
firstUpdate: boolean;
|
||||||
|
} & ListenerRSSInfos;
|
||||||
|
|
||||||
let myManager : ManageListener;
|
let myManager: ListenerRssAggregator;
|
||||||
let bindistenerChannelId: {[key: string] : string} = {};
|
let listenersDataBinding = new Map<string, ListenerData>();
|
||||||
|
let logger: any;
|
||||||
|
let firstUpdate = true;
|
||||||
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
async function register({
|
async function register({
|
||||||
registerSetting,
|
registerSetting,
|
||||||
settingsManager,
|
settingsManager,
|
||||||
peertubeHelpers,
|
peertubeHelpers,
|
||||||
}: any) {
|
}: any) {
|
||||||
|
const basePath = peertubeHelpers.plugin.getDataDirectoryPath();
|
||||||
|
logger = peertubeHelpers.logger;
|
||||||
|
|
||||||
registerSetting({
|
registerSetting({
|
||||||
name: 'ytb-urls',
|
name: 'ytb-urls',
|
||||||
label: 'liste des urls youtube a auto-importer',
|
label: 'liste des urls youtube a auto-importer',
|
||||||
type: 'input-textarea'
|
type: 'input-textarea',
|
||||||
})
|
});
|
||||||
|
|
||||||
const basePath = peertubeHelpers.plugin.getDataDirectoryPath();
|
logger.warn('setting register');
|
||||||
myManager = new ManageListener(path.join(basePath, '/data/storage.bd'));
|
fs.appendFileSync(path.join(basePath, '/storage.bd'), ''); // append
|
||||||
|
|
||||||
|
const configAggregator = await ListenerRssAggregator.instantiateAggregator(
|
||||||
|
path.join(basePath, '/storage.bd')
|
||||||
|
);
|
||||||
|
myManager = new ListenerRssAggregator(configAggregator);
|
||||||
|
|
||||||
|
logger.warn('Aggregator created');
|
||||||
|
|
||||||
const inputs = await settingsManager.getSetting('ytb-urls');
|
const inputs = await settingsManager.getSetting('ytb-urls');
|
||||||
|
if (inputs) await addListeners(inputs);
|
||||||
|
|
||||||
addListeners(inputs);
|
logger.warn('Config loaded');
|
||||||
|
|
||||||
|
settingsManager.onSettingsChange(async (settings: any) => {
|
||||||
|
await addListeners(settings['ytb-urls']);
|
||||||
|
});
|
||||||
|
|
||||||
|
myManager.on('newEntries', (entries: any) => {
|
||||||
|
if (firstUpdate) {
|
||||||
|
logger.warn('Premiere update');
|
||||||
|
|
||||||
|
firstUpdate = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.warn(
|
||||||
|
'Nouvelles baba entrées détéctées: ' + JSON.stringify(entries)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addListeners(listenerInput: string) {
|
||||||
|
let objs: ListenerData[];
|
||||||
|
try {
|
||||||
|
objs = JSON.parse(listenerInput);
|
||||||
|
} catch {
|
||||||
|
logger.warn('Erreur: malformé');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const item of objs) {
|
||||||
|
if (listenersDataBinding.has(item.address)) break;
|
||||||
|
listenersDataBinding.set(item.address, {
|
||||||
|
ChannelId: item.ChannelId,
|
||||||
|
firstUpdate: item.firstUpdate,
|
||||||
|
address: item.address,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
settingsManager.onSettingsChange((settings: any) => {
|
|
||||||
myManager.stopAll();
|
myManager.stopAll();
|
||||||
myManager.save();
|
await myManager.saveOverride(objs);
|
||||||
|
firstUpdate = true;
|
||||||
|
|
||||||
addListeners(settings['ytb-urls']);
|
if (logger) logger.warn('Configuration modifiée: ' + listenerInput);
|
||||||
})
|
|
||||||
|
|
||||||
myManager.on('update', (entries: any) => {
|
|
||||||
// for (const item in entries.items)
|
|
||||||
// console.info(item.)
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function addListeners(listenerInput: any) {
|
|
||||||
for (const line in listenerInput.split('\n'))
|
|
||||||
if (!myManager.listenerArray.map((it: any) => it.address).includes(line)) // si ligne non présente
|
|
||||||
{
|
|
||||||
let splitted = line.split(':');
|
|
||||||
bindistenerChannelId[splitted[1]] = splitted[0];
|
|
||||||
myManager.registerListener({ address: splitted[0] });
|
|
||||||
}
|
|
||||||
|
|
||||||
myManager.save();
|
|
||||||
myManager.startAll();
|
myManager.startAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function unregister() {
|
async function unregister() {
|
||||||
myManager.stopAll();
|
myManager.stopAll();
|
||||||
myManager.save();
|
return;
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
register,
|
register,
|
||||||
unregister
|
unregister,
|
||||||
}
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user