.
This commit is contained in:
parent
8558c555e5
commit
f21f752cbb
1901
package-lock.json
generated
1901
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
68
package.json
68
package.json
|
@ -1,36 +1,36 @@
|
||||||
{
|
{
|
||||||
"name": "peertube-plugin-auto-import-ytb",
|
"name": "peertube-plugin-auto-import-ytb",
|
||||||
"description": "PeerTube plugin quickstart",
|
"description": "PeerTube plugin quickstart",
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
"author": "AmauryJOLY",
|
"author": "AmauryJOLY",
|
||||||
"bugs": "https://framagit.org/framasoft/peertube/peertube-plugin-quickstart/issues",
|
"bugs": "https://framagit.org/framasoft/peertube/peertube-plugin-quickstart/issues",
|
||||||
"clientScripts": [],
|
"clientScripts": [],
|
||||||
"css": [],
|
"css": [],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ts-node": "^10.0.0",
|
"ts-node": "^10.0.0",
|
||||||
"typescript": "^4.3.4"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"engine": {
|
"engine": {
|
||||||
"peertube": ">=3.2.0"
|
"peertube": ">=3.2.0"
|
||||||
},
|
},
|
||||||
"homepage": "https://framagit.org/framasoft/peertube/peertube-plugin-quickstart",
|
"homepage": "https://framagit.org/framasoft/peertube/peertube-plugin-quickstart",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"peertube",
|
"peertube",
|
||||||
"plugin"
|
"plugin"
|
||||||
],
|
],
|
||||||
"library": "./dist/main.js",
|
"library": "./dist/main.js",
|
||||||
"files": [
|
"files": [
|
||||||
"dist/",
|
"dist/",
|
||||||
"README.md"
|
"README.md"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"buildAndDeploy": "npm run build && npm run deploy",
|
"buildAndDeploy": "npm run build && npm run deploy",
|
||||||
"deploy": "bash ./scripts/deploy.sh",
|
"deploy": "bash ./scripts/deploy.sh",
|
||||||
"build": "tsc"
|
"build": "tsc"
|
||||||
},
|
},
|
||||||
"staticDirs": {},
|
"staticDirs": {},
|
||||||
"translations": {},
|
"translations": {},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"listener-rss-agregator": "0.0.2"
|
"listener-rss-agregator": "file:/tmp/tmp.lX4jI4rkxi/listener-rss-agregator"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
109
src/main.ts
109
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) {
|
||||||
registerSetting({
|
const basePath = peertubeHelpers.plugin.getDataDirectoryPath();
|
||||||
name: 'ytb-urls',
|
logger = peertubeHelpers.logger;
|
||||||
label: 'liste des urls youtube a auto-importer',
|
|
||||||
type: 'input-textarea'
|
|
||||||
})
|
|
||||||
|
|
||||||
const basePath = peertubeHelpers.plugin.getDataDirectoryPath();
|
registerSetting({
|
||||||
myManager = new ManageListener(path.join(basePath, '/data/storage.bd'));
|
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) => {
|
logger.warn('Aggregator created');
|
||||||
myManager.stopAll();
|
|
||||||
myManager.save();
|
|
||||||
|
|
||||||
addListeners(settings['ytb-urls']);
|
const inputs = await settingsManager.getSetting('ytb-urls');
|
||||||
})
|
if (inputs) await addListeners(inputs);
|
||||||
|
|
||||||
myManager.on('update', (entries: any) => {
|
logger.warn('Config loaded');
|
||||||
// for (const item in entries.items)
|
|
||||||
// console.info(item.)
|
|
||||||
|
|
||||||
})
|
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) {
|
async function addListeners(listenerInput: string) {
|
||||||
for (const line in listenerInput.split('\n'))
|
let objs: ListenerData[];
|
||||||
if (!myManager.listenerArray.map((it: any) => it.address).includes(line)) // si ligne non présente
|
try {
|
||||||
{
|
objs = JSON.parse(listenerInput);
|
||||||
let splitted = line.split(':');
|
} catch {
|
||||||
bindistenerChannelId[splitted[1]] = splitted[0];
|
logger.warn('Erreur: malformé');
|
||||||
myManager.registerListener({ address: splitted[0] });
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
myManager.save();
|
for (const item of objs) {
|
||||||
myManager.startAll();
|
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() {
|
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