This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
WeaponMaster's profile picture

Need help with Song player

Started by WeaponMaster, 16 February 2013 - 02:38 AM
WeaponMaster #1
Posted 16 February 2013 - 03:38 AM
Title: Need help with Song player

Body:
Greetings,
recently, i came across an excellent program and video, showing a noteblock player. program is written onto computer, songs in .nbs format are placed in the saves/worldname/computers/comp#/song folder(i think). an iron noteblock from misc peripherals is added to the side of the computer, and upon running the program, it confronts you with a simple layout which allows you to play the song with ease. it had taken me a long time to find such a thing. however, on testing this on a server i setup, i found a problem. using the wonders of paste bin, i could download the program with ease. however, i need to access the world save in order to put the .nbs files into it to play it.
i am kinda an idiot with coding, and have made repeated forays into lua with mild success, but my programing logic needs a good deal of work. i basically need someone to help me code a program which can download a .nbs file, maybe from mediafire or something similar, and insert it into the song folder.
here are links to the original program and video, all credits to author.
[media]http://www.youtube.com/watch?v=ro4EK8smULQ[/media]
download to program on the video's discription
thanks, and hope you can help
bjornir90 #2
Posted 16 February 2013 - 05:25 AM
I don't have time to code it for the moment but if the folder is in the computer it will be easy, you need to enanle http API and then use it and the fs API to make it (look in the wiki)
LBPHacker #3
Posted 16 February 2013 - 06:12 AM
Save this and run with a parameter that points to an .nbs file on the internet.



if not http then
	print("HTTP API is disabled")
	return false
end
local destination = "songs"
local url = ({...})[1]
local httpHandle = http.get(url)
if not httpHandle then
	print("Error downloading file")
	return false
end
if not fs.exists(destination) then fs.makeDir(destination) end
if not fs.isDir(destination) then
	print("Destination must be a directory")
	return false
end
local fileHandle = fs.open(destination .. "/" .. fs.getName(url), "w")
if not fileHandle then
	print("Error opening file")
	return false
end
fileHandle.write(httpHandle.readAll())
httpHandle.close()
fileHandle.close()
print("Done")
Mc_gee #4
Posted 17 February 2013 - 01:43 PM
Save this and run with a parameter that points to an .nbs file on the internet.



if not http then
	print("HTTP API is disabled")
	return false
end
local destination = "song"
local url = ({...})[1]
local httpHandle = http.get(url)
if not httpHandle then
	print("Error downloading file")
	return false
end
if not fs.exists(destination) then fs.makeDir(destination) end
if not fs.isDir(destination) then
	print("Destination must be a directory")
	return false
end
local fileHandle = fs.open(destination .. "/" .. fs.getName(url), "w")
if not fileHandle then
	print("Error opening file")
	return false
end
fileHandle.write(httpHandle.readAll())
httpHandle.close()
fileHandle.close()
print("Done")

can you do a example because i'm getting nowhere if you do it like that
LBPHacker #5
Posted 17 February 2013 - 10:26 PM
OK, I upload it to pastebin… Done.

Type these two lines into the shell:
pastebin get EPmXcFs0 downloader
downloader http://somewhereontheinternet.com/mymusic.nbs
Where "downloader" can be anything, and "http://somewhereontheinternet.com/mymusic.nbs" is the file on the internet.
Mc_gee #6
Posted 18 February 2013 - 02:37 AM
OK, I upload it to pastebin… Done. Type these two lines into the shell:
pastebin get EPmXcFs0 downloader downloader http://somewhereontheinternet.com/mymusic.nbs
Where "downloader" can be anything, and "http://somewhereontheinternet.com/mymusic.nbs" is the file on the internet.
am i doing it right because i do this

downloader http://199.91.154.22/axtyjcq3glug/8f2bizyl2dsyb6n/Song+of+Storms.nbs
but the player can't see it
LBPHacker #7
Posted 18 February 2013 - 03:31 AM
It downloads everything into the "song" folder. Have you tried that? ("ls song" in shell)
Mc_gee #8
Posted 18 February 2013 - 06:03 AM
It downloads everything into the "song" folder. Have you tried that? ("ls song" in shell)

yes the file is in the song folder
LBPHacker #9
Posted 18 February 2013 - 06:05 AM
So what's the matter then?
Mc_gee #10
Posted 18 February 2013 - 06:20 AM
the player can't see the files
Mc_gee #11
Posted 18 February 2013 - 06:27 AM
i think you made a mistake with the folder name it's songs, not song
LBPHacker #12
Posted 18 February 2013 - 08:18 AM
saves/worldname/computers/comp#/song

I don't think so. Or at least I wasn't the one who made the mistake. Anyways, updated. Same pastebin ID, same command.
WeaponMaster #13
Posted 21 February 2013 - 02:38 PM
Save this and run with a parameter that points to an .nbs file on the internet.



if not http then
	print("HTTP API is disabled")
	return false
end
local destination = "song"
local url = ({...})[1]
local httpHandle = http.get(url)
if not httpHandle then
	print("Error downloading file")
	return false
end
if not fs.exists(destination) then fs.makeDir(destination) end
if not fs.isDir(destination) then
	print("Destination must be a directory")
	return false
end
local fileHandle = fs.open(destination .. "/" .. fs.getName(url), "w")
if not fileHandle then
	print("Error opening file")
	return false
end
fileHandle.write(httpHandle.readAll())
httpHandle.close()
fileHandle.close()
print("Done")
thanks :D/>
now i can finnaly play songs on multiplayer!
however, when i tried this out, songs it downloaded would not play. they show up in the program's listing, but when i press the number for any song which was downloaded by this, it returns the error code "play:106: 'for' limit must be a number". i don't think it is a problem with the play program, though i wouldn't know if it was. maybe it is something to do with the way the downloader works? also, can you add a renamer to add .nbs to the file end? if it is not there, it will not be read. i also checked the .nbs file which i downloaded using note block studio, but it could not be read. i think there lies an error with the way the program downloads the files :(/> please help
LBPHacker #14
Posted 22 February 2013 - 02:55 AM
OK then, could you give me a link to the player or something? Because I've tested the downloader and it works fine. (Or at least it does what it is supposed to do.) As you can see, I've had a little argument with Mc_gee some replies earlier, and now the downloader downloads everything into the "song" folder. But, to be honest, I've never seen the player before, so I can't be sure what's wrong.

NVM I've found the player. And yeah, it uses the "songs" folder, not the "song". Thanks a bunch, Mc_gee…

But what did you try to download? http://199.91.154.22...g+of+Storms.nbs is not valid.

So :D/> Downloader updated again, and still can be found here. (EPmXcFs0@pastebin)
LBPHacker #15
Posted 22 February 2013 - 03:14 AM
So I'm here again. Played around a bit with the player, and found out that you can actually tell the player where to search for songs, eg.
 player folderForMySongs 
This way the player will list the songs in "folderForMySongs".

And play:106: 'for' limit must be a number: Exactly what I've expected. Take a look at the file. It's HTML, isn't it? It's because, as I've mentioned it before, the file is unavailable, so our file - that should be a song - is now a 404 error page or something like that.
vSwifty #16
Posted 17 July 2013 - 06:38 PM
So I'm here again. Played around a bit with the player, and found out that you can actually tell the player where to search for songs, eg.
 player folderForMySongs 
This way the player will list the songs in "folderForMySongs".

And play:106: 'for' limit must be a number: Exactly what I've expected. Take a look at the file. It's HTML, isn't it? It's because, as I've mentioned it before, the file is unavailable, so our file - that should be a song - is now a 404 error page or something like that.

Hate to be a necromancer here but this is relevant to my problem, I've been trying to use the downloader but most of the time it says it downloaded the file but when I check the file it's either blank or an HTML.

Is there a site that has DDL so the downloader can only download the NBS file?
LBPHacker #17
Posted 20 August 2013 - 10:09 AM
Guys (oh I'm going to be kicked in the a** for being a necromancer)… There is a huge problem with this program. As every program which uses binary files in CC, this program faces the problem of reading CR characters as LF characters (Java or LuaJ being dumb, not sure which of them) as well. That means 3 byte offset per CR characters. I'm going to patch up this program so it'll able to load files with base64 encoding. That way, you only have to encode your existing music with base64 on a website like this, but I'm going to supply a converter for in-game computers as well.

EDIT: Thought about it a bit… Of course I'm not going to supply an in-game converter, since it'd read the CRs the same crappy way as the player does now.