Adding up the Length column
-
aurumdigitus
- Posts: 1075
- Joined: 30 May 2008 21:02
- Location: Lake Erie
Adding up the Length column
In working with MP3's have a List view set up that shows the Length column as well as some other relevant data.
Question: Is there any feature of XY that will sum the Lengths shown to give a grand total?
Question: Is there any feature of XY that will sum the Lengths shown to give a grand total?
Re: Adding up the Length column
Nothing built-in but you can use Report + Eval to calculate the length.
Code: Select all
"Calculate Length"
// Retrieve the lengths as a mathematical equation.
// You may need to adjust the '{prop:*Length}' for your system.
Global $G_DURATION = Report('+{prop:*Length}', 0 /*use 1 for selection instead*/, 0);
// Remove items which didn't have a length.
$G_DURATION = FormatList($G_DURATION, 'tue', '+');
// Expand 'hh:mm:ss' to 'hh*60*60+mm*60+ss' so we calculate total seconds.
$G_DURATION = RegexReplace($G_DURATION, '(\d\d):(\d\d):(\d\d)', '$1*60*60+$2*60+$3');
// Do the math.
$G_DURATION = eval($G_DURATION);
Sub '_formatDuration';
Echo $G_DURATION;
"Format Duration in Seconds : _formatDuration"
Global $G_DURATION;
$Secs = $G_DURATION;
// Just stealing Don's code since I don't feel like doing this right now:
// Src: http://www.xyplorer.com/xyfc/viewtopic.php?p=57847#p57847
// format duration given in seconds
$DAYS_PER_YEAR = 365.25;
$HOURS_PER_DAY = 24;
$MINS_PER_HOUR = 60;
$SECS_PER_MIN = 60;
$duration = "";
$Mins = $Secs \ $SECS_PER_MIN;
$Hours = $Mins \ $MINS_PER_HOUR;
$Days = $Hours \ $HOURS_PER_DAY;
$Years = $Days \ $DAYS_PER_YEAR;
If ($Years > 0) {
$duration = $Years . "y";
}
$Days = $Days % $DAYS_PER_YEAR;
If ($Days > 0) {
$duration = $duration . " " . $Days . "d";
}
$Hours = $Hours % $HOURS_PER_DAY;
If ($Hours > 0) {
$duration = $duration . " " . $Hours . "h";
}
$Mins = $Mins % $MINS_PER_HOUR;
If ($Mins > 0) {
$duration = $duration . " " . $Mins . "min";
}
$Secs = $Secs % $SECS_PER_MIN;
If ($Secs > 0) {
$duration = $duration . " " . $Secs . "sec";
}
$G_DURATION = $duration;-
aurumdigitus
- Posts: 1075
- Joined: 30 May 2008 21:02
- Location: Lake Erie
Re: Adding up the Length column
Thank you for the code that came with such celerity!
This must be crucial: // You may need to adjust the '{prop:*Length}' for your system. Do not comprehend and thus unable to implement the change. Instead, when XYS is run am presented with the screen shot below.
Moral - Some days you're the windshield, other days you're the bug.
This must be crucial: // You may need to adjust the '{prop:*Length}' for your system. Do not comprehend and thus unable to implement the change. Instead, when XYS is run am presented with the screen shot below.
Moral - Some days you're the windshield, other days you're the bug.
- Attachments
-
- Screen capture.jpg (94.84 KiB) Viewed 3910 times
Re: Adding up the Length column
That error shouldn't be related to that comment.aurumdigitus wrote:This must be crucial: // You may need to adjust the '{prop:*Length}' for your system. Do not comprehend and thus unable to implement the change. Instead, when XYS is run am presented with the screen shot below.
If you see a length value after running the following script with your music files selected you don't need to mess with that line:
Code: Select all
Text Report("{prop:*Length}<crlf>", 1);Your error is about it not finding the script to format the duration, so give the attached file a try instead.
-
klownboy
- Posts: 4397
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440
Re: Adding up the Length column
Worked great for me (also USA...as far as "length" prop working). This may come in handy. It looks like the only prerequisite is to have an mp3 folder selected such that the files are shown in the list panel (i.e., doesn't seem to matter if any, one, or all are actually selected which is also nice). Might be nice for a trigger. Of course each mp3 file already has one trigger "click" to play them.
Thanks TheQwerty for the script and aurumdigitus fot the idea / request.
Ken
Thanks TheQwerty for the script and aurumdigitus fot the idea / request.
Ken
Re: Adding up the Length column
It just uses report to retrieve the lengths so you can change it to only report on the selected items or an item list generated through other means.
Or you could change it to use folderreport and recursively retrieve it for a folder and all its children.
I'm not sure how slow that would be and you might discover some limitations in the length of the generated string which gets evaled.
Or you could change it to use folderreport and recursively retrieve it for a folder and all its children.
I'm not sure how slow that would be and you might discover some limitations in the length of the generated string which gets evaled.
-
klownboy
- Posts: 4397
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440
Re: Adding up the Length column
I think it's good just the way it is. Most people would have one album (or should I say CD) in a folder and typically they'd want to know the length of a particular mp3 song(s) or entire the CD. Yes, I just noticed you used "0" for the "itemlist" with report for all current items in the list. Thanks again.
-
aurumdigitus
- Posts: 1075
- Joined: 30 May 2008 21:02
- Location: Lake Erie
Re: Adding up the Length column
@ TheQwerty - To use the tag line from an old 1970's Xerox commercial, "It's a miracle". Duration.xys worked perfectly first time right out of the box. Thanks to you for knowing what magical incantation to perform.
@ klownboy - it provides a certain measure of satisfaction that others find these little brainstorms of mine useful.
Life is funny. I am able to make almost anyone comprehend why long chain carbon polymers make use of SP3 hybridization for their covalent bonding. But writing a decent script - nope.
@ klownboy - it provides a certain measure of satisfaction that others find these little brainstorms of mine useful.
Life is funny. I am able to make almost anyone comprehend why long chain carbon polymers make use of SP3 hybridization for their covalent bonding. But writing a decent script - nope.
-
aurumdigitus
- Posts: 1075
- Joined: 30 May 2008 21:02
- Location: Lake Erie
Opps - update
Bug report! Have discovered that after initial run the script does not reset. It keeps reporting the same time as the first calculation.
Re: Opps - update
Not sure how that can even be possible since the script doesn't store anything.aurumdigitus wrote:Bug report! Have discovered that after initial run the script does not reset. It keeps reporting the same time as the first calculation.
-
aurumdigitus
- Posts: 1075
- Joined: 30 May 2008 21:02
- Location: Lake Erie
Re: Adding up the Length column
Only course of action at the moment seems to be to give up on this quest.
Perhaps it should be mentioned that this desktop (and its software) have certain anomalies that ADMIN has never been able to explain or fix. An especially vexing one is that Floating Preview never has been able to display PDF's.
Perhaps it should be mentioned that this desktop (and its software) have certain anomalies that ADMIN has never been able to explain or fix. An especially vexing one is that Floating Preview never has been able to display PDF's.
Some days you ride the elevator; other days you get the shaft.
-
admin
- Site Admin
- Posts: 64875
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Adding up the Length column
aurumdigitus wrote:Only course of action at the moment seems to be to give up on this quest.
Perhaps it should be mentioned that this desktop (and its software) have certain anomalies that ADMIN has never been able to explain or fix. An especially vexing one is that Floating Preview never has been able to display PDF's.
Some days you ride the elevator; other days you get the shaft.
Take a rest, man...
FAQ | XY News RSS | XY X
-
klownboy
- Posts: 4397
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440
Re: Adding up the Length column
aurumdigitus, just curious, after you take your "rest", how are you running the script?
Are you clicking on a mp3 folder in the tree pane such that the songs are displayed in the list pane and then selecting "load script file..." under scripting? Or you can temporarily assign the script to a CTB left or right click to run it. When you run the script that way, what happens and what happens when you then change folders by clicking a different one in the tree and rerun the script? Still the same total time?
-
aurumdigitus
- Posts: 1075
- Joined: 30 May 2008 21:02
- Location: Lake Erie
Re: Adding up the Length column
@ klownboy - Approach is to select the MP3's in list pane then run script. Have done so from a CTB alone, a CTB that contains a list of favorite scripts and from Scripting | Run Script. No matter which method continue to get varying results.
Tried the different modifications you suggested; no improvement.
Glad it is working for others but have come to believe poltergeist are at work here, the same ones inhibiting PDF displays.
Tried the different modifications you suggested; no improvement.
Glad it is working for others but have come to believe poltergeist are at work here, the same ones inhibiting PDF displays.
-
klownboy
- Posts: 4397
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.7171 at 100% 2560x1440
Re: Adding up the Length column
If you'd rather select item (mp3 files), try changing the "0" to "1" in this line (the 4th line) to see if you get better results.
I'm not sure why there's a second "0" after the comment in that line of TheQwerty's original code ?? I may be all wet but, it doesn't appear to be correct according to the help syntax (maybe an extra "0" got in there). The above line works for me when used as I explained in my previous post. If you want to highlight files change the "0" to "1".
Code: Select all
Global $G_DURATION = Report('+{prop:*Length}', 0 );
XYplorer Beta Club