Calculate playing time of mp3's
-
aurumdigitus
- Posts: 1075
- Joined: 30 May 2008 21:02
- Location: Lake Erie
Calculate playing time of mp3's
Using Sticky Selection would like to be able to pick a number of mp3's in a folder and have the total playing time (Length) calculated from the Tags and displayed in some manner. Can this be accomplished via Scripting, conjuring, incantation or any other manner?
-
admin
- Site Admin
- Posts: 66351
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Calculate playing time of mp3's
I think scripting is enough, but incantation never harms.aurumdigitus wrote:Using Sticky Selection would like to be able to pick a number of mp3's in a folder and have the total playing time (Length) calculated from the Tags and displayed in some manner. Can this be accomplished via Scripting, conjuring, incantation or any other manner?
I would look at the property() function, and then it's just a little string parsing and math.
FAQ | XY News RSS | XY X
-
TheQwerty
- Posts: 4373
- Joined: 03 Aug 2007 22:30
Re: Calculate playing time of mp3's
Code: Select all
//Display the Length Property # of the current system.
"Find Length Property : showProp"
Global($prop);
Sub("_getProp");
$prop = $prop == 100 ? "Could not find length property for the current item." : "The Length Property is #$prop.";
Echo($prop);
//Brute Force through Properties to find the length.
"_getProp"
Global($prop);
$prop = 1;
while ($prop < 100) {
$test = RegExReplace(Property("#$prop", "<curitem>"), "^[0-9]+:[0-9]+:[0-9]+$", ":::MATCH:::");
if ($test Like ":::MATCH:::") { break; }
$prop++;
}
"Calculate Length of Selection"
/* Find the Property number corresponding to the length.
You can remove the next three lines if you replace "$prop" below
with the number returned by "Find Length Property".
*/
Global($prop);
Sub("_getProp");
End($prop == 100, "Could not find length property of:<crlf><curitem>");
//Convert the length of each item to seconds and sum them.
Global($sec);
$result = Report('Eval(RegExReplace(Property("#' . $prop . '","{FullName}"),"^([0-9]+):([0-9]+):([0-9]+)$","$1*3600+$2*60+$3"))+',1,'Global($sec);$sec=Eval(','0);');
Load("$result",,"s");
//Convert from seconds back to hh:mm:ss
$hrs = '00';
$min = '00';
if ($sec >= 3600) {
$hrs = GetToken($sec / 3600, 1, '.');
$sec = $sec - $hrs*3600;
$hrs = $hrs < 10 ? "0$hrs" : $hrs;
}
if ($sec >= 60) {
$min = GetToken($sec / 60, 1, '.');
$sec = $sec - $min*60;
$min = $min < 10 ? "0$min" : $min;
}
$sec = $sec < 10 ? "0$sec" : $sec;
Echo("Total Length: $hrs:$min:$sec");You can make it a bit shorter if you use "Find Length Property" to get the number of the length property on your system and then remove the first 3 lines of code in "Calculate Length of Selection" and replace "$prop" with that number.
-
Stefan
- Posts: 1360
- Joined: 18 Nov 2008 21:47
- Location: Europe
Re: Calculate playing time of mp3's
TheQwerty wrote:Code: Select all
$prop = 1; while ($prop < 100) { $test = RegExReplace(Property("#$prop", "<curitem>"), "^[0-9]+:[0-9]+:[0-9]+$", ":::MATCH:::"); if ($test Like ":::MATCH:::") { break; } $prop++; }
XYplorer menu > Tools > Configuration > File Info Tips >> see the list on the right. For my XP 'Dauer' has # 21get the number of the length property on your system
-
TheQwerty
- Posts: 4373
- Joined: 03 Aug 2007 22:30
Re: Calculate playing time of mp3's
Awww I completely forgot about that nice list by Don!Stefan wrote:XYplorer menu > Tools > Configuration > File Info Tips >> see the list on the right. For my XP 'Dauer' has # 21
But yes it's #21 "Duration" here as well.
Though leaving it as is gives everyone a chance to significantly improve the performance.
XYplorer Beta Club