65 lines
1.4 KiB
JavaScript
65 lines
1.4 KiB
JavaScript
import { ManageListener } from 'gestion-listener';
|
|
|
|
let myManager;
|
|
let bindBtwistenerChannelId = {};
|
|
|
|
async function register({
|
|
registerHook,
|
|
registerSetting,
|
|
settingsManager,
|
|
storageManager,
|
|
videoCategoryManager,
|
|
videoLicenceManager,
|
|
videoLanguageManager
|
|
}) {
|
|
registerSetting({
|
|
name: 'ytb-urls',
|
|
label: 'liste des urls youtube a auto-importer',
|
|
type: 'input-textarea'
|
|
})
|
|
|
|
const basePath = peertubeHelpers.plugin.getDataDirectoryPath();
|
|
myManager = new ManageListener(path.join(basePath, '/data/storage.bd'));
|
|
|
|
const inputs = await settingsManager.getSetting('ytb-urls');
|
|
|
|
addListeners(inputs);
|
|
|
|
settingsManager.onSettingsChange((settings) => {
|
|
myManager.stopAll();
|
|
myManager.save();
|
|
|
|
addListeners(settings['ytb-urls']);
|
|
})
|
|
|
|
myManager.on('newEntries', (entries) => {
|
|
// for (const item in entries.items)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
function addListeners(listenerInput) {
|
|
for (const line in listenerInput.split('\n'))
|
|
if (!myManager.listenerArray.map((it) => it.address).includes(line)) // si ligne non présente
|
|
{
|
|
let splitted = line.split(':');
|
|
bindBtwistenerChannelId[splitted[1]] = splitted[0];
|
|
myManager.addNewListener({ address: splitted[0] });
|
|
}
|
|
|
|
myManager.save();
|
|
myManager.startAll();
|
|
}
|
|
|
|
async function unregister() {
|
|
myManager.stopAll();
|
|
myManager.save();
|
|
return
|
|
}
|
|
|
|
module.exports = {
|
|
register,
|
|
unregister
|
|
}
|