0xVasconcelos / TidalAPI

Unofficial Node.js TIDAL API
MIT License
209 stars 45 forks source link

Playback example #21

Open pschroen opened 8 years ago

pschroen commented 8 years ago

Feature request for either built-in playback support, or a Wiki with examples.

Here's one that handles both lossless and high quality with fluent-ffmpeg and speaker:

api.getStreamURL({id:22560696}, function (data) {
  var url = quality === 'lossless' ? data.url : 'rtmp://'+data.url;
  ffmpeg(url).format('wav').pipe(new Speaker(), {end:true}).on('finish', function () {
    console.log('track finished');
  });
});
0xVasconcelos commented 8 years ago

I'll think about the native playback method, but you're right about the Wiki. I'll try make something this week. :+1:

Thanks friend!

pschroen commented 8 years ago

Improved example with wav to avoid the pop at the beginning.

api.getStreamURL({id:22560696}, function (data) {
  var reader = new wav.Reader();
  reader.on('format', function (format) {
    reader.pipe(new Speaker(format));
  });
  var url = quality === 'lossless' ? data.url : 'rtmp://'+data.url,
  ffmpeg(url).format('wav').pipe(reader, {end:true}).on('finish', function () {
    console.log('track finished');
  });
});
gyurobenjamin commented 7 years ago

Is it still working example? I can play any wav song via http(s) with this example, but not the tidal url what this plugin provide.

Error: ffmpeg exited with code 1: http://audio-enc.tidal.com/v2/0/baf5111593e2f509567fa2901941b6e4_26.flac?__token__=exp=1503781950~hmac=ef36e4ff2c2ec32881b54e73141ef856052440c355d88df26a08f2a6fbe8c849: Invalid data found when processing input

    at ChildProcess.<anonymous> (/../tidal/node_modules/fluent-ffmpeg/lib/processor.js:182:22)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:192:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)

Don't we need to do anything with the encryptionKey?

gyurobenjamin commented 7 years ago

AAC / High quality version works well via rtmp. But lossless/high-res doesn't with FLAC. I downloaded the FLAC file and can't do anything with that.

Any idea?

gyurobenjamin commented 7 years ago

Token was wrong. With some token the file will be encrypted. Check some possibilities here. https://github.com/arnesongit/plugin.audio.tidal2/blob/d633fc9b2d25acf728111460c796e405aece522a/resources/lib/koditidal.py#L733