Kodi Community Forum

Full Version: Get hash code from file name to find thumbnails
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi.

I want to know the hash coded name for a thumbnail.

I have found this in the wiki :

http://wiki.xbmc.org/index.php?title=Thumbnails#Hashing

So I make some tests with Python :

Code:
def get_crc32( string ):
    string = string.lower()
    bytes = bytearray(string.encode())
    crc = 0xffffffff;
    for b in bytes:
        crc = crc ^ (b << 24)
        for i in range(8):
            if (crc & 0x80000000 ):
                crc = (crc << 1) ^ 0x04C11DB7
            else:
                crc = crc << 1;
        crc = crc & 0xFFFFFFFF
    return '%08x' % crc

print ("CRC32=", get_crc32("F:\\Videos\\Nosferatu.avi"))

As espected, hash code is :

Code:
CRC32= 2a6ec78d

But I want to find the thumbnail for this picture : C:\TV\TF1.tbn

So same function in Python :

Code:
print ("CRC32=", get_crc32("C:\\TV\\TF1.tbn"))

And result :

Code:
CRC32= 2a6ec78d

But the correct file in thumbnail folder is XBMC\userdata\Thumbnails\Video\11c05c994.tbn

There is a xbmc module for getting the hash location.
See the py-docs.

Example:
https://github.com/XBMC-Addons/script.ar...loader#L80

Thanks Martijn.

But I was doing this outside XBMC and as the code is given in the wiki, I want to understand how XBMC get hash name and not use built in function Tongue
Ah ok Smile
Possibly some one can point you to the source code in XBMC
this has been all changed in master. however;

see CFileItem::GetCachedXXXThumb() for the code in eden (FileItem.cpp)
Thanks Spiff but I don't find the function that give 11c05c994 for the filename C:\TV\TF1.tbn

In FileItem.cpp

Code:
CStdString CFileItem::GetCachedArtistThumb() const
{
  return CThumbnailCache::GetArtistThumb(*this);
}

In ThumbnailCache.cpp

Code:
CStdString CThumbnailCache::GetArtistThumb(const CFileItem &item)
{
  return GetArtistThumb(item.GetLabel());
}
It doesn't give it for a .tbn file. It gives it for the media file. i.e. crc the media file and that's the thumb to use.
OK but I want to write a Pyhton function that give the hash codec name for a fullpath file.

Exactly the same that in the wiki :

http://wiki.xbmc.org/index.php?title=Thumbnails#Hashing

But, as spiff said, the function given is deprecated.

So where can I found in the cpp files, the function that give 11c05c994 (and store thumbnail in XBMC\userdata\Thumbnails\Video\11c05c994.tbn) for the filename C:\TV\TF1.tbn ?

Thanks.
Again, that is not the filename that produced said thumb. TF1.avi if a video file or C:\TV\TF1\ if a folder would have been used.

The cpp file is the one you quote above (ThumbnailCache.cpp) - you'll need an older version, eg look in the Eden branch on github.

https://github.com/xbmc/xbmc/blob/Eden/x...lCache.cpp

Cheers,
Jonathan
Sorry but I don't undersand Sad

What I do :

- Make a directory C:\TV
- Add a M3U file : C:\TV\TF1.m3u
- Add a TBN file : C:\TV\TF1.tbn to specify the thumbnail to XBMC
- Add C:\TV to XBMC source with no scrapper
- In XBMC, first time I access this sourcce, XBMC copy C:\TV\TF1.tbn to XBMC\userdata\Thumbnails\Video\11c05c994.tbn
- If I want to update my TF1.tbn thumbnail, I overwrite C:\TV\TF1.tbn but XBMC don't use it and still display 11c05c994.tbn
- So I have to manually copy my new TF1.tbn to XBMC\userdata\Thumbnails\Video\11c05c994.tbn

But when you have a lot a files in Thumbnails directories, it's hard to know how the searched thumbnail is named.

So I was thinking of a small python code that give me 11c05c994 when I pass C:\TV\TF1.tbn or TF1.tbn (don't know if thumbnail name is based on filename (with or withour extension) or fullpath filename.

Hope that is clearer for you guys Wink

Thanks.
You pass it C:\TV\TF1.m3u
Get it and it's so logical !!!

So with this code :

Code:
def get_crc32( string ):
    string = string.lower()
    bytes = bytearray(string.encode())
    crc = 0xffffffff;
    for b in bytes:
        crc = crc ^ (b << 24)
        for i in range(8):
            if (crc & 0x80000000 ):
                crc = (crc << 1) ^ 0x04C11DB7
            else:
                crc = crc << 1;
        crc = crc & 0xFFFFFFFF
    return '%08x' % crc

print ("CRC32=", get_crc32("C:\\TV\\TF1.m3u"))

Get the correct result :

Code:
CRC32= 1c05c994

But the thumbnail get a one more 1 at first position :

XBMC\userdata\Thumbnails\Video\11c05c994.tbn
The first character is re-used as the subfolder.
OK.

Guess that I haven't subdirectory because I was using a fresh XBMC setup with only 1 file (TF1.m3u) so no subfolder was created Big Grin

Thanks a lot for your answers.