Author Topic: Disc Duration  (Read 1040 times)

hamlet35

  • Newbie
  • *
  • Posts: 6
Good morning all!

I am trying to create a virtual tag for Disc Duration - I need this for multiple disc sets. On my Main Table I want to show something like this:

Disc 1 of 2  46:00
Tracks
Disc 2 of 2  35:00

Right now I have the album duration in there, but would like to get Disc Duration and not album duration.  I tried doing some research, but couldn't find anything.

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
Someone else might know of a condensed formula, but here it is in four virtual tags:

v1 Duration converted to seconds   =   $Add($Mul($Split(<Time>,:,1),60),$Split(<Time>,:,2))
v2 Unique Album Disc   =   <Disc#><Album><Album Artist>
v3 Total Duration per Disc   =   $Sum(<v1>,<v2>)
v4 Combined Disc Duration   =   $Split($Div(<v3>,60),",",1):$Sub(<v3>,$Mul($Split($Div(<v3>,60),",",1),60))
Strength and Honour (2025)

hamlet35

  • Newbie
  • *
  • Posts: 6
This was a great start and I thank you so much. I think I now have a formatting issue.
In this part of the code from part 4: $Split($Div(<v3>,60),",",1):$Sub(<v3>,$Mul($Split($Div(<v3>,60),",",1),60)), is there a way to get the results in the format of 56:09 for discs that are less than an hour and 1:15: 00 for above an hour or even in the format of 00:00:00 (hour, minute, seconds)

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
is there a way to get the results in the format of 56:09 for discs that are less than an hour and 1:15: 00 for above an hour or even in the format of 00:00:00 (hour, minute, seconds)
It is possible, but to be honest, I'm not up for that task this evening - sorry.
See if you can play around with this formula below to get it to do what you want. You just need to insert the seconds in v3 in here:

Just wondering if it's possible to also split hours and days? Or I guess just hours would make the most sense, no need for days.
....
I think I finally got it!

Code
$Split($Div($Mul($Add($Mul($Pad($Split(<Time>,:,1),2),60),$Split(<Time>,:,2)),<Play Count>),3600),.,1) hours $Mod($Split($Div($Mul($Add($Mul($Pad($Split(<Time>,:,1),2),60),$Split(<Time>,:,2)),<Play Count>),60),.,1),60) minutes $Mod($Mul($Add($Mul($Pad($Split(<Time>,:,1),2),60),$Split(<Time>,:,2)),<Play Count>),60) seconds
Strength and Honour (2025)

karbock

  • Sr. Member
  • ****
  • Posts: 552
A new v4 formula to distinguish between discs longer/shorter than one hour.
It is also shorter, thanks to the use of modulos and downward roundings.

You'll need to have the Additional Tagging & Reporting Tools plugin installed (for $ge and $RoundDown).

Code
$If($ge(<v3>,3600),$RoundDown($Div(<v3>,3600),0)":",)$Pad($RoundDown($Div($Mod(<v3>,3600),60),0),2)":"$Pad($Mod(<v3>,60),2)

Or, if you prefer the ... h ... min ... s format:
Code
$If($ge(<v3>,3600),$RoundDown($Div(<v3>,3600),0)" h ",)$RoundDown($Div($Mod(<v3>,3600),60),0)" min "$Mod(<v3>,60)" s"

hamlet35

  • Newbie
  • *
  • Posts: 6
This: $If($ge(<v3>,3600),$RoundDown($Div(<v3>,3600),0)" h ",)$RoundDown($Div($Mod(<v3>,3600),60),0)" min "$Mod(<v3>,60)" s"

did the trick!  Thanks for everyone's help!

karbock

  • Sr. Member
  • ****
  • Posts: 552
You're welcome!

NOTE:
Since the value in <Time> is an approximation (the milliseconds are dropped),
<v3> will never be accurate to the second.
But there is no workaround.

hiccup

  • Hero Member
  • *****
  • Posts: 9111
Building upon the great solutions that Mayibongwe and Karbock have already provided, thanks to Boroda it is now possible to accomplish this with three virtual tags instead of four, but more importantly, much simpler formulas.
It requires the latest version of the Additional Tagging & Reporting Tools plugin (v8.2.8932)
(see here for a link to the first version that has this new functionality)

It (probably?) also requires MusicBee v3.6

These are the three virtual tags:

1.
Seconds
$Seconds(<Time>)

2.
Disc tracks
<Album><Album Artist><Disc#>

3.
Disc duration
$DurationFromSeconds($Sum(<Seconds>,<Disc tracks>))

#1 and #2 being necessary to make #3 work
#3 being the one that you will be using for displaying disc duration
 
Last Edit: April 28, 2025, 07:37:59 PM by hiccup

Zak

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2553
I'm not going to install the plugin to test it, but it looks like the $Sum function will accept an expression as the first argument, but not the second.

So it might be possible to do this:

Code
$DurationFromSeconds($Sum($Seconds(<Time>),<Disc tracks>))
Which will only require two virtual tags instead of three.
Bee excellent to each other...

hiccup

  • Hero Member
  • *****
  • Posts: 9111
Code
$DurationFromSeconds($Sum($Seconds(<Time>),<Disc tracks>))
Which will only require two virtual tags instead of three.
Nope, doesn't work.
There is some limitation on nesting with regards to the $Sum function.