Kodi Community Forum
How do I get a thumbnail via HTTP API? - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Kodi Application (https://forum.kodi.tv/forumdisplay.php?fid=93)
+--- Thread: How do I get a thumbnail via HTTP API? (/showthread.php?tid=46134)



How do I get a thumbnail via HTTP API? - pummra - 2009-02-27

This probably super easy, I just can't get my head round it.

I am able to get the thumbnail from XBMC using:

http://10.0.0.2/xbmcCmds/xbmcHttp?command=GetThumb(C:\Documents%20and%20Settings\jenkins\Application%20Data\XBMC\userdata\Thumbnails\Video\9\99caa6a6.tbn%20)

but all I get from that is a load of text, how do I covert it to a JPEG?


- spiff - 2009-02-27

it's mime64 encoded


- bufferbuilder - 2009-02-27

I've been attempting the same thing. I believe you can use the FileDownload command in the API or use the CopyFile command which would allow you to copy the thumb to a folder that is exposed to the web server.

Hopefully, someone can confirm or set me straight.


- spiff - 2009-02-27

do the getthumb. mime64-decode the data. you have your thumb.
or use the CopyFile/FileDownload stuff but that will surely be much slower if you plan to grab many thumbs..

http://en.wikipedia.org/wiki/Base64


- pummra - 2009-03-06

I may be being really dim but I can't seem to decode any thumbnails should the below code work?

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://10.0.0.2/xbmcCmds/xbmcHttp?command=GetThumb(C:\Documents%20and%20Settings\jenkins\Application%20Data\XBMC\userdata\Thumbnails\Video\9\99caa6a6.tbn)');
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$test = curl_exec($curl_handle);
curl_close($curl_handle);


$ifp = fopen( "image.jpg", "wb" );
fwrite( $ifp, base64_decode( $test) );
fclose( $ifp );

It creates the image but the image doesn't open. Can anyone help.


- pummra - 2009-03-09

Can anyone help me with this? I am wanting to create a new web interface to control XBMC but am coming across this stumbling block and can't get round it.


- pummra - 2009-03-16

is there anyone who can give me a clue on this?

the above code was in PHP.


- Bram77 - 2009-03-16

I've tried GetThumb and couldn't get it to work either (C#).
I'm using FileDownload to get the now playing cover art...

Code:
public bool FileExists(string filePath)
        {
            string[] response =    parent.Request("FileExists", filePath);
            return parent.CreateBoolRespose(response);
        }
        
        public MemoryStream FileDownload(string filePath)
        {
            MemoryStream msFile;
            string[] aDownloadData;
            byte[] aFileBytes;
            
            if (this.FileExists(filePath))
            {
                try
                {
                    aDownloadData = parent.Request("FileDownload(" +filePath+ ";[bare])");
                    
                    if (aDownloadData != null)
                    {
                        aFileBytes     = Convert.FromBase64String(aDownloadData[0]);
                        msFile        = new MemoryStream(aFileBytes, 0, aFileBytes.Length);
                        //msFile.Write(aFileBytes, 0, aFileBytes.Length);
                    }
                    else
                        msFile = null;
                }
                catch (Exception e)
                {
                    parent.WriteToLog(DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss") + " - DEBUG: " + e.Message + " || " + filePath);
                    msFile = null;
                }
            }
            else
            {
                MessageBox.Show("File does not exist");
                msFile = null;
            }
            
            return msFile;
        }
This returns a MemoryStream which you won't be using in PHP.


- pummra - 2009-03-20

I'm an idiot, I just didn't have the bare parameter set!


- controlbyte - 2009-03-31

I'm trying to do that with

Code:
GetCurrentlyPlaying([thumbFilename],[nothingPlayingFilename],[onlyIfChanged])

but I've not been succesful.


- nad - 2009-04-09

Have a look at the .Net source code here http://code.google.com/p/xbmc-http-api-apps/downloads/list

If you are wanting to display a thumb from within a browser the easiest approach is the CopyFile approach that bufferbuilder mentioned.

Nad