Thumbnail Hash (How is it created)
#1
Thumbs Down 
Hi,

I trying to create a python script to create thumbnails but need to know how the thumbnail.tbn is created.

from reading the forums and browsing the svn source (I have no C,C++ knowledge) I gather that the hash.tbn is created from the full path name to the file.

i.e, 'F:\movies\best\myfirst.avi' (For XBOX Partition)
i.e, 'smb://Mypc/Movies/myfirst.avi' (For smb Share)

What I hope someone can help with is :
* Are the paths converted to lowercase before hashing.
* Does all of filename/path get hashed.
* Is any other data used ie filesize etc used to create the hash.

If someone could give an example of what xbmc would do to my example paths (Listed above) before creating a hash would be very usefull.

I believe that the hash is a plain crc32 hash from what I have read.

The reason I would like this is because my files move around alot from PC,XBOX, DVD and I would like to put my thumbs into a seperate folder using the filename of the avi/album etc. The app would read through my shares and ensure that a thumbnail gets copied into the thumbnails directory regardless of where the file is current system.

Any help would be appreciated and if I manage to write a script for it im sure alot of people would find it a usefull addition. Thanks..Big Grin
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
#2
For videos for instance:

Code:
Crc32 crc;
  if (IsStack())
  {
    CStackDirectory dir;
    crc.ComputeFromLowerCase(dir.GetFirstStackedFile(m_strPath));
  }
  else
    crc.ComputeFromLowerCase(m_strPath);
  CStdString thumb;
  thumb.Format("%s\\%08x.tbn", g_settings.GetVideoThumbFolder().c_str(), (unsigned __int32)crc);

As you can see, it converts to lower case, calculates the CRC and then names the file as that.

Most filetypes follow the same reasoning, though music is slightly more complicated, as there is both file/folder associated thumbs (done in the same way as videos) and there's also album associated thumbs (usually from embedded thumbs, or they're generated during a scan if a folder contains just one album). They're cached based on:

album + path crc'd using the above code.

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
#3
Cheers for that..
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
#4
Sad 
I've tried
Code:
lower(path/filename.ext)
and almost every iteration I can think of and I'm not getting the same values for the CRC32.

The thumbnail file:
Code:
2a6ec78d.tbn
The file:
Code:
F:\Videos\Nosferatu.avi

Table of wrong answers:
f:\videos\nosferatu.avi - BB9A6DBF
f:/videos/nosferatu.avi - 7E470307
videos/local videos/nosferatu.avi - 9EB00BAA
nosferatu.avi - 2AAC6879

My CRC calculations produce the sameas this page: http://www.lammertbies.nl/comm/info/crc-...ation.html

So, what am I missing? Angry
#5
I did solve this with the help of a separate crc module I found whilst trawling the net..

Download This and it will solve your woes as it did mine..
I have included a small script of my own that uses the modules to create a correct filehash for music/video thumbnails..
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
#6
Thank you very much, I shall keep this in my folder. However, I guess I neglected to mention that this project was using C#. Whoopsie.

The code I'm using is from http://www.vbaccelerator.com/home/net/co...C32_cs.asp

And from what I can see, the function isn't correct in some way. For the string '123456789', XBMC gets "0376E6E7" and I get "CBF43926".

I was hoping to make some sort of custom thumbnail replacer for the PC using C#. Sad

Thank you muchly anyway chunk. I might have to work on something pythonie then.
#7
If its C surely you can just use the code from the xbmc CVS source just look for the crc.ComputeFromLowerCase functions.

The script in my link is what I use to re-create my thumbnails. I have all my music thumbnails that match the foldernames of my MP3 music in one folder. But my DVD-Rs could be loaded in either my PC or the XBOX drive so I create two hashs for each original folder name..I run this on my PC.
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
#8
It's a C# project, not a C project. And I can't load C (or C++) code without it first being a DLL and I'm not proficient enough in doing that yet.

*grumble grumble*
#9
Sorry I dont even know the difference between c variants maybe I should learn..!
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
#10
Okee dokee.. figured it out:

C# Code:
Code:
public string Hash(string input)
{
    uint m_crc = 0xffffffff;
    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
    bytes = encoding.GetBytes(input.ToLower());
    foreach (byte myByte in bytes)
    {
        m_crc ^= ((uint)(myByte) << 24);
        for (int i = 0; i < 8; i++)
        {
            if ((System.Convert.ToUInt32(m_crc) & 0x80000000) == 0x80000000)
            {
                m_crc = (m_crc << 1) ^ 0x04C11DB7;
            }
            else
            {
                m_crc <<= 1;
            }
        }
    }
    return String.Format("{0:x8}", m_crc);
}

123456789 returns 0376e6e7
F:\Videos\Nosferatu.avi returns 2a6ec78d
smb://user:pass@server/share/directory/ returns c5559f13
smb://user:pass@server/share/directory/file.ext returns 8ce36055

Remember:
1) When hashing remote shares, use the path as displayed in the sources.xml file, which can include the username and password.
2) When hashing directories for thumbnails, include the final slash.

Hopefully, this will help someone find a specific thumbnail easier :)

Logout Mark Read Team Forum Stats Members Help
Thumbnail Hash (How is it created)2