CC snippet - Video length

Discuss and share scripts and script files...
highend
Posts: 8376
Joined: 06 Feb 2011 00:33

CC snippet - Video length

Post by highend » 22 Mar 2018 12:05

How to set up a custom column with a snippet: viewtopic.php?f=7&t=18653

This one displays the length of all video files in a folder in a custom column.

It uses:
a.) System installed codecs (very fast)
A codec package helps in this case, e.g. the K-Lite Codec Pack
http://www.codecguide.com/download_kl.htm
The basic package should work just fine

or if a codec for a specific video format isn't installed
b.) MediaInfo: https://mediaarea.net/en/MediaInfo/Download/Windows
You need the CLI version of it!

Necessary changes inside the snippet:

Code: Select all

$mediaInfo = "<xydrive>\Tools\@Command Line Tools\MediaInfo\MediaInfo.exe";
Adapt the path!

The snippet code:

Code: Select all

Snip: CustomColumn 1
  XYplorer 18.90.0000, 22.03.2018 09:46:17
Action
  ConfigureColumn
Caption
  Video length
Type
  3
Definition
  
      $nsecs = property("System.Media.Duration", <cc_item>);
  
      // Use mediainfo for unknown codecs ($nsecs is empty!)
      if ($nsecs == "") {
          $mediaInfo = "<xydrive>\Tools\@Command Line Tools\MediaInfo\MediaInfo.exe";
          $length = regexreplace(runret("$mediaInfo --Inform=General;%Duration/String3% ""<cc_item>"""), "\.\d*\r?\n");
          return $length;
  
      // Use system properties for known codecs
      } else {
          // To get real seconds from nanoseconds, multiply the value with 0.0000001
          $secs = round($nsecs * 0.0000001);
  
          // Calculate length
          // Do we have a playtime in hours?
          $hours = $secs / 3600;
          if ($hours >= 1) {
              $hours = format(regexmatches($hours, "^\d+"), "00");
              $secs  = $secs - $hours * 3600;
          } else { $hours = "00"; }
          // Playtime only in minutes
          $mins = $secs / 60;
          if ($mins >= 1) {
              $mins = format(regexmatches($mins, "^\d+"), "00");
              $secs = $secs - $mins * 60;
          } else { $mins = "00"; }
          // -> Playtime is only seconds
          // Nothing to calculate here any more
          return $hours . ":" . $mins . ":" . format($secs, "00");
      }
Format
  0
Trigger
  1
Item Type
  0
Item Filter
  {:Video}

It looks like this:
cc_setup.png
cc_setup.png (12.42 KiB) Viewed 1132 times
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

xyramzi
Posts: 4
Joined: 21 Mar 2018 17:17

Re: CC snippet - Video length

Post by xyramzi » 24 Mar 2018 18:47

I really appreciate your effort but there are two problems here:

1. I have no idea how to do the suggested cure.

2. It existed in a previous instalments with no script or snippet. It was either in Configuration or Customise Columns. Since the new installation, I can't find it.

Still trying,
Ramzi

highend
Posts: 8376
Joined: 06 Feb 2011 00:33

Re: CC snippet - Video length

Post by highend » 24 Mar 2018 18:56

1. I have no idea how to do the suggested cure
What cure?
2. It existed in a previous instalments with no script or snippet
It exists when you choose the property for a column (right click the columns caption).
Iirc it's called length, duration or playtime
But this will only work for items that have a codec installed...
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

xyramzi
Posts: 4
Joined: 21 Mar 2018 17:17

Re: CC snippet - Video length

Post by xyramzi » 06 Apr 2018 16:28

Thank you. I'll try what you recommended and hope I can do it.

G_Mugford
Posts: 12
Joined: 22 Feb 2015 23:32

Re: CC snippet - Video length

Post by G_Mugford » 28 Feb 2019 00:05

Highend,

Newbie here ... I had Video Length showing up in my various file managers up to about two years ago. I run Win 7 Pro x64. Then, the info went away for anything not AVI or SOME MP4s. I use K-Lite Mega Code Pack and keep it current. I've half-heartedly tried to restore the information, but the videos play. And when they boot up, I know how long my enjoyment will last. Nothing dire. But I happened across the thread here and thought I would give it a shot as it pertains to XYplorer. I installed mediaInfo.exe GUI and tested it and it worked as I hoped it would. It showed the running length of the MKVs, MOVs and MP4s that had been recalcitrant. One by one. So, I moved forward with setting up an undefined column as indicated above. I downloaded the CLI version and unzipped it to a folder underneath where I'd installed the GUI version. I then edited the script above to include the full path command to the CLI's mediaInfo.exe. Saved everything and it all came up zeroes, AVIs included. I tried encapsulating the path in quotation marks and double quotation marks, even though there were no spaces in the pathname (I'm a bit ... obsessive/compulsive about NOT installing into the program files hive NOR having spaces in path or file names). Still, nothing. At this point, the sage advice to await Windows 10's inevitable installation when 7 reaches end of life next summer seems the best bet.

Or do you have another option?

Thanks in advance, GM

jupe
Posts: 1244
Joined: 20 Oct 2017 21:14
Location: 1909 x64

Re: CC snippet - Video length

Post by jupe » 28 Feb 2019 01:29

It sounds like you have a problem with K-Lite (XY needs x86 version), I recommend removing and a new fresh install (playback and shell properties are different components so because playback works in WMP that means nothing), but if you are after a quick easy fix just to get this column working with XY via Mediainfo you should just be able to change the top line (of the definition) to this $nsecs = ""; if, as you say you've already set the path correctly.

edit: oops sorry just noticed your question wasn't directed at me...

G_Mugford
Posts: 12
Joined: 22 Feb 2015 23:32

Re: CC snippet - Video length

Post by G_Mugford » 28 Feb 2019 10:26

Jupe,

No issue with your replying to my query. It's a forum and the advantage of a forum is the ability for all to help where they can. Thanks for taking your time to offer some help.

I tried the edit change hoping it would suffice. It didn't. But the x86 install might be productive. I'm trying to think when I started with the x64 install of K-Lite. It might very well be about the time things info-wise with MKVs went south. So, certainly worth a try. I'll report back.

GM

G_Mugford
Posts: 12
Joined: 22 Feb 2015 23:32

Re: CC snippet - Video length

Post by G_Mugford » 28 Feb 2019 10:40

Hmmm, it seems a 32 bit install of K-Lite (I looked at the whole suite of versions) is a non-starter. The installer comes as dual 32/64 bit and picks the version according to the operating system. So, the next step is to search around for an older version that specifically states x32. Maybe a portable version? I've found a couple.

There's maybe some good that comes from a total uninstall and then re-install of the various video play programs. I've always kept WMC as my main default choice, with a fallback to Portable VLC where needed (and I use it for music files).

The game's afoot.

Thanks, GM

highend
Posts: 8376
Joined: 06 Feb 2011 00:33

Re: CC snippet - Video length

Post by highend » 28 Feb 2019 10:45

Em, what?

http://files2.codecguide.com/K-Lite_Cod ... 5_Mega.exe

This automatically installs 32 and 64-bit codecs (on a 64-bit OS), unless you
tell it specifically to leave out 32-bit ones...
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

jupe
Posts: 1244
Joined: 20 Oct 2017 21:14
Location: 1909 x64

Re: CC snippet - Video length

Post by jupe » 28 Feb 2019 10:59

Umm, not to interject (again) :oops: but I don't see how this can fail:
jupe wrote:
28 Feb 2019 01:29
if you are after a quick easy fix just to get this column working with XY via Mediainfo you should just be able to change the top line (of the definition) to this $nsecs = ""; if, as you say you've already set the path correctly.
what I meant by this is, replace this $nsecs = property("System.Media.Duration", <cc_item>); with this: $nsecs = "";, is that what you did? I am unsure how this could fail :?: Did you right click the column header and select "Configure Custom Column #??" and there make the changes? if not?, just try this (as a quick and dirty fix), edit the column definition (as described above) to be just this:

Code: Select all

          $mediaInfo = "c:\the\correct\path\to\MediaInfo\CLi\MediaInfo.exe";
          $length = regexreplace(runret("$mediaInfo --Inform=General;%Duration/String3% ""<cc_item>"""), "\.\d*\r?\n");
          return $length;
edit: BTW K-Lite has no impact on VLC, so if you have it installed or not VLC will still function the same...

G_Mugford
Posts: 12
Joined: 22 Feb 2015 23:32

Re: CC snippet - Video length

Post by G_Mugford » 28 Feb 2019 11:59

Sadly,

Even after finding a Standard version of 12.95 portable that installed in the x86 program files hive on C: (I NEVER voluntarily install programs into the hive if at all possible, but I was trying to get as pure a 32-bit install as possible), the Video Length column in XYplorer remained all zeros, even the entry for an AVI file of an old Lone Ranger TV episode was 00:00:00.

Well, I'm going to call the experiment a failure, despite the generous help of others. I'll uninstall (by the way, uninstalling through Revo Uninstaller found LOTS of detritus when I uninstalled the 14.75 version. A LOT of detritus) and re-install the latest x64 version. Turns out, I'll just have to await Win10 looming so ominously in the background. Even seems like I hear the theme to Jaws. Sigh.

Thanks all, GM

highend
Posts: 8376
Joined: 06 Feb 2011 00:33

Re: CC snippet - Video length

Post by highend » 28 Feb 2019 12:05

even the entry for an AVI file of an old Lone Ranger TV episode was 00:00:00.
Select that file, execute this from the address bar and post the output:
text "_" . property("System.Media.Duration", <curitem>) . "_";
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

G_Mugford
Posts: 12
Joined: 22 Feb 2015 23:32

Re: CC snippet - Video length

Post by G_Mugford » 28 Feb 2019 12:13

Cross-posted as I progressed, so I missed Jupe's response. And once again, I'm happy for your involvement. So thanks for the time. My script did not change during the K-Lite maneuvering. The script with the actual path and your edit is shown here:

Code: Select all

Snip: CustomColumn 1
  XYplorer 18.90.0000, 22.03.2018 09:46:17
Action
  ConfigureColumn
Caption
  Video length
Type
  3
Definition
  
      //$nsecs = property("System.Media.Duration", <cc_item>);
      $nsecs = "";  // suggested by Jupe
  
      // Use mediainfo for unknown codecs ($nsecs is empty!)
      if ($nsecs == "") {
          $mediaInfo = "<xydrive>\Tools\@Command Line E:\apps\media\mediaInfo\CLI\MediaInfo.exe";
          $length = regexreplace(runret("$mediaInfo --Inform=General;%Duration/String3% ""<cc_item>"""), "\.\d*\r?\n");
          return $length;
  
      // Use system properties for known codecs
      } else {
          // To get real seconds from nanoseconds, multiply the value with 0.0000001
          $secs = round($nsecs * 0.0000001);
  
          // Calculate length
          // Do we have a playtime in hours?
          $hours = $secs / 3600;
          if ($hours >= 1) {
              $hours = format(regexmatches($hours, "^\d+"), "00");
              $secs  = $secs - $hours * 3600;
          } else { $hours = "00"; }
          // Playtime only in minutes
          $mins = $secs / 60;
          if ($mins >= 1) {
              $mins = format(regexmatches($mins, "^\d+"), "00");
              $secs = $secs - $mins * 60;
          } else { $mins = "00"; }
          // -> Playtime is only seconds
          // Nothing to calculate here any more
          return $hours . ":" . $mins . ":" . format($secs, "00");
      }
Format
  0
Trigger
  1
Item Type
  0
Item Filter
  {:Video}
I had changed the caption to Video Length, picked format Text, Trigger List and Item Type Files. The Item filter was {:Video}

To the best of my knowledge, I did what was asked. It just didn't work. Things like that happen. The computer crashed hard two weeks ago and 32 generations of C drive backup turned up with bad boot manager recovery. So, a return to a disk image from a different backup program when I switched install SSD's back in October got me back functional and I spent a week updating back to where I was. Things happen and this computer is running an out of date operating system that I refuse to budge from because I truly hate Windows 10's smother Mommy complex. And it's nasty habit of not running software I've written In Delphi using Paradox databases.

So, rather than extend this thread, I'm going to submit to Karma or whatever is deciding on how things work on this old box. Thanks for stepping in. It was worth the try, but the mix of things on the box is just not working with this specific problem (it is working with ALL AVIs and half the MP4s in another file manager, just NO MKVs).

Thanks, GM

jupe
Posts: 1244
Joined: 20 Oct 2017 21:14
Location: 1909 x64

Re: CC snippet - Video length

Post by jupe » 28 Feb 2019 12:16

The path is all messed up, make it correct without double colons and you''ll be in business...

eg.:

Code: Select all

$mediaInfo = "<xydrive>\Tools\@Command Line E:\apps\media\mediaInfo\CLI\MediaInfo.exe";
=

Code: Select all

$mediaInfo = "E:\apps\media\mediaInfo\CLI\MediaInfo.exe";

highend
Posts: 8376
Joined: 06 Feb 2011 00:33

Re: CC snippet - Video length

Post by highend » 28 Feb 2019 12:17

This is NOT the script, this is a snippet that fills all items for that custom column definition^^

This is the script:

Code: Select all

      $nsecs = property("System.Media.Duration", <cc_item>);
  
      // Use mediainfo for unknown codecs ($nsecs is empty!)
      if ($nsecs == "") {
          $mediaInfo = "<xydrive>\Tools\@Command Line Tools\MediaInfo\MediaInfo.exe";
          $length = regexreplace(runret("$mediaInfo --Inform=General;%Duration/String3% ""<cc_item>"""), "\.\d*\r?\n");
          return $length;
  
      // Use system properties for known codecs
      } else {
          // To get real seconds from nanoseconds, multiply the value with 0.0000001
          $secs = round($nsecs * 0.0000001);
  
          // Calculate length
          // Do we have a playtime in hours?
          $hours = $secs / 3600;
          if ($hours >= 1) {
              $hours = format(regexmatches($hours, "^\d+"), "00");
              $secs  = $secs - $hours * 3600;
          } else { $hours = "00"; }
          // Playtime only in minutes
          $mins = $secs / 60;
          if ($mins >= 1) {
              $mins = format(regexmatches($mins, "^\d+"), "00");
              $secs = $secs - $mins * 60;
          } else { $mins = "00"; }
          // -> Playtime is only seconds
          // Nothing to calculate here any more
          return $hours . ":" . $mins . ":" . format($secs, "00");
      }
And sorry, but this is total bs:

Code: Select all

$mediaInfo = "<xydrive>\Tools\@Command Line E:\apps\media\mediaInfo\CLI\MediaInfo.exe";
It must be:

Code: Select all

$mediaInfo = "E:\apps\media\mediaInfo\CLI\MediaInfo.exe";
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

Post Reply