-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaylist.js
More file actions
126 lines (90 loc) · 3.5 KB
/
Copy pathplaylist.js
File metadata and controls
126 lines (90 loc) · 3.5 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const {CasparCG} = require("casparcg-connection");
const Decimal = require('decimal.js');
const Notifier = require('./class/Notification.js');
const connection = new CasparCG();
// Playlist > run
// VideoQueue > runplaylist
// run_playlist _ _
// runPlaylist
class VideoQueue {
constructor(win) {
this.win = win;
}
async getAllvideolist() {
const playlist = await connection.thumbnailList();
return playlist.response.data;
}
async runPlaylist(data) {
for (const entry of data) {
try {
console.log('--- GROJAM ', entry.name);
await connection.play(1, 1, entry.name);
await this.countframe(entry);
} catch (err) {
console.log(err);
}
}
console.log("Pabaiga");
// return "pabaiga";
// await connection.clear(1,1);
// await connection.disconnect();
}
async templatePlay(data) {
setTimeout(function () {
connection.cgAdd(1, 0, 1, "lower-third-responsive",
1, data);
}, data.beginTime * 1000);
setTimeout(function () {
connection.cgStop(1, 0, 1)
}, data.endTime * 1000);
}
async countframe(entry) {
const notificbegin = new Notifier();
notificbegin.notification(`${entry.name} Pradėjo groti`, entry.name);
console.log('-- ISKVIECIAM');
await new Promise(resolve => setTimeout(resolve, 200));
const videoinfo = await connection.info(1, 1);
const videotime = videoinfo.response.data.stage;
await new Promise(resolve => setTimeout(resolve, 200));
if (!('layer' in videotime)) {
console.log("nera");
await this.countframe(entry);
return;
}
if (videotime.layer.layer_1.foreground.file.time[0] === '0') {
console.log("nera, 0 == 0");
await this.countframe(entry);
return;
}
await new Promise(async (resolve, reject) => {
const intervalFunction = (async () => {
const videoinfo = await connection.info(1, 1);
const videotime2 = videoinfo.response.data.stage;
const videotimefirst = videotime2.layer.layer_1.foreground.file.time[0];
const videotimelast = videotime2.layer.layer_1.foreground.file.time[1];
console.log(videotimefirst, videotimelast);
const decimalnumber = new Decimal(videotimelast);
const progresBar = videotimefirst / videotimelast;
this.win.setProgressBar(progresBar);
this.win.webContents.send('get-time', JSON.stringify({
nowTime: videotimefirst,
endTime: videotimelast,
name: entry.name
}));
if (decimalnumber.equals(new Decimal(videotimefirst))) {
console.log("lygu");
console.log("isgrojo" + entry.name);
clearInterval(intervalId);
const notificend = new Notifier();
notificend.notification(`${entry.name} Baigė groti`, entry.name);
this.win.setProgressBar(-1);
resolve();
}
});
const intervalId = setInterval(intervalFunction, 100);
await intervalFunction();
});
await connection.stop(1, 1);
}
}
module.exports = VideoQueue;