What algorithm does plex use to get database hash value?

I am trying to match the file on the HD with the file listed in the sqlite database using the hash value. Does plex just hash the movie file or does it hash the entire directory? I’ve tried sha1, md5 and others with no luck finding a match for the movie listing in the .db

Plex reads the first block from the file (4K) and generates the hash from there.
It doesn’t make sense to hash the entire file as that would be wasteful and resource intensive.

Thanks @ChuckPa !

Now I am searching for a simple way to do this on the command line… and not coming up with much.

file="path/to/mp4"

08/07/22_19:08:14 /Users/john
0-zsh% dd count=1 ibs=4k < "$file" | openssl sha1
1+0 records in
8+0 records out
4096 bytes transferred in 0.000015 secs (273066667 bytes/sec)
b024d1b7910d423fdb59b5687bcf97519f056771

However this does not match the hash in the database for that mp4. In fact it looks like most of the first 4k just has the encoding info.

EDIT
tried changing language for terminal according to this post


08/07/22_19:31:42 /Users/john/
0-zsh% LC_CTYPE=C && LANG=C

08/07/22_19:34:01 /Users/john/
0-zsh% dd bs=1 count=4096 < "$file" > bytes 
4096+0 records in
4096+0 records out
4096 bytes transferred in 0.010991 secs (372669 bytes/sec)

08/07/22_19:34:11 /Users/john/
0-zsh% wc -m /Users/john/bytes 
    4096 /Users/john/bytes

08/07/22_19:34:20 /Users/john/
0-zsh% openssl sha1 /Users/john/bytes 
SHA1(/Users/john/bytes)= b024d1b7910d423fdb59b5687bcf97519f056771

Suggestions please!

ALSO,
Is there a description somewhere of other metadata_items values in ~/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db

Tried to figure out duration which can’t be in seconds… is it milliseconds?

There is a column in the path, named file, which contains the path to the file.

You’re looking for media_parts table.

I am trying to modify the date in the database to match the date of the file on the disk. For some reason Plex is not displaying files in order they were added. That is my ultimate purpose here.

Plex’s method for storing dates is not any way you’d expect.
It’s stored in seconds since epoch.

I would think it’s easier to touch a file and set the date fields than to modifiy the database

Plex adds the file in the order presented by readdir()

I have that epoch bit figured out.

The files themselves all have the correct modification dates but for some reason plex is not displaying them in the order they were added. Not sure touching the files will cause plex to update.

Can you be more specific on how it generates the hash?

I have tried a number of methods on the command line and have failed to match the hash value that plex calculates.

Is it the video alone or the entire mp4 container that is hashed?

Encoding settings?

@John_001

As I said, they read the first block (4K) bytes.

This includes the header (media info) and the start of the video stream.

They have a routine which generates the hash. I can’t share it because it’s proprietary C++

1 Like

If I go back to your OP,

“Which file on the HD?”

I can do this:

<r/Library/Plex Media Server/Plug-in Support/Databases] # ../../../../Plex\ SQLite com.plexapp.plugins.library.db            
SQLite version 3.35.5 2021-04-19 18:32:05
Enter ".help" for usage hints.
sqlite> select file from media_parts;
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E01 - Pilot [ HDTV-1080p AVC EAC3 5.1 ].mkv
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E02 - Sex for Furniture [ HDTV-1080p AVC EAC3 5.1 ].mkv
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E03 - The Ring [ HDTV-1080p AVC EAC3 5.1 ].mkv
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E04 - The Wood Pile [ HDTV-1080p AVC EAC3 5.1 ].mkv
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E05 - The Garage Band [ HDTV-1080p AVC EAC3 5.1 ].mkv
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E06 - Your Mother or Your Wife [ HDTV-1080p AVC EAC3 5.1 ].mkv
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E07 - Dream Getaway [ HDTV-1080p AVC EAC3 5.1 ].mkv
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E08 - Death Sex [ WEBDL-1080p h264 EAC3 5.1 ].mkv
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E09 - The Toaster [ DVD XviD MP3 2.0 ].avi
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E10 - Daddy's Girl [ WEBDL-1080p h264 EAC3 5.1 ].mkv
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E11 - The Anniversary Party [ WEBDL-1080p h264 EAC3 5.1 ].mkv
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E12 - The Hockey Lie [ WEBDL-1080p h264 EAC3 5.1 ].mkv
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E13 - Fight Friend [ DVD XviD MP3 2.0 ].avi
/share/CACHEDEV1_DATA/nas/glock/qa/340/tv/00s/'Til Death (2006)/Season 01/'Til Death (2006) - S01E14 - The Colleague [ DVD XviD MP3 2.0 ].avi

There’s the path. You can then take the ID columns from other tables to here or back (for a few of them)

Use the rest API

http://<IP_OF_PMS>:32400/library/metadata/<MEDIA_KEY>/tree?X-Plex-Token=<YOUR_TOKEN>

You can find your token here:
https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/

Sample:

Issue:

curl -k https://192.168.1.2:32400/library/metadata/9038/tree?X-Plex-Token=ThisIsMyToken

Response:

<?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="1" identifier="com.plexapp.plugins.library" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1659032912">
<MetadataItem id="9038" title="2 Minutes Later" guid="plex://movie/5d776845999c64001ec3234c" parentTitle="" instanceRatingKey="" index="1" originallyAvailableAt="2007-04-13" addedAt="1215276889" refreshedAt="1659144719">
<MediaItem id="9321">
<MediaPart id="152394" file="/share/CACHEDEV1_DATA/video/movies/2 Minutes Later (2007) {imdb-tt0892033}/2 Minutes Later {imdb-tt0892033}.avi" size="734126080" openSubtitleHash="984c8c89827d1183" hash="78f6d4b11c856296ddf624b1eee47fe71110dfd7" duration="4094136">
<MediaStream id="419459" index="0" type="1" codec="mpeg4" bitDepth="8" chromaLocation="left" chromaSubsampling="4:2:0" codecID="XVID" codedHeight="352" codedWidth="624" frameRate="23.976" height="352" level="5" profile="advanced simple" refFrames="1" requiredBandwidths="2078,1622,1452,1349,1322,1322,1322,1322" width="624" />
<MediaStream id="419460" index="1" type="2" channels="2" codec="mp3" audioChannelLayout="stereo" requiredBandwidths="136,136,136,136,136,136,136,136" samplingRate="48000" streamIdentifier="1" />
</MediaPart>
</MediaItem>
</MetadataItem>
</MediaContainer>

Tested with both movies and episodes

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