Jump to content

Automated Tagging


Steve86

Recommended Posts

3 minutes ago, chef said:

So both those baseItems represent two different resolutions?

 

In this case yes. One is a DVD rip, the other a BluRay rip.

Edit:

You can see a bit of the details for them in this post:

 

Edited by roaku
  • Like 1
Link to comment
Share on other sites

Just now, roaku said:

In this case yes. One is a DVD rip, the other a BluRay rip.

Okay, just have to figure that out on the backend, and we can give it a go.

Link to comment
Share on other sites

13 minutes ago, chef said:

Okay, just have to figure that out on the backend, and we can give it a go.

You should l be able to take the resolution logic bakes provided in the below link, but just substitute BaseItem.GetMediaStreams() and some code to iterate/stream through those to grab the one with Type 'Video'...or 'Audio' or whatever else the current rule needs to check.

But tweaked like so:

//pseudo-code to find the MediaStream you care about
MediaStream videoStream = baseItem.GetMediaStreams().FilterOrIterateToFindByTypeVideo();


var is4K = videoStream.Height <= 2160 &&
videoStream.Width <= 4096 &&
videoStream.Height > 1080 &&
videoStream.Width > 1920;
 
if (!is4K) is4K = videoStream.DisplayTitle.ToLower().Contains("4k"); 


 

Edited by roaku
Link to comment
Share on other sites

14 hours ago, bakes82 said:

Do all Sources/Streams only point to 1 base item?  Thus if you add a 4k tag will it block the entire item from being shown or just the 1 stream?

They don't "point" to anything.  They are subsets of an item.

Link to comment
Share on other sites

14 hours ago, roaku said:

So, the problem with this approach is that each movie version will potentially match different rules and therefore need different tags. If this isn't accommodated, Users who shouldn't have access to MovieVersion B might be able to see it because Movie Version C matched a rule and so the plugin added the tag to the 'primary' Item, which is Movie Version A. Or vice versa. That problem is documented here.

The alternative approach we're trying now is to query for the items *without a User*. This query returns all the Items ungrouped by their version as full fledged BaseItems.

This way, we can trust BaseItem.GetMediaStreams() to have all the MediaStreams we care about *for that version*. We don't need to use GetMediaSources() this way (although, the plugin might need to look at GetMediaSources() for other reasons, and its data is equally trustworthy with this approach).

We also now have direct access to the BaseItem we need to update the tags for. And Emby tag white listing will already behave properly if each version's tags are different.

The logical organization is how I laid it out.  There is no facility to filter out different media sources in the UI so what you are attempting above is not likely to do what you want.

Link to comment
Share on other sites

16 hours ago, ebr said:

I apologize that I did not read all the updates here but, in case you haven't figured it out yet, the logical layout is:

BaseItem -> can contain one or more MediaSources -> which can then contain multiple MediaStreams.

And the tag is a property of the BaseItem as a whole.

So, to satisfy conditions, you would need to query all the media streams on each of the media sources for any particular base item and then add the tag to the base item if the condition was met by the underlying streams.

 

The original request wanted  the ability to block their users from accessing one source (example 4k source) by tagging the baseItem.  Which doesn't sound possible to do by tagging the baseItem. 

However, we can still build the auto tag plugin, it will handle auto tagging in a general sense. 

Probably should remove the resolution option from the configuration. 

  • Like 1
Link to comment
Share on other sites

3 hours ago, ebr said:

The logical organization is how I laid it out.  There is no facility to filter out different media sources in the UI so what you are attempting above is not likely to do what you want.

It works exactly how I've been describing.

In fact, blacklisting and whitelisting will not work properly *unless* you bypass the version groupings to tag the separated base items, as shown in the link I included.

If you only tag the primary item in a group with a blacklist ban, the alternate versions will still show up in the User's ui. This is considered correct behavior, with the announced fix being to enhance the Metadata Manager to support tagging alternate versions.

Right now, you can work around it by  modifying each movie file's nfo file and rescanning or separating each version into its own movie, modifying the Metadata as needed, then regrouping.

And here's confirmation that all movies can be retrieved independently from their grouping, both through the REST API and native C# querying.

 

I've seen how Movie Version B still appears in the UI if only Movie Version A gets a blacklist tag or ratings block in my own library.

I've worked around this defined and documented behavior in my own library.

What, precisely, are you saying isn't going to 'work like I want'?

 

Now, if we put tag based blacklisting/whitelisting and any other system features that behave like it aside, then yes, generic tags only *need* to be applied to the primary item...right now...but the Metadata Manager is eventually going to be updated to support multi-version tagging and other metadata. This auto tagging plugin will need to be updated then, anyway. There's no downside to supporting version tagging now, and it avoids the whitelist/blacklisting problem that exists right now.

 

Edited by roaku
Link to comment
Share on other sites

36 minutes ago, chef said:

 

The original request wanted  the ability to block their users from accessing one source (example 4k source) by tagging the baseItem.  Which doesn't sound possible to do by tagging the baseItem. 

However, we can still build the auto tag plugin, it will handle auto tagging in a general sense. 

Probably should remove the resolution option from the configuration. 

It works exactly how I described. What issue are you having?

Link to comment
Share on other sites

Just now, roaku said:

It works exactly how I described. What issue are you having?

I've just got  a 4k version of a movie I already had 1080p version of. I'm going to add it to my library and attempt this. I am not lucky enough to have any 4k devices, so I don't have multiple versions of media. I'll set up the library item and attempt the query and iterations nesessary to figure this out 👍

Link to comment
Share on other sites

1 minute ago, chef said:

I've just got  a 4k version of a movie I already had 1080p version of. I'm going to add it to my library and attempt this. I am not lucky enough to have any 4k devices, so I don't have multiple versions of media. I'll set up the library item and attempt the query and iterations nesessary to figure this out 👍

Cool. I'd recommend reviewing this thread if you haven't to see the specific behavior for whitelisting/blacklisting I'm talking about.

It goes into detail about what's happening and why, and confirms that applying tags directly to the version(s) that matches is the correct approach, just for tagging period. Nothing to do with a plugin.

 

Link to comment
Share on other sites

21 hours ago, bakes82 said:

@chef Does this work?


var mediaItems =
                    libraryManager.GetItemList(
                            new InternalItemsQuery
                            {
                                IncludeItemTypes = new[] {nameof(Movie)},
                                IsVirtualItem = false,
                                OrderBy = new[]
                                {
                                    new ValueTuple<string, SortOrder>(ItemSortBy.SeriesSortName, SortOrder.Ascending),
                                    new ValueTuple<string, SortOrder>(ItemSortBy.SortName, SortOrder.Ascending)
                                }
                            })
                        .ToList();
                
                mediaItems.First().GetMediaSources().First().Id

 

I'm checking this now @bakes82

 

Link to comment
Share on other sites

@chef

Just remember that you don't need that last line where it's using GetMediaSources and trying to find an Id on one.

Just verify that the count of 'mediaItems' is bigger than when you query with a user (or look at the count through a client app).

I'm assuming that you have at least one multi-versioned movie at this point.

Edited by roaku
  • Like 1
Link to comment
Share on other sites

Just want to make sure I'm on the right path :)

The query parameters are able to narrow results based on most of our rule parameters.

Note:  it would seem that, eventually, we can add the ability to have more then one rule profile parameter to narrow results further. For example, instead of look at one parental Rating, the rule could eventually have multiple. This would help create a broader auto-tagging system.

                var itemQuery = LibraryManager.QueryItems(new InternalItemsQuery()
                {
                    Recursive        = true,
                    IncludeItemTypes = new[] { rule.Profile.Type },
                    User             = UserManager.Users.FirstOrDefault(user => user.Policy.IsAdministrator),
                    AudioCodecs      = new []{ rule.Profile.AudioCodec ?? "" },
                    Containers       = new []{ rule.Profile.Container ?? "" },
                    OfficialRatings  = new []{ rule.Profile.Rating ?? "" },
                    VideoCodecs      = new []{ rule.Profile.VideoCodec ?? "" }
                });

 

Now we look at specific resolutions (I'm going o call it "resolution" to simplify things: 1080p, 720p, 4K etc.)

 

This is nothing more then testing out code to find a 4k source.

                Parallel.ForEach(itemQuery.Items,new ParallelOptions() { MaxDegreeOfParallelism = 4}, (item, state) =>
                {
                    var sources = item.GetMediaSources(true, true, new LibraryOptions());
                    
                    var source4K = sources.Where(s =>
                        s.VideoStream.Height <= 2160 && s.VideoStream.Width <= 4096 && s.VideoStream.Height > 1080 &&
                        s.VideoStream.Width > 1920);     
                                        
                });

 

A "source4k" is found, and we get an "Id"  for the source. This is different then a baseItem.InternalId (which is fine).

What I need to figure out is the condition which takes in the "rule.Profile.Resolution" (which currently can be one of the following:  2160p, 1080p, 720p)

and finds the MediaSource.

 

Can we figure this out by only looking at the VideoSource.Height?

 

If  s.VideoStream.Height is between 2160 and 1080 => 2160p

if  s.VideoStream.Height is between 720 and 1080 => 1080p

if  s.VideoStream.Height is less then or equal to 720 => 720p

 

I realize there are resolutions below 720p, but for now.... .... are these fair assumptions?

 

Thoughts? 

It's taking me a minute to catch up on what in the world is happening. LOL.

Edited by chef
Link to comment
Share on other sites

@chef

Are you trying my approach here or someone else's? Because there are some things to change/behavior to verify if it's supposed to be mine. :)

Edited by roaku
Link to comment
Share on other sites

54 minutes ago, roaku said:

@chef

Are you trying my approach here or someone else's? Because there are some things to change/behavior to verify if it's supposed to be mine. :)

Okay, let's try your approach. 

My apologies, my father in-law died, so I've had the kids alone for the past day... Im definitely not following exactly what to do. 

Link to comment
Share on other sites

I have two versions of a movie now. One is 4K the other 1080p. In my library there are two entries. 

How do I create one entry with two sources?

2versions.thumb.png.4fb0ee639b0376117160d08af4412d1d.png

Link to comment
Share on other sites

I'm sorry to hear that.

 

So, I saw that you still have a User in your query, just moved to a different part of the object instantiation. Have you verified that you're getting the movies ungrouped by version this way? I think you'll probably need to remove the User altogether.

 

Once you know your movies are coming back ungrouped, you'll have a 'one to one' relationship between a BaseItem and a  version.

So, you can do this to figure out the resolution (adapted from bakes logic):

//pseudo-code to find the MediaStream you care about
MediaStream videoStream = baseItem.GetMediaStreams().FilterOrIterateToFindByTypeVideo();


var is4K = videoStream.Height <= 2160 &&
videoStream.Width <= 4096 &&
videoStream.Height > 1080 &&
videoStream.Width > 1920;
 
if (!is4K) is4K = videoStream.DisplayTitle.ToLower().Contains("4k"); 

If is4k is true for your current BaseItem, you can just update the tags for that BaseItem as needed.

You should be able to test for any other MediaStream property in a similar way.

  • Thanks 1
Link to comment
Share on other sites

3 minutes ago, chef said:

I have two versions of a movie now. One is 4K the other 1080p. In my library there are two entries. 

How do I create one entry with two sources?

2versions.thumb.png.4fb0ee639b0376117160d08af4412d1d.png

Put them in the same movie folder and rename each file so that you have '{Movie Name} (YYYY) - {The Version Name}.ext'

Emby will take the part after the dash as the name for that version.

Edited by roaku
  • Thanks 1
Link to comment
Share on other sites

bakes82

You can use the auto grouping plugin and not deal with the Emby naming convention also, its what I do, way better.  Or just merge them manually.

Link to comment
Share on other sites

12 minutes ago, bakes82 said:

You can use the auto grouping plugin and not deal with the Emby naming convention also, its what I do, way better.  Or just merge them manually.

He's just trying to create a test case man.

  • Like 1
Link to comment
Share on other sites

22 hours ago, roaku said:

What, precisely, are you saying isn't going to 'work like I want'?

I said it wasn't likely to work.  What you are doing is leveraging some undocumented behaviors of an internal implementation.  The process is a bit convoluted and could stop working at any time since it isn't how we are logically viewing the items at this point.  Proceed at your own risk :).

  • Like 1
Link to comment
Share on other sites

I understand that we are treading new territory here, and I completely understand what eric is getting at.

 

but I thought I'd mention that these versions (1080p and 4K) have different InternalIds.

result1.png.df6c8c4429700633889d18d4711a9d93.png

result2.png.b76bf70a38c30c3567d5f34301791818.png

 

As long as items have different InternalIds, we can tag them.

 

 

Now that I have wrapped my head around the MediaStreams 'thing' (sorry it took so long....), I should at least attempt to tag and limit access (using tags) to a 4K item in a user Library. Just to at least try it. 

 

 

Edited by chef
Link to comment
Share on other sites

2 hours ago, ebr said:

I said it wasn't likely to work.  What you are doing is leveraging some undocumented behaviors of an internal implementation.  The process is a bit convoluted and could stop working at any time since it isn't how we are logically viewing the items at this point.  Proceed at your own risk :).

I linked to several threads where every aspect of this approach is declared to be correct and expected behavior by Luke. Well, the no-user query was described as 'sort of intentional' anyway.

Without this approach it *is impossible* to properly implement a whitelist/blacklist (tagging or rating/custom rating) for any user who groups their items as versions. I've linked to explanations and feature requests for this issue as well. The response there is that the problem will be solved by enhancing the Metadata Manager to allow users access to the ungrouped items...like we're doing now.

So, the two options I see are do it this way now and update the plugin if sometime in the future the architecture is modified or give up.

Do you see a third option? Because I'm only advocating this one because it exists.

Edited by roaku
Link to comment
Share on other sites

Sorry if I sound frustrated, but I've asked for changes in this space months ago and was told by one powerful Emby overlord that everything is the way it is on purpose and isn't going to change. There's only going to be future development to *further* entrench this item structure.

Now I'm being told by another powerful Emby overlord that it's all just dust in the wind. How can we hope to develop against it? :)

Link to comment
Share on other sites

bakes82
2 minutes ago, roaku said:

I linked to several threads where every aspect of this approach is declared to be correct and expected behavior by Luke.

Without this approach it *is impossible* to properly implement a whitelist/blacklist (tagging or rating) for any user who groups their items as versions.

So, the two options I see are do it this way now and update the plugin if sometime in the future the architecture is modified or give up.

Do you see a third option? Because I'm only advocating this one because it exists.

I can tell you if you put 4k in a new library and use the auto merge plugin and dont share the 4k library this approach works.  @ebrdo you guys plan to drop the multi unique ids because from a DB point it seems odd to repeat the data multi times instead of just having a junction table between the meta data ref/source

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...