soundcloud download fixed (for now) removed youtube download
This commit is contained in:
parent
13005db51c
commit
c8f5e9c823
@ -1,7 +1,6 @@
|
|||||||
local discordia=require('discordia')
|
local discordia=require('discordia')
|
||||||
local commands=require('./../commands.lua')
|
local commands=require('./../commands.lua')
|
||||||
discordia.extensions()
|
discordia.extensions()
|
||||||
local io = io
|
|
||||||
|
|
||||||
function split(s,d)
|
function split(s,d)
|
||||||
local t,c,i={},'',0
|
local t,c,i={},'',0
|
||||||
@ -20,72 +19,46 @@ function split(s,d)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function clearTmp()
|
function clearTmp()
|
||||||
for file in io.popen([[dir "./tmp" /b]]):lines() do if file then os.remove('./tmp/'..file) end end
|
for file in io.popen([[dir "./tmp" /b]]):lines() do
|
||||||
|
if file then
|
||||||
|
os.remove('./tmp/'..file)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function isTmpEmpty()
|
||||||
|
local dir = io.popen([[dir "./tmp" /b]]):read()
|
||||||
|
return dir==nil, dir, dir~=nil and split(dir,'\n') or {}
|
||||||
end
|
end
|
||||||
|
|
||||||
commands:Add('yt',{},"wip", function(t)
|
|
||||||
clearTmp()
|
|
||||||
local args = t.args
|
|
||||||
local message = t.message
|
|
||||||
if args[1] then
|
|
||||||
if args[1]:match('?v=([%w-_]+)') or args[1]:match('youtu.be/([%w-_]+)') then
|
|
||||||
local id=args[1]:match('?v=([%w-_]+)') or args[1]:match('youtu.be/([%w-_]+)')
|
|
||||||
message:reply('Attempting to download song ID='..id)
|
|
||||||
local filepath = ''
|
|
||||||
local name
|
|
||||||
local s=io.popen('ytdl.exe -x --audio-format mp3 --output "./tmp/%(title)s - %(uploader)s.%(ext)s" '..id)
|
|
||||||
if s then
|
|
||||||
repeat
|
|
||||||
a = split(io.popen([[dir "./tmp" /b]]):read('*all'),'\n')
|
|
||||||
for _,v in next,a do
|
|
||||||
if v:sub(#v-3)=='.mp3' then
|
|
||||||
print(v)
|
|
||||||
filepath=v
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
until filepath:sub(#filepath-3)=='.mp3'
|
|
||||||
if filepath then
|
|
||||||
message:reply('Found file: '..filepath)
|
|
||||||
message:reply({file='./tmp/'..filepath})
|
|
||||||
os.remove('./tmp/'..filepath)
|
|
||||||
else
|
|
||||||
message:reply('Error downloading song (this is not supposed to happen)')
|
|
||||||
end
|
|
||||||
else
|
|
||||||
message:reply('Error downloading song')
|
|
||||||
end
|
|
||||||
else
|
|
||||||
message:reply('Invalid URL')
|
|
||||||
end
|
|
||||||
else
|
|
||||||
message:reply('No URL provided')
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
commands:Add('sc',{},"wip", function(t)
|
commands:Add('sc',{},"wip", function(t)
|
||||||
clearTmp()
|
|
||||||
local args = t.args
|
local args = t.args
|
||||||
local message = t.message
|
local message = t.message
|
||||||
if args[1] then
|
if args[1] then
|
||||||
if args[1]:match('https://soundcloud.com/[%w-_]+/[%w-_]+') then
|
if args[1]:match('https://soundcloud.com/[%w-_]+/[%w-_]+') then
|
||||||
|
clearTmp()
|
||||||
local link=args[1]:match('https://soundcloud.com/[%w-_]+/[%w-_]+')
|
local link=args[1]:match('https://soundcloud.com/[%w-_]+/[%w-_]+')
|
||||||
message:reply('Attempting to download song from <'..link..'>')
|
message:reply('Attempting to download song from <'..link..'>')
|
||||||
local filepath
|
local filepath = ''
|
||||||
local s=io.popen('ytdl.exe -o "./tmp/%(title)s - %(uploader)s.%(ext)s" '..link)
|
local s=io.popen('ytdl.exe -o "./tmp/%(fulltitle)s.%(ext)s" '..link)
|
||||||
if s then
|
local songName
|
||||||
repeat
|
repeat
|
||||||
local name = io.popen([[dir "./tmp" /b]]):read('*all')
|
local str = s:read()
|
||||||
filepath = name:sub(1,name:len()-1)
|
local tag = str:match('^%[(.+)%]')
|
||||||
until filepath:sub(#filepath-3)=='.mp3'
|
if tag=='soundcloud' then
|
||||||
if filepath then
|
local song = str:match('^%[soundcloud%] (.+):')
|
||||||
message:reply('Found file: '..filepath)
|
if song:match('%d+')~=song then
|
||||||
message:reply({file='./tmp/'..filepath})
|
songName = song:match('.+/(.+)')
|
||||||
os.remove('./tmp/'..filepath)
|
end
|
||||||
else
|
end
|
||||||
message:reply('Error downloading song (this is not supposed to happen)')
|
until s:read()==nil
|
||||||
|
s:close()
|
||||||
|
if type(songName)=='string' and songName~='' then
|
||||||
|
message:reply('found song: '..songName)
|
||||||
|
local empty,file = isTmpEmpty()
|
||||||
|
if not empty then
|
||||||
|
message:reply({file='./tmp/'..file})
|
||||||
|
os.remove('./tmp/'..file)
|
||||||
end
|
end
|
||||||
else
|
|
||||||
message:reply('Error downloading song')
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
message:reply('Invalid URL')
|
message:reply('Invalid URL')
|
||||||
@ -94,3 +67,10 @@ commands:Add('sc',{},"wip", function(t)
|
|||||||
message:reply('No URL provided')
|
message:reply('No URL provided')
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
commands:Add('ct',{},'',function()
|
||||||
|
clearTmp()
|
||||||
|
end)
|
||||||
|
-- commands:Add('ft',{},'',function()
|
||||||
|
-- filterTmp()
|
||||||
|
-- end)
|
@ -1,42 +1,42 @@
|
|||||||
local discordia=require('discordia')
|
-- local discordia=require('discordia')
|
||||||
local API=require('./../strafes_net.lua')
|
-- local API=require('./../strafes_net.lua')
|
||||||
discordia.extensions()
|
-- discordia.extensions()
|
||||||
API.MAPS={}
|
-- API.MAPS={}
|
||||||
for _,game in next,API.GAMES do
|
-- for _,game in next,API.GAMES do
|
||||||
if type(tonumber(game)) == 'number' then
|
-- if type(tonumber(game)) == 'number' then
|
||||||
local maps = {count=0}
|
-- local maps = {count=0}
|
||||||
local res,headers = API:GetMaps(game)
|
-- local res,headers = API:GetMaps(game)
|
||||||
local pages = tonumber(headers['Pagination-Count'])
|
-- local pages = tonumber(headers['Pagination-Count'])
|
||||||
maps.count=maps.count+#res
|
-- maps.count=maps.count+#res
|
||||||
for _,v in next,res do
|
-- for _,v in next,res do
|
||||||
maps[v.ID]=v
|
-- maps[v.ID]=v
|
||||||
end
|
-- end
|
||||||
if pages>1 then
|
-- if pages>1 then
|
||||||
for i=2,pages do
|
-- for i=2,pages do
|
||||||
res,headers = API:GetMaps(game,i)
|
-- res,headers = API:GetMaps(game,i)
|
||||||
maps.count=maps.count+#res
|
-- maps.count=maps.count+#res
|
||||||
for _,j in next,res do
|
-- for _,j in next,res do
|
||||||
maps[j.ID]=j
|
-- maps[j.ID]=j
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
setmetatable(maps,{__index=function(self,i)
|
-- setmetatable(maps,{__index=function(self,i)
|
||||||
if i=='count' then return self.count end
|
-- if i=='count' then return self.count end
|
||||||
if not tonumber(i) then
|
-- if not tonumber(i) then
|
||||||
for ix,v in next,self do
|
-- for ix,v in next,self do
|
||||||
if type(v)=='table' and v.DisplayName:lower():find(i:lower()) then
|
-- if type(v)=='table' and v.DisplayName:lower():find(i:lower()) then
|
||||||
return v
|
-- return v
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
elseif tonumber(i) then
|
-- elseif tonumber(i) then
|
||||||
for ix,v in next,self do
|
-- for ix,v in next,self do
|
||||||
if type(v)=='table' and v.ID==i then
|
-- if type(v)=='table' and v.ID==i then
|
||||||
return v
|
-- return v
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
||||||
end})
|
-- end})
|
||||||
API.MAPS[game]=maps
|
-- API.MAPS[game]=maps
|
||||||
print('map init done for game:',API.GAMES[game],'count:',API.MAPS[game].count)
|
-- print('map init done for game:',API.GAMES[game],'count:',API.MAPS[game].count)
|
||||||
end
|
-- end
|
||||||
end
|
-- end
|
@ -65,8 +65,6 @@ commands:Add('skill',{},'skill <username|mention|"me"> <game> <style>', function
|
|||||||
for _,time in next,times do
|
for _,time in next,times do
|
||||||
points = points+time.Points
|
points = points+time.Points
|
||||||
end
|
end
|
||||||
local s = (test_a)/(test_b-1)
|
|
||||||
print(s)
|
|
||||||
local msg = 'Average Skill: '..API:FormatSkill(math.clamp(s,0,1))..'\n'..
|
local msg = 'Average Skill: '..API:FormatSkill(math.clamp(s,0,1))..'\n'..
|
||||||
'Points: '..points..'\n'..
|
'Points: '..points..'\n'..
|
||||||
pad(API,'Map',50)..' | '..pad(API,'Skill',7)..' | '.. pad(API,'Placement',14)..' | Time\n\n'
|
pad(API,'Map',50)..' | '..pad(API,'Skill',7)..' | '.. pad(API,'Placement',14)..' | Time\n\n'
|
||||||
|
@ -27,7 +27,6 @@ local function request(method,url,headers,body,options)
|
|||||||
local remaining_hour = tonumber(rheaders['X-RateLimit-Remaining-Hour'])
|
local remaining_hour = tonumber(rheaders['X-RateLimit-Remaining-Hour'])
|
||||||
local reset = tonumber(rheaders['RateLimit-Reset'])
|
local reset = tonumber(rheaders['RateLimit-Reset'])
|
||||||
local retry_after = tonumber(rheaders['Retry-After'])
|
local retry_after = tonumber(rheaders['Retry-After'])
|
||||||
print(remaining,remaining_hour)
|
|
||||||
if remaining and reset then
|
if remaining and reset then
|
||||||
local t = remaining==0 and reset or .38
|
local t = remaining==0 and reset or .38
|
||||||
if retry_after then t = retry_after end
|
if retry_after then t = retry_after end
|
||||||
|
@ -188,7 +188,7 @@ function API:GetMapCompletionCount(MAP_ID,STYLE_ID)
|
|||||||
end
|
end
|
||||||
return ((pages-1)*200)+#res
|
return ((pages-1)*200)+#res
|
||||||
end
|
end
|
||||||
--cool doggo
|
--cool doggo, aidan and me
|
||||||
function API:CalculatePoint(rank,count)
|
function API:CalculatePoint(rank,count)
|
||||||
return RANK_CONSTANT_A*(math.exp(RANK_CONSTANT_B)-1)/(1-math.exp(math.max(-700, -RANK_CONSTANT_C*count)))*math.exp(math.max(-700, -RANK_CONSTANT_D*rank))+(1-RANK_CONSTANT_E)*(1+2*(count-rank))/(count*count)
|
return RANK_CONSTANT_A*(math.exp(RANK_CONSTANT_B)-1)/(1-math.exp(math.max(-700, -RANK_CONSTANT_C*count)))*math.exp(math.max(-700, -RANK_CONSTANT_D*rank))+(1-RANK_CONSTANT_E)*(1+2*(count-rank))/(count*count)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user