PSeitz / yamaha-nodejs

A node module to control your yamaha receiver
MIT License
123 stars 32 forks source link

Extracting the ID or ULR of an Album_Art #23

Open MarkusMas opened 6 years ago

MarkusMas commented 6 years ago

Hi PSeitz,

thank you for creating this piece of code. I'm trying to use it for creating a driver for my NEEO remote.

Can you please add some commands for extracting info about the playback?

The Request for this would be: <YAMAHA_AV cmd="GET"><SERVER><Play_Info>GetParam</Play_Info></SERVER></YAMAHA_AV>

Response is then for example: <YAMAHA_AV rsp="GET" RC="0"><SERVER><Play_Info><Feature_Availability>Ready</Feature_Availability><Playback_Info>Play</Playback_Info><Play_Mode><Repeat>One</Repeat><Shuffle>Off</Shuffle></Play_Mode><Time><Elapsed>1:26</Elapsed></Time><Meta_Info><Artist>A.A. Milne read by Alan Bennett</Artist><Album>Winnie the Pooh</Album><Song>Eeyore, The Old Grey Donkey...</Song></Meta_Info><Album_ART><URL>/YamahaRemoteControl/AlbumART/AlbumART6475.jpg</URL><ID>64752</ID><Format>JPEG</Format></Album_ART></Play_Info></SERVER></YAMAHA_AV>

I would love to integrate the Album_ART into my project so i need the ID or URL of the Album_Art that is played back.

Can you please help to extract this information? I have a very basic knowledge of coding so help would be really appreciated.

MarkusMas commented 6 years ago

I finally made some progress but i'm stuck again..

I added this to simpleCommand.js to extract the URL: Yamaha.prototype.getPlayInfo = function() { var command = '<YAMAHA_AV cmd="GET"><SERVER><Play_Info>GetParam</Play_Info></SERVER></YAMAHA_AV>'; return this.SendXMLToReceiver(command).then(xml2js.parseStringAsync); };

Yamaha.prototype.getShortAlbumArtURL = function() { return this.getPlayInfo().then(function(info) { var PlayInfo = []; var PlayInfoXML = info.YAMAHA_AV.SERVER[0].Play_Info[0].Album_ART[0].URL[0]; return PlayInfoXML; }); };

Now i can print th URL to the Console with this code: yamaha.getShortAlbumArtURL().then(function(result){ console.log("Short URL is:"+result); })

But if i want to add the IP Adress: var ShortAlbumArtURL = yamaha.getShortAlbumArtURL() var FullAlbumArtURL = 'http://' + yamaha.ip + ShortAlbumArtURL; console.log(FullAlbumArtURL);

The output of the console is: http://192.168.178.39[object Promise]

PSeitz commented 6 years ago

All calls return promises, not the actual result, it should be probably something like this.

yamaha.getShortAlbumArtURL().then(function(url) {
    var FullAlbumArtURL = 'http://' + yamaha.ip + url; 
    console.log(FullAlbumArtURL);
})
MarkusMas commented 6 years ago

Thank you for helping on that very basic level. That writes the full URL to the console :)

How do i manage to have the FullAlbumArtURL available outside this function?!

My goal is to have a module that returns the full URL to another function.

module.exports.GetImageUri = function(deviceid) { return yamaha.getShortAlbumArtURL().then(function(URL) { var FullAlbumArtURL = 'http://' + yamaha.ip + URL; console.log(FullAlbumArtURL); }) };

But the image is then undefined?

PSeitz commented 6 years ago

promises are async, it's not possbile to get the result in a sync manner, you have to use then() like this

GetImageUri().then(function(uri) {
// the result returns
})
MarkusMas commented 6 years ago

Hi PSeitz, thank you for your support! i also got soume support over here: https://planet.neeo.com/r/80jwc9 It works for now ... ^^