-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 loc) · 1.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#! /usr/bin/env node
const Rx = require('@reactivex/rxjs');
const YamlFs = require('yaml-fs').YamlFs;
const Analyzer = require('./analyzer.js');
const CastsAnalyzer = require('./castsAnalyzer.js');
let yamlFs = new YamlFs();
if (process.argv.length < 3) {
console.log('Programm needs to be invoked with directory');
process.exit(1);
}
let directory = process.argv[2];
yamlFs.getMetaDataForFiles(directory)
.then(metaDataList => {
let analyzer = new Analyzer(metaDataList);
let castsAnalzyer = new CastsAnalyzer();
Rx.Observable
.from(metaDataList)
.flatMap(fileMetaData => {
return Rx.Observable.forkJoin(
castsAnalzyer.getRelatedVideos(fileMetaData),
analyzer.getRelatedPosts(fileMetaData)
).map(related => {
[relatedVideos, relatedPosts] = related;
fileMetaData.yamlProperties.related_posts = relatedPosts;
if (!fileMetaData.yamlProperties.no_related_videos) {
fileMetaData.yamlProperties.related_videos = relatedVideos;
}
return fileMetaData;
})
}, 4).subscribe(fileMetaData => {
yamlFs.writeFile(fileMetaData);
});
});