Skip to content

Commit

Permalink
Merge pull request #1 from aabytt/hostname-resolve
Browse files Browse the repository at this point in the history
Hostname resolve
  • Loading branch information
aabytt authored Jun 16, 2022
2 parents 2c76ae9 + d5f1af2 commit ad915ea
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions service/service.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
var Service = require('webos-service');
var dns = require('dns').lookup,
dns_resolve;
var url = require('url').parse,
parsedUri;
var service = new Service('com.lampa.tv.service');
var exec = require('child_process').exec,
child;


service.register("ffprobe", function(message) {
child = exec('./ffprobe -v error -print_format json -show_entries stream=index,codec_type,codec_name,codec_long_name,codec_time_base,sample_rate,channels,channel_layout,bit_rate:stream_tags=title,handler_name,language "' + message.payload.uri + '"',
function (error, stdout, stderr) {
message.respond({returnValue: true, result: '[FFPROBE OUTPUT]', data: stdout, stderrText: stderr});

if (error !== null) {
message.respond({returnValue: true, result: '[ERROR]', data: '[DETAILS] ' + error});
}
parsedUri = url(message.payload.uri);
dns_resolve = dns(parsedUri.hostname, function onLookup(err, addresses, family) {
var resolvedUri = parsedUri.protocol + '//'+ addresses + (parsedUri.port ? (':' + parsedUri.port) : '') + parsedUri.path;
child = exec('./ffprobe -v error -print_format json -show_entries stream=index,codec_type,codec_name,codec_long_name,codec_time_base,sample_rate,channels,channel_layout,bit_rate:stream_tags=title,handler_name,language ' + '"' + resolvedUri+'"',
function (error, stdout, stderr) {
message.respond({returnValue: true, result: '[FFPROBE OUTPUT] Resolved uri: ' + resolvedUri, data: stdout, stderrText: stderr});
if (error !== null) {
message.respond({returnValue: true, result: '[ERROR]', data: '[DETAILS] ' + error});
}
});
});
});

0 comments on commit ad915ea

Please sign in to comment.