@“MovieFan.Plex” Okay, I have progressed far by now, but still have two issues (which may be the same root cause):
1: My HASH value in the special metadata_items record for the collection is 64 chars (256 bits), whereas the HASH value for entries generated though the PMP is 40 chars (160 bits). Why? And how should I calculate the HASH in case it isn’t a SHA256 hash?
2: When I try to edit a collection that I have created (in the Collection view), I get “there was an error editing this item”). This could be because of the wrong HASH value, or perhaps I need to create “the disc folder where poster and background images for this item are stored.”? If so, where (in the directory structure) should I create it, and how should it be named (as far as I can see, there’s a split first on the first letter, and then subdirectories underneath that).
I can fix the collection problem easily enough (I can “enter” the collection, select all media therein, add a new collection to the items, go back to collection view, delete the faulty collection, enter the newly created collection, re-enter the correct collection name in all the items and then finally delete the newly created collection from the collection view) and the corrected collection is then editable. But doing so for 100+ collections is a bit of a chore 
Please help me get the final stretch - it’s so much easier doing batch updates this way 
1 - I’m not aware of a hash in PMP. Can you explain what you see? Since you are dealing with PMS, I’m not sure what the hash, where ever you see it in PMP, has anything to do with collections. The hash is just the sha256 of the guid. The directory structure is them the first letter then the remainder of the hash as the subdirectory.
2 - I haven’t tried recreating what you are doing so this is just advice based on my personal experience. There may be issues I’m not aware of. Remember, doing stuff directly to the database is not supported and may not work. I’m not aware of that error you are seeing, but it is very likely due to the wrong hash and Plex not being able to find the subsequent directory that is based on the hash.
@“MovieFan.Plex” said:
1 - I’m not aware of a hash in PMP. Can you explain what you see? Since you are dealing with PMS, I’m not sure what the hash, where ever you see it in PMP, has anything to do with collections. The hash is just the sha256 of the guid.
When I create the collection entry in metadata_items, I generate a GUID and prefix it with “collection://” and store it in the “guid” field, then calculate a SHA256 hash over it and store the value in the field “hash”. But when I see what other values are stored in the “hash” field in table metadata_items, it doesn’t look like a SHA256 value to me. Let’s take an example of two hashes- the first one is the one I created directly in the database, and the second one is the one I let PMP (Plex Media Player) create for me by using PMP to create a replacement collection:
1: aa1579175193b899b71b2031b22f046ecb4d024979107bdc53888587d9f9aafe
2: 78dd0b607f25c3b3225800fda0c7fc50947681d7
The first one (the one I manually created) is 64 chars, which equals 256 bits. The second one (the one created via PMP) is 40 chars, which equals 160 bits.
The directory structure is them the first letter then the remainder of the hash as the subdirectory.
Yes, but under which directory branch?
???<Hash1><HashRemainder>
What is the ??? part?
And do I need to create the directory myself, or can PMS (Plex Media Server) automatically create it when it needs it (if I get the hash generated correctly)?
@“MovieFan.Plex” :
Okay - from some experimentation, it seems like it isn’t a SHA256 but a SHA1 algorithm that is used (verified by comparing
a computed SHA1-hash of an exising record’s guid field to the stored hash value).
Also, I think I have determined the directory structure:
\Library\Application Support\Plex Media Server\Metadata\Collections<Hash1st><HashRemainder>.bundle (I’ll call this path “media path” in the rest of the message).
Underneath the media path, I have found an “Uploads” directory with two potential sub-directories (posters and art) which seem to contain the user-defined posters and backgrounds, respectively. The file names in these two directories are a hash (SHA-1 it would appear, as they are also 160 bits) without any extension. If I put a new file in there with a random hash number, it appears in the appropriate part when editing a movie. And the field “user_thumb_url” can then relate to the “active” one as in:
upload://posters/d6be8249df6447308dcf455306e1f61bb07a64ec
where the “posters/d6be8249df6447308dcf455306e1f61bb07a64ec” part then is added to the above media path.
However, I have been unable to find any place in the database that references these files and/or links them to the mediaitem. Is the mere presence of files in these sub-folders off the media path enough? If I (wrongly) have attached a poster to a mediaitem and want to remove it, is it simply enough to detect the proper file in the “poster” sub-directory and delete it (making sure, of course, that I don’t delete the one that is referenced in the “user_thumb_url” field).
@HeartWare42 said:
However, I have been unable to find any place in the database that references these files and/or links them to the mediaitem.
@“MovieFan.Plex” said:
I’m not clear what you mean by mediaitems.
Sorry - metadata_items. The posters etc. - are they linked (in the database) in some table to the metadata_items table (or other table), or is PMS merely scanning this directory when it needs to determine which images are available to select among?
@HeartWare42 said:
Is the mere presence of files in these sub-folders off the media path enough? If I (wrongly) have attached a poster to a mediaitem and want to remove it, is it simply enough to detect the proper file in the “poster” sub-directory and delete it (making sure, of course, that I don’t delete the one that is referenced in the “user_thumb_url” field).
@“MovieFan.Plex” said:
The files in here are the originals and what PMS will use to generate the thumbnails the clients show. You can technically delete these and it won’t affect any client that has already viewed the collection, but PMS won’t be able to generate new ones, so you may still see the thumbnail in Plex Web, if that is what you are using to check. But when you click edit, the poster/background won’t be there to let you select it again.
What I am (also) trying to accomplish is to remove the wrongly uploaded posters from a movie/TV show/collection (an option to do so from PMP or WebPlayer would be beneficial). They have never (or more correctly only for a very brief time) been the “default” poster for that item, and certainly no client have ever downloaded the wrong poster. So if I just remove the wrong file from the directory, it will disappear and I don’t need to adjust any table in the database to inform PMS that I have deleted one of the posters?
@HeartWare42 said:
What I am (also) trying to accomplish is to remove the wrongly uploaded posters from a movie/TV show/collection (an option to do so from PMP or WebPlayer would be beneficial). They have never (or more correctly only for a very brief time) been the “default” poster for that item, and certainly no client have ever downloaded the wrong poster. So if I just remove the wrong file from the directory, it will disappear and I don’t need to adjust any table in the database to inform PMS that I have deleted one of the posters?
There isn’t a way to unselect a poster right now.
It’s not just unselecting a poster - it’s deleting the file from the file system so that it can’t be selected. When I add new items to my database and edit them using PMP, I sometimes (when I search for appropriate posters on the net) forget to copy the newly found image URL into the clipboard, so that when I paste it into the new (2nd, 3rd, etc.) added item, I get the URL from the previous one instead. It’s not a problem per se, as I just go back to the browser and copy the correct URL and then use that in PMP to assign the poster. But then I have a poster on an item that has absolutely no relation to the movie/tv show and I would like to be able to remove the poster altogether. I am currently in the process of making a program that can allow you to browse the posters/banners/backgrounds of all the items in your database, and then you can delete any of them (as long as they are not referenced in one of the User_*_url fields) from the file system.
I am slowly figuring out how all the various prefixes (media:// upload:// metadata://) in the User_*_url fields should be interpreted, but am having some trouble figuring out how to collect all the images for a given metadata_item in the various groups (poster, banner, background). It’s fun to poke around in the database (only reading, since I only manipulate the file system when I delete an image file) and try to figure out how to get my program to show the same images as PMP 
Anything you can help me with in this area would be greatly appreciated (ie. given a specific metadata_item’s id, how do I collect all the images that PMP shows in the Poster/Banner/Background areas when editing a movie/show/episode?)
If you want a beta version of the program I am making, PM me, and I’ll send you a link. It’s in working order by now, but could use some filter functions in order to better be able to find what you’re looking for.
There is no way to delete a poster from the UI. This is a feature that has been asked for, but not by many. If you want to remove a poster, you will need to do it manually. The other prefixes relate to where the extra info is stored. Items automatically downloaded by an agent will be in “metadata” so has the prefix “metadata://”. “media” is for local content found next to the file. And “upload” are things found from online sources. Collections only use the “upload” folder since the other 2 do not apply in the case of collections. The URL fields only identify the chosen poster so for other media items, you will have to search all 3 locations to look for all potential posters.
I am trying to figure out the system of the various images (Poster/Background/Banner - Banner only for TV shows, it seems), and have run into a curious thing. I have a movie (not a collection - metadata_type = 1) with the following values (in table metadata_items):
user_thumb_url: upload://posters/5b57d369cbcf9a98561d146e35e5407bc1289f94
user_art_url: media://e/0729e052044c1e9fded4d865520cf970d1a1bf4.bundle/Contents/Art/art1.jpg
hash: d27221d8936708db28d6f8430ddc9cb1b7ae7a2a
The thumb one, I can figure out (I have “uploaded” it myself using my program and then selected it in PMP - I am still not writing directly to the database from this program). The art one I can’t figure out. Where does the hash value for this item come from?
Also - and this may be because of the local cache you have mentioned - PMP shows posters and/or backgrounds that I can’t locate in the expected folders. Currently, I scan the following folders:
Library\Application Support\Plex Media Server\Media\localhost<Hash>.bundle\Contents<Type>
Library\Application Support\Plex Media Server\Metadata<Kind><Hash>.bundle\Uploads<Type>
(where is the hash value from the metadata_item record split in 2 so that the 1st character denotes one directory level, and the remainder denotes a subdirectory underneath), is either “Movies”, “TV Shows” or “Collections” depending on the metadata_type value, and is either “Art”, “Posters” or “Banners” depending on what I want to display).
There is also a directory
K:\Library\Application Support\Plex Media Server\Metadata<Kind><Hash>.bundle\Contents
but that seems to only contain subdirectories that contain Info.xml files.
The reason that I can’t seem to “synchronize” what PMP and my program is showing may be the cache you have mentioned. Is there a way to clear the local cache of PMP so that it always asks for the latest values? Some directory on my local PC that I need to empty in order for it to re-request the latest updates I have done? Or some action I can do on the server (in PMP) that invalidates all caches in all clients?
@“MovieFan.Plex”
Forgot to mention you in the previous mail, so you probably didn’t get notified about a new message for you 
Just an update to the mediadata_type field mentioned above. It’s from my first steps to add music artist relations via script:
1 Movie
2 Show
3 Season
4 Episode
5 Trailer
6 Comic
7 Person
8 Artist
9 Album
10 Track
11 Picture
12 Clip
13 Photo
14 Photoalbum
15 Playlist
16 PlaylistFolder
18 Collection