Solved

ASP how to create a M3U list

Posted on 2014-04-24
12
553 Views
Last Modified: 2014-04-26
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
0
Comment
Question by:Thomas Grassi
  • 7
  • 5
12 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40021748
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.
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40021790
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40021842
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.
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40023965
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
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40023984
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

0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40024666
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
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 40024702
See my example here http:#a40023984
"playlist_"&Session.SessionID&".txt"
If this worked
set fname=fs.CreateTextFile("m:\playlist\myplaylist.txt",true)

Open in new window

Then based on my sample
set fname=fs.CreateTextFile("m:\playlist\myplaylist_"&Session.SessionID&".txt",true)

Open in new window

Compare mine (top) with  yours
set fname=fs.CreateTextFile("m:\playlist\myplaylist_"&Session.SessionID&".txt",true)
set fname=fs.CreateTextFile("m:\playlist\"myplaylist_"&Session.SessionID&".txt"",true)

Open in new window

0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40024712
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.
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40024784
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?
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40024801
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.
0
 
LVL 23

Author Comment

by:Thomas Grassi
ID: 40024844
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?
0
 
LVL 23

Author Closing Comment

by:Thomas Grassi
ID: 40024867
Scott

Closing this one

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

Thanks for all you help
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now