Check audio lenght in seconds

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.
You could do the following with Reqn:
code_language.skript:
send request to "https://dl.dropboxusercontent.com/s/twx0oix1bfo20mc/Eddie%%20Van%%20Halen%%20-%%20Eruption.mp3?dl=0"
wait 1 second
set {_headers::values::*} to response's header values
set {_duration} to ({_header::values::11} parsed as num*0.008) / 128
It's not exact though, the formula is:
code_language.skript:
sizeOfFileInBytes*0.008 / bitrate
I multiply it by 0.008 to convert it to bits, in your case it would be
code_language.skript:
set {_duration} to ({_header::values::11} parsed as num*0.008) / 128
set {_duration} to floor(({_duration} - 10))

Off-topic: @BrettPlayMC what addon?
 
Last edited by a moderator:
Off-topic: @BrettPlayMC what addon?
https://forums.skunity.com/resources/openaudiomcskript.189/

You could do the following with Reqn:
code_language.skript:
send request to "https://dl.dropboxusercontent.com/s/twx0oix1bfo20mc/Eddie%%20Van%%20Halen%%20-%%20Eruption.mp3?dl=0"
wait 1 second
set {_headers::values::*} to response's header values
set {_duration} to ({_header::values::11} parsed as num*0.008) / 128
It's not exact though, the formula is:
code_language.skript:
sizeOfFileInBytes*0.008 / bitrate
I multiply it by 0.008 to convert it to bits, in your case it would be
code_language.skript:
set {_duration} to ({_header::values::11} parsed as num*0.008) / 128
set {_duration} to floor(({_duration} - 10))
?

So I have to check the bitrate first to make the division?

Also, is not possible to get the number value direct from the page, as it is displayed in the page? I don't know how CSS, HTML or whatever works, but the info is already available in the site:

mmUtBYC.png


I think I made a workaround where I will not need this value anymore, but to know if it's possible for it to be retrieved directly would be nice. Thanks.
[doublepost=1495819082,1495817947][/doublepost]What if I want to check if a player provided a working dropbox link?

Here is the code:

code_language.skript:
command /callradio <text>
  description: Call radio and suggests a music
  trigger:
    if arg 1 starts with "https://dl.dropboxusercontent.com/":
      if arg 1 contains " ":
        message "You can't do that!" #blank space detected
        stop
      add {radiomusic::*} to arg 1
    message "You need a direct link from dropbox!"

But I need to check if:
It's a valid link.
It's a link to a MP3
(any other fail safe test possible?)
 
https://forums.skunity.com/resources/openaudiomcskript.189/



So I have to check the bitrate first to make the division?

Also, is not possible to get the number value direct from the page, as it is displayed in the page? I don't know how CSS, HTML or whatever works, but the info is already available in the site:

mmUtBYC.png


I think I made a workaround where I will not need this value anymore, but to know if it's possible for it to be retrieved directly would be nice. Thanks.
[doublepost=1495819082,1495817947][/doublepost]What if I want to check if a player provided a working dropbox link?

Here is the code:

code_language.skript:
command /callradio <text>
  description: Call radio and suggests a music
  trigger:
    if arg 1 starts with "https://dl.dropboxusercontent.com/":
      if arg 1 contains " ":
        message "You can't do that!" #blank space detected
        stop
      add {radiomusic::*} to arg 1
    message "You need a direct link from dropbox!"

But I need to check if:
It's a valid link.
It's a link to a MP3
(any other fail safe test possible?)
If it doesn't contain .com, http(s), etc.
 
I sent out that method because it's not possible to get the number you see there, I would have done that otherwise.

Answering the other question, you could do the following:
code_language.skript:
send request to arg-1
wait 1 second
if response's status code is 200:
    set {_headers::values::*} to response's header values
    if {_header::values::14} is "audio/mpeg": #I think it was the 14, if not it's the 15 or 4
        #the above stuff
 
I sent out that method because it's not possible to get the number you see there, I would have done that otherwise.

Answering the other question, you could do the following:
code_language.skript:
send request to arg-1
wait 1 second
if response's status code is 200:
    set {_headers::values::*} to response's header values
    if {_header::values::14} is "audio/mpeg": #I think it was the 14, if not it's the 15 or 4
        #the above stuff
For this is needed Reqn?
 
I saw that you set the spaces in the link to "%%". Is this needed?

code_language.skript:
send request to "https://dl.dropboxusercontent.com/s/twx0oix1bfo20mc/Eddie%%20Van%%20Halen%%20-%%20Eruption.mp3?dl=0"
[doublepost=1495821917,1495821823][/doublepost]And check it out, this will work? (loop the header value)

code_language.skript:
          if arg 1 contains "https://dl.dropboxusercontent.com/":
            if arg 1 contains " ":
              set " " to "%%" in arg 1
            send request to arg-1
            wait 1 second
            if response's status code is 200:
              set {_headers::values::*} to response's header values
              loop {_headers::values::*}:
                if loop-value is "audio/mpeg":
                  #dostuff
 
I saw that you set the spaces in the link to "%%". Is this needed?

code_language.skript:
send request to "https://dl.dropboxusercontent.com/s/twx0oix1bfo20mc/Eddie%%20Van%%20Halen%%20-%%20Eruption.mp3?dl=0"
You can't put spaces in an URL, it gets converted to "%20" (see Percent-encoding). And it's "%%20" in Skript because you have to double the percent signs in a string to be parsed correctly and not as an expression.

And yes, it'll. I would do it like this though:
code_language.skript:
loop {_headers::values::*}:
    if loop-text is "audio/mpeg":
        ser {_check} to true
if {_check} is set:
    #do stuff
 
You can't put spaces in an URL, it gets converted to "%20" (see Percent-encoding).

And yes, it'll. I would do it like this though:
code_language.skript:
loop {_headers::values::*}:
    if loop-text is "audio/mpeg":
        ser {_check} to true
if {_check} is set:
    #do stuff
Oh, right. Your loop is better as it would not run twice if loop-text "audio/mpeg" is found more than once. Thanks.
Is this necessary then or can I remove?
code_language.skript:
            if arg 1 contains " ":
              set " " to "%%20" in arg 1
Thanks.
 
Oh, right. Your loop is better as it would not run twice if loop-text "audio/mpeg" is found more than once. Thanks.
Is this necessary then or can I remove?
code_language.skript:
            if arg 1 contains " ":
              set " " to "%%20" in arg 1
Thanks.
Only the check is unnecessary, you could keep the second line just to be sure. Make sure to replace "set" with "replace" and "to" with "with", it should be:
code_language.skript:
set {_url} to arg-1
replace " " with "%%20" in {_url}
Such as you can't set specific characters in a text, Skript isn't that easy haha.
 
  • Like
Reactions: BrettPlayMC
Only the check is unnecessary, you could keep the second line just to be sure. Make sure to replace "set" with "replace" and "to" with "with", it should be:
code_language.skript:
set {_url} to arg-1
replace " " with "%%20" in {_url}
Such as you can't set specific characters in a text, Skript isn't that easy haha.
Oh, right, I already used alot the replace in chat filters I made for my server, but I forgot.
The "set {_url} to arg-1 is needed or can I make this straight:

code_language.skript:
            if arg 1 contains " ":
              replace " " with "%%20" in the arg 1
 
Oh, right, I already used alot the replace in chat filters I made for my server, but I forgot.
The "set {_url} to arg-1 is needed or can I make this straight:

code_language.skript:
            if arg 1 contains " ":
              replace " " with "%%20" in the arg 1
I don't remember if you can replace stuff from the argument directly so you might have to try. I did a local variable with the argument in it just if it wasn't the case.
 
  • Like
Reactions: aescraft
Do I need to clear these kind of variables "{_url}" in the end of the code? Or it will clear itself?
 
Do I need to clear these kind of variables "{_url}" in the end of the code? Or it will clear itself?
These local variables should be automatically deleted after the trigger is done as every local variable. So yeah, it'll be cleared itself.
 
You could do the following with Reqn:
code_language.skript:
send request to "https://dl.dropboxusercontent.com/s/twx0oix1bfo20mc/Eddie%%20Van%%20Halen%%20-%%20Eruption.mp3?dl=0"
wait 1 second
set {_headers::values::*} to response's header values
set {_duration} to ({_header::values::11} parsed as num*0.008) / 128
It's not exact though, the formula is:
code_language.skript:
sizeOfFileInBytes*0.008 / bitrate
I multiply it by 0.008 to convert it to bits, in your case it would be
code_language.skript:
set {_duration} to ({_header::values::11} parsed as num*0.008) / 128
set {_duration} to floor(({_duration} - 10))

Off-topic: @BrettPlayMC what addon?
Just explain to me, what is the 128? 128bits?

And the "set {_duration} to floor(({_duration} - 10))", what is the purpose? Don't get it...
 
Yeah, 128 is the bitrate of the audio file, not every audio file has that bitrate but it's the case for the most part of them. The floor function rounds down the given number and I subtracted 10 from the duration because it adds 10 to the duration for some reason, that's why I said it's not exact.

You can search what bitrate is, it's kind of technical info in this case so I won't explain it.
 
You can search what bitrate is, it's kind of technical info in this case so I won't explain it.
Is it possible to make the skript check the bitrate?
I need to check the audio track lenght to limit in up to 7 minutes musics the mp3 the players can recommend to the global radio, to avoid abuse.
[doublepost=1496004041,1495826868][/doublepost]Bump.
 
Status
Not open for further replies.