How does the thumbnails linked to the database?

Just curious,



I twiddle around with the Myvideos34.db and userdata/thumbnails/ directory…

I could not find a relation or link between the movie and the thumbnail / fanart… ??



hoping to be enlightened… :slight_smile:



Thanks! :slight_smile:

The thumbnails are named with the CRC32 hash of the video file path.



ahhh it's that strhash thingy? any tips on how do you decode it?

Thanks!!


I've tried to figure this out myself but I'm not having any luck. For example, the movie "Objectified" is stored at /Volumes/donovan/Movies/Objectified (2009).m4v. The crc32 of that is 2e6107f5. So I'd expect the thumbnail path to be ~/Library/Application Support/Plex/userdata/Thumbnails/Video/2/2e6107f5.tbn, but it's not. I found the actual thumbnail for Objectified at 0dd3cc7c. I looked through the code in FileItem.cpp, and I think all the thumbnail path generators use the lowercase version of the file, which means the crc32 is actually 0387cfe1. Closer, but still not it. I've tried converting the slashes to Windows slashes, using only the file name without the path, and the file path without the extension. None of these come out to the actual 0dd3cc7c.

Can anyone give me an explanation of how to generate the right path for this algorithm? (big plus if you do it in Ruby, since that's what I'm using to read the sqlite db and associate the thumbs with the files)


As a heads up, as you may have heard, we've moving away from those databases in the Plex/Nine series :)


Good to know. What's it moving to instead? Is there documentation on this somewhere? The last commit on http://github.com/elan/plex/tree/master is dated from May '09, so I'm guessing that's not the canonical place for the source. And I'd still like this to work in Plex/Eight, so my question still stands. A class/method that I should look at would help, or maybe an example of what m_strPath in CFileItem::GetCachedVideoThumb looks like, if that is actually the right method (for finding the movie poster for a specific movie file). Thanks!


There is no documentation on it yet, and development on the Plex/Nine series is done on a private git repository until the first public release.

The canonical branch for Plex/Eight is here: http://github.com/elan/plex/commits/v0.8

I would think that the method you found is the correct one, but to be honest I find that code so convoluted it gives me headaches :) I think your best bet would be to insert a few prints in that method to see what the final path used is. If you're not building the source let me know and I can do it for you.


I'm inclined to do it myself, as I don't want to waste your time, but I just tried it and got ~6k xcode build errors before finally killing the build. The first was 'Unable to resolve plug-in dependency for "Plex.xib"'. Many of the remaining ones are missing header files (such as SDL/SDL.h), which leads me to believe either my paths aren't set up correctly or I'm missing some prerequisite software.

Help with either doing the print statements yourself or helping me (I'm eventualbuddha in the plex irc channel on freenode) to build the app would be greatly appreciated. Thanks again!

**UPDATE:** Let me read the README first. Always seem to forget that...

If you’re building yourself, make sure you’re building the v0.8 branch, and have all the dependencies installed as per the Wiki page. If you’re on Snow Leopard, you can contact me privately for a zip file containing a working Mac Ports /opt/ directory which should build Plex.



For file mode:



<br />
Computing CRC [/Volumes/Incoming/The Daily Show - 2009-08-20 - Betsy McCaughey/the.daily.show.2009.08.20.pdtv.xvid-fqm.avi] => [/Users/elan/Library/Application Support/Plex/userdata/Thumbnails/Video/a/a6a6aabc.tbn]<br />




For movie mode (perhaps what's screwing up your life at the moment, because there are no actual files harmed in the making of the CRC):


<br />
Computing CRC [videodb://1/2/1] => [/Users/elan/Library/Application Support/Plex/userdata/Thumbnails/Video/5/561f1e38.tbn]<br />




I've run into the same problem. I've tried looking at the source (for XBMC and Boxee also) but I haven't touched C in over 20 years so it just made me dizzy. If you find a solution, I'd appreciate you sharing (as others would I'm sure).

BTW, I was looking at this from the standpoint of REALBasic (fyi).


I eventually figured it out with elan's help. It seems that the crc32 algorithm used in Plex is not the same as the one used in, say, Ruby's zlib (which also happens to agree with the php one I found at http://crc32-checksum.waraxe.us/). The comment at the top of Crc32.cpp says that the crc of 123456789 should be 0376e6e7, though with Ruby (and the php site) I get cbf43926. So I wrote a quick C program based on Crc32.cpp:


<br />
#import <stdio.h><br />
#import <string.h><br />
<br />
unsigned int crc32(unsigned char* buffer, unsigned int count) {<br />
  unsigned int crc = 0xFFFFFFFF;<br />
  unsigned char value;<br />
  int i;<br />
<br />
  while (count--)<br />
  {<br />
    value = *buffer++;<br />
    crc ^= ((unsigned int)value << 24);<br />
    for (i = 0; i < 8; i++)<br />
    {<br />
      if (crc & 0x80000000)<br />
      {<br />
        crc = (crc << 1) ^ 0x04C11DB7;<br />
      }<br />
      else<br />
      {<br />
        crc <<= 1;<br />
      }<br />
    }<br />
  }<br />
<br />
  return crc;<br />
}<br />
<br />
int main(int argc, char** argv)<br />
{<br />
  if (argc < 2) {<br />
    printf("usage: %s STRING
", argv[0]);<br />
    return 1;<br />
  }<br />
<br />
  printf("%08x
", crc32(argv[1], strlen(argv[1])));<br />
  return 0;<br />
}<br />




This program gives the right value:


<br />
$ ./crc32 123456789<br />
0376e6e7<br />




So what I ended up doing is basically this:

[list=1]
[*]Find the movie you want the thumbnail for in ~/Library/Application Support/Plex/userdata/Database/MyVideos34.db, table movie, note its idFile column value.
[*]Find the associated record in the files table (same idFile value), then find the associated record in the path table (via the idPath column value in both tables)
[*]Concatenate the path and file name together to get the full file path (like /Volumes/donovan/Movies/Objectified (2009).m4v), then pass that (*lowercased first!*) to the crc32 function ported to whatever language you're using.
[/list]

Using the program above, I got this:


<br />
$ ./crc32 "/volumes/donovan/movies/objectified (2009).m4v"<br />
0dd3cc7c<br />




So to find the thumbnail for that movie I should look in ~/Library/Application Support/Plex/userdata/Thumbnails/Video/0/0dd3cc7c.tbn, where that file is either a JPG or a PNG. In my library they're pretty much all JPG files, but you can check using the file command:


<br />
$ file 0dd3cc7c.tbn <br />
0dd3cc7c.tbn: JPEG image data, JFIF standard 1.01<br />




Note that, as elan said, this is subject to change. If you want a more well-supported way you could look into the GetMovieDetails API call. Just make sure you turned web access on in your preferences.

I hope that helps!


I'll have to dig out my C books and take a look at your code. I had looked at this a while ago, but now I just want to know because it bugs me.

Thanks for the effort.

For posterity, a Ruby program equivalent to the C program above. The only tricky part for me was making sure I emulated C integer overflow properly.



<br />
#!/usr/bin/env ruby<br />
<br />
def crc32(buffer)<br />
  crc = 0xFFFFFFFF<br />
<br />
  buffer.each_byte do |value|<br />
    crc = uint32(crc ^ (value << 24))<br />
    8.times do<br />
      if (crc & 0x80000000).nonzero?<br />
        crc = uint32((crc << 1) ^ 0x04C11DB7)<br />
      else<br />
        crc = uint32(crc << 1)<br />
      end<br />
    end<br />
  end<br />
<br />
  return crc<br />
end<br />
<br />
def uint32(n)<br />
  n % (1 << 32)<br />
end<br />
<br />
if ARGV.empty?<br />
  puts "usage: #{$0} STRING"<br />
  exit 1<br />
end<br />
<br />
printf("%08x
", crc32(ARGV[0]))<br />


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.