1 |
|
2 | "use strict";
|
3 |
|
4 | const debug = require('debug')('upnpserver:contentHandlers.Srt');
|
5 | const logger = require('../logger');
|
6 |
|
7 | const ContentHandler = require('./contentHandler');
|
8 |
|
9 | class Srt extends ContentHandler {
|
10 |
|
11 | get name() {
|
12 | return "srt";
|
13 | }
|
14 |
|
15 | |
16 |
|
17 |
|
18 | prepareMetas(contentInfos, context, callback) {
|
19 |
|
20 | var contentURL = contentInfos.contentURL;
|
21 |
|
22 | var srtBasename = contentURL.basename.replace(/\.[^.]*$/, '.srt');
|
23 |
|
24 | var srtURL = contentURL.changeBasename(srtBasename);
|
25 |
|
26 | srtURL.stat((error, stats) => {
|
27 | if (error) {
|
28 | if (error.code === "ENOENT") {
|
29 | return callback();
|
30 | }
|
31 |
|
32 | return callback(error);
|
33 | }
|
34 |
|
35 | if (stats.isFile() && stats.size > 0) {
|
36 | debug("prepareMetas", "SRT detected => url=" + srtURL);
|
37 |
|
38 | var res = [{}];
|
39 | var metas = {
|
40 | res: res
|
41 | };
|
42 |
|
43 | res.push({
|
44 | contentHandlerKey: this.name,
|
45 | key: "1",
|
46 | type: "srt",
|
47 | mimeType: "text/srt",
|
48 | size: stats.size,
|
49 | mtime: stats.mtime.getTime()
|
50 | });
|
51 |
|
52 | return callback(null, metas);
|
53 | }
|
54 |
|
55 | return callback();
|
56 | });
|
57 | }
|
58 |
|
59 | |
60 |
|
61 |
|
62 | processRequest(node, request, response, path, parameters, callback) {
|
63 |
|
64 | var contentURL = node.contentURL;
|
65 | var basename = contentURL.basename;
|
66 | var srtURL = contentURL.changeBasename(basename.replace(/\.[^.]*$/, '.srt'));
|
67 |
|
68 | debug("processRequest", "srtURL=", srtURL, "contentURL=", contentURL);
|
69 |
|
70 | this.service.sendContentURL({
|
71 | contentURL: srtURL
|
72 |
|
73 | }, request, response, callback);
|
74 | }
|
75 | }
|
76 |
|
77 | module.exports = Srt;
|