INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: NEW: ItemCount(...) expression  (Read 1883 times)

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 41926
  • Shoes gone again!
NEW: ItemCount(...) expression
« on: September 24, 2019, 03:02:22 pm »

Coming soon to MC25 is a new expression function ItemCount(...).

It provides the count of whatever expression you put in as a parameter in the library.

So let's say you specify:
ItemCount(/[Album/])

You'll get the count of files in the album.

You can also use expressions like:
ItemCount(AlbumKey/(/))

That expression gets the count of files in the album (smart handling of duplicate album names, etc.)

This came from the requests in this thread:
https://yabb.jriver.com/interact/index.php/topic,122303.0.html

Originally we thought it might be too slow, but now we cache the results and rebuild the cache each minute (so a fresh import might not show for a minute).

Enjoy :)
Logged
Matt Ashland, JRiver Media Center

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: NEW: ItemCount(...) expression
« Reply #1 on: September 24, 2019, 11:54:29 pm »

Hmmm, these seem to require a different syntax to what I am used to, since you are including escape characters inside the function.

Okay, I read the thread discussing this. I havent' been drinking whiskey, but I still don't understand the nuance of why escape characters are required. After all, we use functions inside functions all the time in Expressions, such as the simple;

if(isequal([artist], bob dylan, 1), Genius, Mediocre)

The () for isequal don't need escaping. So why does Albumkey()?

I get what the escaping does, passing the literal "Albumkey()" to the ItemCount() function, but how is that different to the isequal()?

I assume that what you want to do is pass the literal, and not evaluate the function, or in the case of /[Album/] field first. But I'm not sure why.  ?

Sorry. I'm not really a programmer.  :o
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: NEW: ItemCount(...) expression
« Reply #2 on: September 25, 2019, 12:05:52 am »

Now I'm even more confused. No escape characters used in this example:

I'm wondering about:
ItemCount(AlbumKey() - [Disc #])


I'll test tomorrow and reply here.
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: NEW: ItemCount(...) expression
« Reply #3 on: September 25, 2019, 03:24:13 am »

this could be a highly interesting feature. 
Logged

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 41926
  • Shoes gone again!
Re: NEW: ItemCount(...) expression
« Reply #4 on: September 25, 2019, 07:52:42 am »

You need to escape because otherwise it just evaluates the value of AlbumKey() or whatever and replaces the text with the value.  Instead you need to pass that actual string like AlbumKey() to the function so it can use it.

Does that make sense?
Logged
Matt Ashland, JRiver Media Center

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: NEW: ItemCount(...) expression
« Reply #5 on: September 25, 2019, 08:40:19 am »

Yes, it does make sense, but I think I need to try it out to get it to sink in.

But then the "ItemCount(AlbumKey() - [Disc #])" example doesn't make sense, because "AlbumKey() - [Disc #]" would be evaluated before being passed. Maybe you meant to put escape characters in that example?
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

Matt

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 41926
  • Shoes gone again!
Re: NEW: ItemCount(...) expression
« Reply #6 on: September 25, 2019, 08:47:29 am »

But then the "ItemCount(AlbumKey() - [Disc #])" example doesn't make sense, because "AlbumKey() - [Disc #]" would be evaluated before being passed. Maybe you meant to put escape characters in that example?

Yes, they need to be escaped.  That was Matt typing at home on his phone!  Sorry!
Logged
Matt Ashland, JRiver Media Center

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 695
  • Hi
Re: NEW: ItemCount(...) expression
« Reply #7 on: September 25, 2019, 02:35:17 pm »

Thanks a lot for implementing this Matt.  I think this is going to be very useful.
Logged

ferday

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1732
Re: NEW: ItemCount(...) expression
« Reply #8 on: September 25, 2019, 06:01:40 pm »

i had written a global function to count tracks and auto populate # tracks

this works great, and much simpler - the syntax is wild though, the escape characters are in odd spots to me

nice one Matt, highly useful
Logged

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 695
  • Hi
Re: NEW: ItemCount(...) expression
« Reply #9 on: September 25, 2019, 09:19:36 pm »

Matt, I am trying to do what I think would be a simple task but I am not having any luck.  I'd like to find how many seasons of a show I have.  I was hoping that something like

Code: [Select]
ItemCount(/[series/]/[season/])
Would do it, but that just returns how many episodes I have for that show. I understand why it's doing that, but it's not the behavior I was hoping for.   To find the number of episodes I would have thought it would be something like

Code: [Select]
ItemCount(/[series/]/[episode/])
Which also does return the number of episodes.

So, I have a request.  Would it be possible to add a mode to this function?  Something like mode 0, count all files that match the given values.  Mode 1, count all unique values that match the given values.

So, if I have a show that has two seasons, each season has 10 episodes

Code: [Select]
ItemCount(/[series/]/[season/],0)Would return 20

Code: [Select]
ItemCount(/[series/]/[season/],1)Would return 2
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: NEW: ItemCount(...) expression
« Reply #10 on: September 25, 2019, 09:34:13 pm »

You need to escape each control character Moe, not the function name. So try;

ItemCount(/[series/]/[season/])
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 695
  • Hi
Re: NEW: ItemCount(...) expression
« Reply #11 on: September 25, 2019, 09:41:06 pm »

You need to escape each control character Moe, not the function name. So try;

ItemCount(/[series/]/[season/])

I have, that was just me making a mistake on the forum, not in MC.  I edited the post, thanks.
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: NEW: ItemCount(...) expression
« Reply #12 on: September 25, 2019, 10:13:12 pm »

Nope. Still wrong in the post above.
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 695
  • Hi
Re: NEW: ItemCount(...) expression
« Reply #13 on: September 25, 2019, 10:17:19 pm »

Sigh... long day.

It was correct in MC. I got it working for other things.  Fixing it now.
Logged

RoderickGI

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 8186
Re: NEW: ItemCount(...) expression
« Reply #14 on: September 25, 2019, 10:58:47 pm »

I've just tested this a bit using custom columns in the standard Shows View, and re-read Matt's first post, and the original thread. Now I understand your request Moe. What Matt has built doesn't really meet the original request.

I was also expecting ItemCount(/[series/]/[season/]) to return the number of unique combinations of Series and Season, which would give the number of Seasons, regardless of the number of Episodes. But Matt's original description specifically says the function counts files, not unique combinations.

So I support you request for a count of the unique combinations of the values passed to ItemCount().
Logged
What specific version of MC you are running:MC27.0.27 @ Oct 27, 2020 and updating regularly Jim!                        MC Release Notes: https://wiki.jriver.com/index.php/Release_Notes
What OS(s) and Version you are running:     Windows 10 Pro 64bit Version 2004 (OS Build 19041.572).
The JRMark score of the PC with an issue:    JRMark (version 26.0.52 64 bit): 3419
Important relevant info about your environment:     
  Using the HTPC as a MC Server & a Workstation as a MC Client plus some DLNA clients.
  Running JRiver for Android, JRemote2, Gizmo, & MO 4Media on a Sony Xperia XZ Premium Android 9.
  Playing video out to a Sony 65" TV connected via HDMI, playing digital audio out via motherboard sound card, PCIe TV tuner

Hendrik

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 10710
Re: NEW: ItemCount(...) expression
« Reply #15 on: September 26, 2019, 01:38:53 am »

ItemCount counts the number of files that have the exact same value of the given expression as the file the expression runs in the context of.
Which means it can do things like counting the number of files that belong to the same album as a file you are looking at, or to the same show, or to the same season.

But it can't count the number of seasons, or the number of discs belonging to an album, because it just doesn't know what value you might want. A simple mode doesn't help here. You would have to pass several values, a search expression, a comparison expression, etc. It gets rather unwieldy, and the performance issue might come back.

This is not a relational database, every such operation we do has to literally look at every file, evaluate the expression you specified for it, and then compare the values. This is not fast.
Logged
~ nevcairiel
~ Author of LAV Filters
Pages: [1]   Go Up