Home AMX User Forum AMX Design Tools

Adding a HTTP header to dynamic image request

Hey guys

Apple have changed the http request for coverart on an Apple TV very slightly and it now requires the 'User_Agent' header. As a result trying to see the image in a generic browser session (or a dynamic image) no longer works. Is there any way of adding a specific header to a dynamic image http request?

The only other option I can see is to send a GET request (with the right headers) direct from Netlinx, save the response to the master as a png, and then use FTP rather HTTP for the dynamic image. Sounds like hard work though!

Thanks

Simon

Comments

  • Just a matter of piping the data to file then informing the panel to update the resource from where it was saved on the master. If you are on an NX, file name case matters (including the extension) and you will want to enable a device type user with access to http/https.

    DATA_EVENT[dvIP]
    {
        ONLINE:
        {
        nFirstPacket = 1 /// need to look at first packet to see if this is a valid message
    
        FILE_SETDIR('\\')
        IF(FILE_SETDIR(cDir) = -4){//Invalid directory Path
            FILE_CREATEDIR(cDir)
        }
        slFileHandle = FILE_OPEN(cFileName,FILE_RW_NEW)                         
    
        SEND_STRING DATA.DEVICE,"
            'GET ',pathNFile,' HTTP/1.1',13,10,
            'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*',13,10,
            'Accept-Language: en-us',13,10,
            'Accept-Encoding: gzip, deflate',13,10,
            'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',13,10,
            'Host: ',host,13,10,13,10"
    
        }
        STRING:
        {
        IF(nFirstPacket)
        {
            nFirstPacket = 0 /// next time, not the first packet.
    
            IF(FIND_STRING(DATA.TEXT,'HTTP/1.1 200 OK',1))
            {
            IF(FIND_STRING(DATA.TEXT,"$D,$A,$D,$A",1))
            {
                REMOVE_STRING(DATA.TEXT,"$D,$A,$D,$A",1)
    
                slResult = FILE_WRITE(slFileHandle,DATA.TEXT,LENGTH_STRING(DATA.TEXT))
            }
            }
            ELSE IF(FIND_STRING(DATA.TEXT,'HTTP',1))
            {
            SEND_STRING 0,"'RESPONSE FROM WEB SERVER:',DATA.TEXT"
            slResult = FILE_CLOSE(slFileHandle)
            }
        }
        ELSE
        {
            slResult = FILE_WRITE(slFileHandle,DATA.TEXT,LENGTH_STRING(DATA.TEXT))
        }
    
        }
        OFFLINE:
        {
        slResult = FILE_CLOSE(slFileHandle)
        FILE_SETDIR('\\')
        }
    

    }

  • Piping the data to a file on the master is simple enough

    DATA_EVENT[dvIP]
    {
        ONLINE:
        {
    
        SEND_STRING DATA.DEVICE,"
            'GET ',pathNFile,' HTTP/1.1',13,10,
            'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*',13,10,
            'Accept-Language: en-us',13,10,
            'Accept-Encoding: gzip, deflate',13,10,
            'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',13,10,
            'Host: ',host,13,10,13,10"
            //'Connection: Keep-Alive',13,10,13,10"
    
        nFirstPacket = 1 /// need to look at first packet to see if this is a valid message
    
        FILE_SETDIR('\\')
        IF(FILE_SETDIR(cDir) = -4){//Invalid directory Path
            FILE_CREATEDIR(cDir)
        }
        slFileHandle = FILE_OPEN(cFileName,FILE_RW_NEW)                         // CREATE THE OLD FILE AGAIN
        }
        STRING:
        {
        IF(nFirstPacket)
        {
            nFirstPacket = 0 /// next time, not the first packet.
    
            IF(FIND_STRING(DATA.TEXT,'HTTP/1.1 200 OK',1))
            {
            IF(FIND_STRING(DATA.TEXT,"$D,$A,$D,$A",1))
            {
                REMOVE_STRING(DATA.TEXT,"$D,$A,$D,$A",1)
    
                slResult = FILE_WRITE(slFileHandle,DATA.TEXT,LENGTH_STRING(DATA.TEXT))
            }
            }
            ELSE IF(FIND_STRING(DATA.TEXT,'HTTP',1))
            {
            SEND_STRING 0,"'RESPONSE FROM WEB SERVER:',DATA.TEXT"
            slResult = FILE_CLOSE(slFileHandle)
            }
        }
        ELSE
        {
            slResult = FILE_WRITE(slFileHandle,DATA.TEXT,LENGTH_STRING(DATA.TEXT))
        }
    
        }
        OFFLINE:
        {
        slResult = FILE_CLOSE(slFileHandle)
        FILE_SETDIR('\\')
        }
    }
    

    At the offline event notify the panel to update the dynamic resource as saved on the master. If on an NX case matters (including the file extension) and you will want to enable a device type user to allow access across http/https.

  • Thanks Ian - I had tried this but was having issues with the file size (its around 200kb) - but I hadn't thought of just writing everything regardless until the offline event and then closing the file. I'll have to use an additional IP port I think as currently I'm only using one for all of the control/feedback and I reckon the coverart might slow it down too much.

    Cheers

    Simon

  • @sling100 said:
    Thanks Ian - I had tried this but was having issues with the file size (its around 200kb) - but I hadn't thought of just writing everything regardless until the offline event and then closing the file. I'll have to use an additional IP port I think as currently I'm only using one for all of the control/feedback and I reckon the coverart might slow it down too much.

    Cheers

    Simon

    This works but it dates back 10 or so years; if I was writing today I would implement a buffer then at the offline event use the content-length header value to right_string() the data into a file as a whole.

  • That's how rest of it works - using the Content-Length. Just not sure my buffer will be big enough :smile:

  • @sling100 said:
    That's how rest of it works - using the Content-Length. Just not sure my buffer will be big enough :smile:

    volatile char sIpBuffer[200000] <- make it as big as you need. 200k enough?

    Although I guess the string handler event piping negates the need to ever optimize the buffer length to the application - might be a valid use case for not using calling create_buffer

Sign In or Register to comment.