Link to home
Start Free TrialLog in
Avatar of Member_2_6492660_1
Member_2_6492660_1Flag for United States of America

asked on

ASP how to create a M3U list

IIS 6
ASP classic
SQL 2008

I have a Music web site that
1. List the entire 34,000 list which you can play any listed song
2. Search box where you can select by artist, album, or name of track from that list you can check any song click on submit and it will present a list of only the selected songs.
From there you can click on any song and play to listen.

I would like to from the check list create a m3u file listing so that you can play all the selected songs without having to click on each one.

Can this be done in ASP? ASP NET? PHP ?

Any ideas on this?

Thanks in advance

Check out my site www.tomsmp3.com
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

I would use the serverside code to search and present the results.

Then use javascript/jquery to listen for the checkbox being checked and take action.

For the search results, you want to limit the amount of songs sent to the browser at once to prevent somebody from scraping them.

Also, I would keep the actual songs outside of the www domain and only call them up/stream  one at a time as needed.

In any case, keep the serverside functions for searching the 35,000 titles and the frontside for display.  Then serverside again to call up the hidden song and stream.  

If you place all 35,000 titles inside the www domain, you are going to get people downloading all of your titles.
Avatar of Member_2_6492660_1

ASKER

I am not sure what an m3u file really is.  I found this link that shows it is a collection of files you can put togehter using vb via file system object (fso) http://vbcity.com/forums/t/16949.aspx

#EXTM3U

then for each song it has 2 line. The first starts with "#EXTINF:", then the length of the song in seconds, then the name(artist - title). The second line is just the directory with filename and extension. Example:

#EXTINF:308,MyArtist - myTitle
C:\My Music\title.mp3

if there are more songs you just append to the file, so 3 more songs would look like:

#EXTINF:308,MyArtist2 - myTitle2
C:\My Music\title2.mp3
#EXTINF:308,MyArtist3 - myTitle3
C:\My Music\title3.mp3
#EXTINF:308,MyArtist4 - myTitle4
C:\My Music\title4.mp3


To create and write a file using fso, read up on http://msdn.microsoft.com/en-us/library/6ee7s9w2(v=vs.84).aspx and http://www.w3schools.com/asp/asp_ref_filesystem.asp
<%
dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("c:\test.txt",true)
fname.WriteLine("Hello World!")
fname.Close
set fname=nothing
set fs=nothing
%>

Open in new window

Notice the path starting with c:\.  Whatever your final path is, that folder has to have write permissions set.  Since you know this code works, you may want to start with this except using the actual path to your server and make sure you can get it to work. If you have issues, it is your folder permissions.

You can call the file whatever you want.  Instead of test.txt, you can use test.m3u.  An m3u file is just a text file with a m3u extension.

Knowing it is just a text file and that file needs to be something like
#EXTM3U
#EXTINF:308,MyArtist2 - myTitle2
C:\My Music\title2.mp3
#EXTINF:308,MyArtist3 - myTitle3
C:\My Music\title3.mp3
#EXTINF:308,MyArtist4 - myTitle4
C:\My Music\title4.mp3

Open in new window

All you need to do is use the WriteLine command as shown above.   Before you do this, make sure you have already made sure the sample works above.  Next, manually write the file in your text editor as you expect it to be.  Test that file out and make sure it works.  Next, use your asp/vb code to create the m3u file as a text file.  It will take an instant. If you have problems, again, check the permissions for the folder.  Open it up in your text editor and compare what you automatically made to what you created manually.  

Good luck and let us know when you get stuck.
Scott

Moving along.

I have the myplaylist.m3u file being created on the servers folder see my code

<%
if request.form<>"" then

dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("m:\playlist\myplaylist.txt",true)

strSongs=request.form("selectItem")
arraySongs=split(strSongs,",")
response.write "<ul>"
for each song in arraySongs
   response.write "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>" 
   
   fname.WriteLine "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>" 
   
   next
response.write "</ul>" 

fname.Close

else
response.write "You did not post any data yet<br>"
end if

set fname=nothing
set fs=nothing

%>
<input type="button" value="BACK!"onClick="history.back();">

Open in new window



I have two questions

1. Any way I can find out who is connected and grab that information so I can uniquely name the myplaylist.m3u file if two people create a playist then one will overlay the other.
reference this statement
set fname=fs.CreateTextFile("m:\playlist\myplaylist.txt",true)
would like to make myplaylist.txt a unique name
PS the file name is left as a .txt so I can easily open the file to see the output
once I get it fixed I will make them .m3u files

2. the frame.WriteLine code I need help on

The way it is now it produces this output  

I need the output to look like this

http://www.tomsmp3.com/mp3/mp3musicalbums/10CC/Billboard%20Top%20100%20-%201975/01-Billboard%20Top%20100%20-%201975-42%20I'm%20Not%20In%20Love.mp3
http://www.tomsmp3.com/mp3/mp3musicalbums/10CC/Billboard%20Top%20100%20-%201975/01-Billboard%20Top%20100%20-%201975-42%20I'm%20Not%20In%20Love2.mp3
http://www.tomsmp3.com/mp3/mp3musicalbums/10CC/Billboard%20Top%20100%20-%201975/01-Billboard%20Top%20100%20-%201975-42%20I'm%20Not%20In%20Love3.mp3 

After this is working I will add a button to like to the m3u file I am working on that code now
myplaylist.txt
1) Each visit generates a session. http://www.w3schools.com/asp/prop_sessionid.asp
 If you try <% response.write(Session.SessionID)%> you will see a number.

This means you can name the file "playlist_"&Session.SessionID&".txt"

1b) You will end up with a lot of files so you will want to run a routine every day at 3am that deletes all the files in the folder.  
http://www.w3schools.com/asp/met_deletefile.asp
http://www.4guysfromrolla.com/webtech/faq/FileSystemObject/faq4.shtml
<%
dim fs
Set fs=Server.CreateObject("Scripting.FileSystemObject")
fs.DeleteFile("m:\playlist\playlist_*.txt")
set fs=nothing
%>

Open in new window


2) urlencode http://www.w3schools.com/asp/met_urlencode.asp
   fname.WriteLine "<li><a href=""" &URLEncode(replace(song,"M:\Music","/mp3")) & """>" & song & "</a></li>" 

Open in new window

Scott

Having a problem getting the session id in the file name

<%
if request.form<>"" then
dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("m:\playlist\"myplaylist_"&Session.SessionID&".txt"",true)
strSongs=request.form("selectItem")
arraySongs=split(strSongs,",")
response.write "<ul>"
for each song in arraySongs
   response.write "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>" 
   
   fname.WriteLine "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>" 
   
   next
response.write "</ul>" 
fname.Close
else
response.write "You did not post any data yet<br>"
end if
set fname=nothing
set fs=nothing
%>
<input type="button" value="BACK!"onClick="history.back();">

Open in new window


What am I missing
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Scott


Now I have myplaylist_ssid.txt files being created.
Thanks
I can't figure out the syntax I need more practice.

Now onto the fname.writeline

I make one change at a time so I know what is going on will post later with results.
Scott

Http 500 on the fname.writeline code you gave me

Here is my code now:

<%
if request.form<>"" then
dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("m:\playlist\myplaylist_"&Session.SessionID&".txt",true)
strSongs=request.form("selectItem")
arraySongs=split(strSongs,",")
response.write "<ul>"
for each song in arraySongs
   response.write "<li><a href=""" & replace(song,"M:\Music","/mp3") & """>" & song & "</a></li>" 
   
   fname.WriteLine "<li><a href=""" &URLEncode(replace(song,"M:\Music","/mp3")) & """>" & song & "</a></li>"   
   
   next
response.write "</ul>" 
fname.Close
else
response.write "You did not post any data yet<br>"
end if
set fname=nothing
set fs=nothing
%>
<input type="button" value="BACK!"onClick="history.back();">

Open in new window


What am I missing?
I don't know.  500 error is generic. You need to turn on sending errors to the browser when you are developing.

What have you tested?  

Some possible clues....
http://msdn.microsoft.com/en-us/library/ms972338.aspx
http://www.w3schools.com/asp/prop_sessionid.asp
http://msdn.microsoft.com/en-us/library/ms524326(v=vs.90).aspx

Break it down to pieces.  Go back and try just the hard coded text to make sure that is the case.  Next, try a simple page sending the session id to the screen. I have already given you that code on this thread.   If you can't get the session id to the screen, you may read in the msdn link I  provided that it is based on cookies and you may have cookies turned off.   This method is not fool proof and you might need another way.  Perhaps people logging in, or testing that they have cookies enabled and if they don't, give them a message to turn them on.    

Start by simply testing sending the session id to the screen.
Scott

The session.sessionid is working.

The line of code that is not working is this

fname.WriteLine "<li><a href=""" &URLEncode(replace(song,"M:\Music","/mp3")) & """>" & song & "</a></li>"

The HTTP 500 errors I have the options turned on but it does not show me any more information

That is another issue that I need to address later.

I know what line it is because it is the only line I changed
Like I said before I only make one change at a time to know where I am at.

What is wrong with the line above?
Scott

Closing this one

Going to Open a new one for the fname.writeline problem.

Thanks for all you help