INTERACT FORUM

Please login or register.

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

Author Topic: Tagging Series for Video Files Automatically  (Read 628 times)

e-head

  • World Citizen
  • ***
  • Posts: 121
Tagging Series for Video Files Automatically
« on: March 24, 2021, 01:45:25 pm »

Hi,
I have an old version of MC with a scripting plugin installed. I wrote a little .NET script that automatically applies the folder name to the series tag for video files. In other words, I have my videos sorted like this:

z:\videos\Planet Earth\video_files_here.mkv
z:\videos\Storyville\more_files.mkv

This script would go through my library and tag all files under "Planet Earth" with "Planet Earth" as the Series.

I was just wondering if was some other way to do this that is fairly painless (by painless I mean I don't want to have to do this for every folder)? I want to upgrade and it looks like this old scripting plugin hasn't been changed in forever, and it also doesn't have a 64 bit version.

Thanks
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Tagging Series for Video Files Automatically
« Reply #1 on: March 24, 2021, 02:25:04 pm »

You can select the files you want and set the Series tag to:
=ListItem([filename (path)],-1,\)
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Tagging Series for Video Files Automatically
« Reply #2 on: March 24, 2021, 03:10:53 pm »

Actually, no he can't, because he doesn't have the build that allows the -1 index for ListItem.  :)

Until the .75 release is made public, e-head will have to use the much uglier:

Code: [Select]
ListItem([Filename (path)],Math(Listcount([Filename (path)],\) - 1),\)
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Tagging Series for Video Files Automatically
« Reply #3 on: March 24, 2021, 05:01:03 pm »

Right :)

It's actually
Code: [Select]
=ListItem([Filename (path)],Math(ListCount([Filename (path)]) - 2),\)
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Tagging Series for Video Files Automatically
« Reply #4 on: March 24, 2021, 05:22:54 pm »

It's actually
Code: [Select]
=ListItem([Filename (path)],Math(ListCount([Filename (path)]) - 2),\)

Is it?  You'd better test.   ;)

He wants the last element in [Filename (path)].  So it's -1 not -2.

ListItem uses a 0 based index.  ListCount is (unfortunately) non-zero based.

So in a 4-element list, ListCount returns 4 (as in 1,2,3,4).  But ListItem identifies them as 0,1,2,3.

Therefore the last item in a list, as retrieved by ListItem, is always ListCount-1.

Perhaps you were thinking of [Filename] which includes the actual filename as the last element, so if you used [Filename] the element he wants would indeed be ListCount-2.  But [Filename (path)] doesn't include the filename. The last element is the directory the file is located in, which is what he wants.  And these examples are using [Filename (path)], so my example, and -1, is correct.  You had it right in your original example, except he couldn't use the unreleased feature.
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Tagging Series for Video Files Automatically
« Reply #5 on: March 24, 2021, 05:39:03 pm »

I did test with Zelda. [Filename (Path)] ends with a slash, so it works with -2.

Also, you had a wrong parenthesis.
Logged

wer

  • Citizen of the Universe
  • *****
  • Posts: 2640
Re: Tagging Series for Video Files Automatically
« Reply #6 on: March 24, 2021, 06:25:49 pm »

This is funny, because we're both wrong.

My expression did have a typo.  I've corrected it.

The correct version is here:
Code: [Select]
=ListItem([Filename (path)],Math(Listcount([Filename (path)],\) - 1),\)
Your expression is wrong, but accidentally evaluates to give the desired answer, but only in the beta version of MC27. In any released version, your expression returns nothing.

It's actually
Code: [Select]
=ListItem([Filename (path)],Math(ListCount([Filename (path)]) - 2),\)


The problem with what you posted is that ListCount([Filename (path)]) - 2)  returns -1 not because it's correct, but because you didn't specify the delimiter of the list in ListCount. Your ListCount() will always return 1 (at least if there are no ; in the path) no matter how long the [Filename (path)] is because you're not separating elements by \.  So it always returns 1, from which you subtract -2, which leaves you with -1.

Your expression still evaluates ok for you, because you are running the latest beta, and you are passing ListItem -1 as the index.  If you'd tested on a release version, you'd have seen the expression doesn't work, because -1 is an invalid index. But you're supposed to be passing the actual positive index number of the last item in the list, which is all the OP can use, since he doesn't have that feature in his release.

So like I said before, to use ListItem to retrieve the last item in the list, the correct answer is always ListCount-1, and never ListCount-2.

So e-head, use this:

Code: [Select]
ListItem([Filename (path)],Math(Listcount([Filename (path)],\) - 1),\)
It works in all versions of MC, including yours.




Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Tagging Series for Video Files Automatically
« Reply #7 on: March 24, 2021, 06:28:51 pm »

Nice debugging, Wer :)
Logged

e-head

  • World Citizen
  • ***
  • Posts: 121
Re: Tagging Series for Video Files Automatically
« Reply #8 on: March 25, 2021, 08:13:55 am »

Thanks everybody! All of this got me headed in the right direction. It looks like the below worked for both setting Genre (../../ folder) and for series (../ folder):

Put this in the series field: =filefolder()
Put this in the genre field: =filefolder([filename,0], 1)

I now have this set up in my auto import rules. Even easier than the old plugin (Mr. Chin's ?? can't remember it's name).
Logged

zybex

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2619
Re: Tagging Series for Video Files Automatically
« Reply #9 on: March 25, 2021, 11:46:24 am »

Eh, I had completely forgotten about that function. Good going eHead :)
Logged
Pages: [1]   Go Up