soundcloud download fixed (for now) removed youtube download

This commit is contained in:
tommy aka doge 2022-08-24 17:20:44 -04:00
parent 13005db51c
commit c8f5e9c823
6 changed files with 81 additions and 104 deletions

View File

@ -1,7 +1,6 @@
local discordia=require('discordia')
local commands=require('./../commands.lua')
discordia.extensions()
local io = io
function split(s,d)
local t,c,i={},'',0
@ -20,72 +19,46 @@ function split(s,d)
end
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
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)
clearTmp()
local args = t.args
local message = t.message
if args[1] then
if args[1]:match('https://soundcloud.com/[%w-_]+/[%w-_]+') then
clearTmp()
local link=args[1]:match('https://soundcloud.com/[%w-_]+/[%w-_]+')
message:reply('Attempting to download song from <'..link..'>')
local filepath
local s=io.popen('ytdl.exe -o "./tmp/%(title)s - %(uploader)s.%(ext)s" '..link)
if s then
repeat
local name = io.popen([[dir "./tmp" /b]]):read('*all')
filepath = name:sub(1,name:len()-1)
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)')
local filepath = ''
local s=io.popen('ytdl.exe -o "./tmp/%(fulltitle)s.%(ext)s" '..link)
local songName
repeat
local str = s:read()
local tag = str:match('^%[(.+)%]')
if tag=='soundcloud' then
local song = str:match('^%[soundcloud%] (.+):')
if song:match('%d+')~=song then
songName = song:match('.+/(.+)')
end
end
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
else
message:reply('Error downloading song')
end
else
message:reply('Invalid URL')
@ -94,3 +67,10 @@ commands:Add('sc',{},"wip", function(t)
message:reply('No URL provided')
end
end)
commands:Add('ct',{},'',function()
clearTmp()
end)
-- commands:Add('ft',{},'',function()
-- filterTmp()
-- end)

View File

@ -1,42 +1,42 @@
local discordia=require('discordia')
local API=require('./../strafes_net.lua')
discordia.extensions()
API.MAPS={}
for _,game in next,API.GAMES do
if type(tonumber(game)) == 'number' then
local maps = {count=0}
local res,headers = API:GetMaps(game)
local pages = tonumber(headers['Pagination-Count'])
maps.count=maps.count+#res
for _,v in next,res do
maps[v.ID]=v
end
if pages>1 then
for i=2,pages do
res,headers = API:GetMaps(game,i)
maps.count=maps.count+#res
for _,j in next,res do
maps[j.ID]=j
end
end
end
setmetatable(maps,{__index=function(self,i)
if i=='count' then return self.count end
if not tonumber(i) then
for ix,v in next,self do
if type(v)=='table' and v.DisplayName:lower():find(i:lower()) then
return v
end
end
elseif tonumber(i) then
for ix,v in next,self do
if type(v)=='table' and v.ID==i then
return v
end
end
end
end})
API.MAPS[game]=maps
print('map init done for game:',API.GAMES[game],'count:',API.MAPS[game].count)
end
end
-- local discordia=require('discordia')
-- local API=require('./../strafes_net.lua')
-- discordia.extensions()
-- API.MAPS={}
-- for _,game in next,API.GAMES do
-- if type(tonumber(game)) == 'number' then
-- local maps = {count=0}
-- local res,headers = API:GetMaps(game)
-- local pages = tonumber(headers['Pagination-Count'])
-- maps.count=maps.count+#res
-- for _,v in next,res do
-- maps[v.ID]=v
-- end
-- if pages>1 then
-- for i=2,pages do
-- res,headers = API:GetMaps(game,i)
-- maps.count=maps.count+#res
-- for _,j in next,res do
-- maps[j.ID]=j
-- end
-- end
-- end
-- setmetatable(maps,{__index=function(self,i)
-- if i=='count' then return self.count end
-- if not tonumber(i) then
-- for ix,v in next,self do
-- if type(v)=='table' and v.DisplayName:lower():find(i:lower()) then
-- return v
-- end
-- end
-- elseif tonumber(i) then
-- for ix,v in next,self do
-- if type(v)=='table' and v.ID==i then
-- return v
-- end
-- end
-- end
-- end})
-- API.MAPS[game]=maps
-- print('map init done for game:',API.GAMES[game],'count:',API.MAPS[game].count)
-- end
-- end

View File

@ -65,8 +65,6 @@ commands:Add('skill',{},'skill <username|mention|"me"> <game> <style>', function
for _,time in next,times do
points = points+time.Points
end
local s = (test_a)/(test_b-1)
print(s)
local msg = 'Average Skill: '..API:FormatSkill(math.clamp(s,0,1))..'\n'..
'Points: '..points..'\n'..
pad(API,'Map',50)..' | '..pad(API,'Skill',7)..' | '.. pad(API,'Placement',14)..' | Time\n\n'

View File

@ -27,7 +27,6 @@ local function request(method,url,headers,body,options)
local remaining_hour = tonumber(rheaders['X-RateLimit-Remaining-Hour'])
local reset = tonumber(rheaders['RateLimit-Reset'])
local retry_after = tonumber(rheaders['Retry-After'])
print(remaining,remaining_hour)
if remaining and reset then
local t = remaining==0 and reset or .38
if retry_after then t = retry_after end

View File

@ -188,7 +188,7 @@ function API:GetMapCompletionCount(MAP_ID,STYLE_ID)
end
return ((pages-1)*200)+#res
end
--cool doggo
--cool doggo, aidan and me
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)
end

BIN
ytdl.exe

Binary file not shown.