Author Topic: Virtual tag that calculates song duration x times played = total time listened?  (Read 2741 times)

SonicRings

  • Sr. Member
  • ****
  • Posts: 277
I just had a neat little idea for a virtual tag that I'm unsure on how to actually make.

I'd like to be able to highlight a song or selection of songs and have it display the total listening time based on how many times each track was played. I know it would use the $Sum function but I'm not sure how to do mathematical operations on song durations.

As an example of my use case, please see the bottom right corner of this screenshot:



The Incredible Boom Boom

  • Sr. Member
  • ****
  • Posts: 1269
To get minutes, <Time> needs to be converted entirely to seconds, then multiplied by the play count, then divided by sixty seconds.
To get seconds, do the same as above, but take the remainder of the equation at the end to get the number of seconds.

Code
$Split($Div($Mul($Add($Mul($Pad($Split(<Time>,:,1),2),60),$Split(<Time>,:,2)),<▶️>),60),.,1) minutes $Mod($Mul($Add($Mul($Pad($Split(<Time>,:,1),2),60),$Split(<Time>,:,2)),<▶️>),60) seconds

There's a more efficient way to do this, but that's what I spit out pretty quickly.

SonicRings

  • Sr. Member
  • ****
  • Posts: 277
To get minutes, <Time> needs to be converted entirely to seconds, then multiplied by the play count, then divided by sixty seconds.
To get seconds, do the same as above, but take the remainder of the equation at the end to get the number of seconds.

Code
$Split($Div($Mul($Add($Mul($Pad($Split(<Time>,:,1),2),60),$Split(<Time>,:,2)),<▶️>),60),.,1) minutes $Mod($Mul($Add($Mul($Pad($Split(<Time>,:,1),2),60),$Split(<Time>,:,2)),<▶️>),60) seconds

There's a more efficient way to do this, but that's what I spit out pretty quickly.

My God, that looks so complicated! Thanks a lot! 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 know you'd have to just divide the minutes by 60 and the remainder would stay as minutes, but looking at your code I don't think I'm able to emulate it myself haha

Frankly I expected the additional tagging tools plugin to have native support for this but it didn't seem like it did.
Last Edit: October 26, 2021, 02:13:39 AM by SonicRings

SonicRings

  • Sr. Member
  • ****
  • Posts: 277
To get minutes, <Time> needs to be converted entirely to seconds, then multiplied by the play count, then divided by sixty seconds.
To get seconds, do the same as above, but take the remainder of the equation at the end to get the number of seconds.

Code
$Split($Div($Mul($Add($Mul($Pad($Split(<Time>,:,1),2),60),$Split(<Time>,:,2)),<▶️>),60),.,1) minutes $Mod($Mul($Add($Mul($Pad($Split(<Time>,:,1),2),60),$Split(<Time>,:,2)),<▶️>),60) seconds

There's a more efficient way to do this, but that's what I spit out pretty quickly.

I've tried as best as I can but couldn't figure it out. Nor could I find a place to learn how to use these functions (what does ,.,1 do?) on the internet.

This is what I have so far. Can you give me a hand, please?

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

The minutes in the above don't work properly. I'm so close. I'm getting 1:00:48 when I should be getting 1:03:48.

EDIT: I think I finally got it! Can you please evaluate my code to see if I did things right? It's giving me the intended result, but want to know if I could have done something better:

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

What was tripping me up was that I had to put $Mod OUTSIDE the $Split for the second line (minutes).

EDIT 2: Looks like I spoke too soon, it seems to be a bit wonky. Eg. two songs each with length 26 minutes and 18 minutes display their lengths normally, but when both are highlighted, it shows as 1 hour 6 minutes. When a third song is then highlighted, it goes back down to 31 minutes... Not sure what's going on.

EDIT 3: I think I see the issue here. When multiple songs are highlighted, the currently displayed Play Count tag value is the value of the first song that was highlighted. So it treats every highlighted song as having, say, 3 plays, multiplying their lengths by 3, when in fact one could have 3 plays, another 6, and another 20.

I suppose I need to make another virtual tag that can add the sum of Play Count for all highlighted tags.. Do you have any idea how I can do this?
Last Edit: October 26, 2021, 12:50:57 PM by SonicRings