Various improvements #3

Merged
amaury.joly merged 16 commits from various-improvements into master 2021-07-27 18:39:49 +02:00
3 changed files with 475 additions and 1607 deletions
Showing only changes of commit f21f752cbb - Show all commits

1901
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,36 +1,36 @@
{
"name": "peertube-plugin-auto-import-ytb",
"description": "PeerTube plugin quickstart",
"version": "0.0.2",
"author": "AmauryJOLY",
"bugs": "https://framagit.org/framasoft/peertube/peertube-plugin-quickstart/issues",
"clientScripts": [],
"css": [],
"devDependencies": {
"ts-node": "^10.0.0",
"typescript": "^4.3.4"
},
"engine": {
"peertube": ">=3.2.0"
},
"homepage": "https://framagit.org/framasoft/peertube/peertube-plugin-quickstart",
"keywords": [
"peertube",
"plugin"
],
"library": "./dist/main.js",
"files": [
"dist/",
"README.md"
],
"scripts": {
"buildAndDeploy": "npm run build && npm run deploy",
"deploy": "bash ./scripts/deploy.sh",
"build": "tsc"
},
"staticDirs": {},
"translations": {},
"dependencies": {
"listener-rss-agregator": "0.0.2"
}
"name": "peertube-plugin-auto-import-ytb",
"description": "PeerTube plugin quickstart",
"version": "0.0.2",
"author": "AmauryJOLY",
"bugs": "https://framagit.org/framasoft/peertube/peertube-plugin-quickstart/issues",
"clientScripts": [],
"css": [],
"devDependencies": {
"ts-node": "^10.0.0",
"typescript": "^4.3.4"
},
"engine": {
"peertube": ">=3.2.0"
},
"homepage": "https://framagit.org/framasoft/peertube/peertube-plugin-quickstart",
"keywords": [
"peertube",
"plugin"
],
"library": "./dist/main.js",
"files": [
"dist/",
"README.md"
],
"scripts": {
"buildAndDeploy": "npm run build && npm run deploy",
"deploy": "bash ./scripts/deploy.sh",
"build": "tsc"
},
"staticDirs": {},
"translations": {},
"dependencies": {
"listener-rss-agregator": "file:/tmp/tmp.lX4jI4rkxi/listener-rss-agregator"
}
}

View File

@ -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 bindistenerChannelId: {[key: string] : string} = {};
let myManager: ListenerRssAggregator;
let listenersDataBinding = new Map<string, ListenerData>();
let logger: any;
let firstUpdate = true;
import * as path from 'path';
import fs from 'fs';
async function register({
registerSetting,
settingsManager,
peertubeHelpers,
peertubeHelpers,
}: any) {
registerSetting({
name: 'ytb-urls',
label: 'liste des urls youtube a auto-importer',
type: 'input-textarea'
})
const basePath = peertubeHelpers.plugin.getDataDirectoryPath();
logger = peertubeHelpers.logger;
const basePath = peertubeHelpers.plugin.getDataDirectoryPath();
myManager = new ManageListener(path.join(basePath, '/data/storage.bd'));
registerSetting({
name: 'ytb-urls',
label: 'liste des urls youtube a auto-importer',
type: 'input-textarea',
});
const inputs = await settingsManager.getSetting('ytb-urls');
logger.warn('setting register');
fs.appendFileSync(path.join(basePath, '/storage.bd'), ''); // append
addListeners(inputs);
const configAggregator = await ListenerRssAggregator.instantiateAggregator(
path.join(basePath, '/storage.bd')
);
myManager = new ListenerRssAggregator(configAggregator);
settingsManager.onSettingsChange((settings: any) => {
myManager.stopAll();
myManager.save();
logger.warn('Aggregator created');
addListeners(settings['ytb-urls']);
})
const inputs = await settingsManager.getSetting('ytb-urls');
if (inputs) await addListeners(inputs);
myManager.on('update', (entries: any) => {
// for (const item in entries.items)
// console.info(item.)
})
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)
);
});
}
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] });
async function addListeners(listenerInput: string) {
let objs: ListenerData[];
try {
objs = JSON.parse(listenerInput);
} catch {
logger.warn('Erreur: malformé');
return;
}
myManager.save();
myManager.startAll();
for (const item of objs) {
if (listenersDataBinding.has(item.address)) break;
listenersDataBinding.set(item.address, {
ChannelId: item.ChannelId,
firstUpdate: item.firstUpdate,
address: item.address,
});
}
myManager.stopAll();
await myManager.saveOverride(objs);
firstUpdate = true;
if (logger) logger.warn('Configuration modifiée: ' + listenerInput);
myManager.startAll();
}
async function unregister() {
myManager.stopAll();
myManager.save();
return
myManager.stopAll();
return;
}
module.exports = {
register,
unregister
}
register,
unregister,
};