CloneTrooper1019

MP3 Binary Obtainer

Jun 30th, 2014
699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.39 KB | None | 0 0
  1. -----------------------------------------------------------------------------------------------------------------------------------------
  2. -- @CloneTrooper1019, 2014
  3.  
  4. -- This function allows you to get the length of a sound using its asset hash.
  5.  
  6. -- Please note that this function only gives you a rough estimate of the sound's length
  7. -- It could be around +/- 2 seconds off, but its certainly closer than nothing.
  8.  
  9. -- It requires the HttpService to be enabled in order to use as it requests the
  10. -- sound informatioh from the website.
  11.  
  12. -- To get the asset hash of a sound, you must go to an audio page.
  13.  
  14. -- For example: If we wanted to get the hash for this sound
  15. -- http://www.roblox.com/Leeeeeeroy-Jenkins-item?id=130758889
  16.  
  17. -- We have to replace it with this in the url:
  18. -- http://www.roblox.com/asset/?id=130758889
  19.  
  20. -- If the audio is supported, you should be redirected to a rbxcdn link like this:
  21. -- http://c2.rbxcdn.com/7f3aa807276de0440acc4f167cdc9ea8
  22.  
  23. -- Those random keys next next to the / in the url are actually the hash of the sound.
  24. -- From there, we set the SoundId of the audio you want to get the length of to this:
  25. -- http://www.roblox.com/asset/?hash=7f3aa807276de0440acc4f167cdc9ea8
  26.  
  27. -- Now you can call getSoundLength on the sound.
  28. -- Be aware that this function may flood the output with warnings, just try to ignore it :P
  29.  
  30. -----------------------------------------------------------------------------------------------------------------------------------------
  31.  
  32. function estLength(sound)
  33.     local http = game:GetService("HttpService")
  34.     local network = game:GetService("NetworkServer")
  35.     if http then
  36.         local soundId = sound.SoundId
  37.         local first,last = string.find(soundId,"?hash=")
  38.         if not first or not last then
  39.             error("The SoundId of "..sound:GetFullName().." must have a hashed version of the asset url. Read the script for more information.")
  40.         else
  41.             local hash = string.sub(soundId,last+1)
  42.             if #hash == 0 then
  43.                 error("Invalid Hash")
  44.             end
  45.             local str
  46.             for i = 0,9 do
  47.                 if str then break end
  48.                 pcall(function ()
  49.                     str = http:GetAsync("http://c"..i..".rbxcdn.com/"..hash,false)
  50.                 end)
  51.             end
  52.             if not str then
  53.                 error("Unable to find sound info for hash: "..hash)
  54.             end
  55.             print("Estimated Audio Length: "..#str/20000)
  56.             return #str/20000
  57.         end
  58.     else
  59.         error("The HttpService must be enabled in order to use this function")
  60.     end
  61. end
Advertisement
Add Comment
Please, Sign In to add comment