JSON and javascipt
#31
(2012-09-19, 21:57)Mizaki Wrote: That doesn't look encoded to me. You have to encode the already encoded thumbnail string. Your string should look like:
Code:
http://192.168.1.9:80/image/image%253A%252F%252Fmusic%2540smb%25253a%25252f%25252fDOE-HTPC%25252fStorage%252520%28E%29%25252fMusic%25252fOasis%252520-%252520Hello.mp3

Apologies, had the wrong code in the first code box.
I've edited it now.... sorry.

but still not working.
Reply
#32
(2012-09-19, 22:00)Millencolin007 Wrote: It looks to me like you are encoding the filename instead of the thumbnail since it ends with .mp3 . You cannot simply take the filename and add image:// in front of it. You need to use the thumbnail or fanart value from the json response

It is the response from the JSON request.

Request:
Code:
{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "album", "artist", "duration", "thumbnail", "file", "fanart", "streamdetails"], "playerid": 0 }, "id": 1}

Response:
Code:
{"id":1,"jsonrpc":"2.0","result":{"item":{"album":"(What's the Story) Morning Glory?","artist":["Oasis"],"duration":239,"fanart":"image://","file":"smb://DOE-HTPC/Storage (E)/Music/Oasis - Roll With It.mp3","id":9,"label":"Oasis - Roll With It","thumbnail":"image://music@smb%3a%2f%2fDOE-HTPC%2fStorage%20(E)%2fMusic%2fOasis%20-%20Hello.mp3","title":"Roll With It","type":"song"}}}

I've urlencoded and tried encodeURIComponent, even online encoder, but won't work in chrome or firefox.

Are you saying I should drop the .mp3?
Reply
#33
No you should not drop the .mp3 but you can try to use Files.PrepareDownload to encode the url

Code:
curl  -H "Content-Type: application/json"  -d "{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"Files.PrepareDownload\",\"params\":{\"path\":\"image://music@%2fmedia%2fMusic%2fMusic%2fSwiss%20Albums%2fHip-Hop%2fWrecked%20Mob%20-%20Mission%20possible%20-%201998%2fWrecked%20Mob%20-%20Honig%20(feat.%20indiecan).mp3\"}}" http://10.0.0.1:8080/jsonrpc

Returns the encoded url you should use

Code:
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "details": {
            "path": "image/image%3a%2f%2fmusic%40%252fmedia%252fMusic%252fMusic%252fSwiss%2520Albums%252fHip-Hop%252fWrecked%2520Mob%2520-%2520Mission%2520possible%2520-%25201998%252fWrecked%2520Mob%2520-%2520Honig%2520(feat.%2520indiecan).mp3"
        },
        "mode": "redirect",
        "protocol": "http"
    }
}
Reply
#34
(2012-09-19, 22:34)Millencolin007 Wrote: No you should not drop the .mp3 but you can try to use Files.PrepareDownload to encode the url

Code:
curl  -H "Content-Type: application/json"  -d "{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"Files.PrepareDownload\",\"params\":{\"path\":\"image://music@%2fmedia%2fMusic%2fMusic%2fSwiss%20Albums%2fHip-Hop%2fWrecked%20Mob%20-%20Mission%20possible%20-%201998%2fWrecked%20Mob%20-%20Honig%20(feat.%20indiecan).mp3\"}}" http://10.0.0.1:8080/jsonrpc

Returns the encoded url you should use

Code:
{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "details": {
            "path": "image/image%3a%2f%2fmusic%40%252fmedia%252fMusic%252fMusic%252fSwiss%2520Albums%252fHip-Hop%252fWrecked%2520Mob%2520-%2520Mission%2520possible%2520-%25201998%252fWrecked%2520Mob%2520-%2520Honig%2520(feat.%2520indiecan).mp3"
        },
        "mode": "redirect",
        "protocol": "http"
    }
}


I tried the Files.PrepareDownload method as follows:
Code:
{"jsonrpc": "2.0", "method": "Files.PrepareDownload", "params":{"path":"image://music@smb%3a%2f%2fDOE-HTPC%2fStorage%20(E)%2fMusic%2fBlink-182%20-%20Adam%27s%20Song.mp3" , "id": "1"}}

It returns a 200 OK response but no data.

After seeing my last post, I noticed my First } was in the wrong location....
Reply
#35
What's the easiest way to listen for the end of a song/movie so that the thumbnail can refresh to the new one?

I was going to have javascript pull the either the duration or percentage element and work off that, but the concern would be if the user stopped it in the middle the HA unit wouldn't be able to tell.

I read somewhere that XBMC broadcasts certain functions... Is this correct??
If so, what format are the packets sent in and what port?

Perhaps I can get the HA unit listening on that port and act on that.
Again, If so, what command would I be listening for? Is there a forum page with commands etc?

I want to take the opportunity to thank everyone for their perseverance,
It's never easy with Third-Party devices, especially ones soooo restricted in what code is available.

Thanks,

Jasp
Reply
#36
If you use HTTP you either have to use websockets for notifications or you can poll. Until websockets, polling is how all web interfaces worked. Just request current player and then item. You could probably just query Player.GetItem. The other way which I've not used is TCP on port 9090.
Image
AWXi - Ajax web interface. Wiki
Reply

Logout Mark Read Team Forum Stats Members Help
JSON and javascipt0