Little help neededForum: Programming and Scripting Topic: Little help needed started by: Zucca Posted by Zucca on Jan. 30 2007,09:45
I got an idea of web radio with only few components...I plan to use < poc > to stream my mp3's to web. I can tke stream from standard input. But afaik it cannot take raw stream. If it could it would be easy to just generate playlist and play it with mpg123 using -s switch. So I managed to get it working with this: cat `cat playlist.m3u`. This will simply ouput everything inside those files specified in 'playlist.m3u'. Ok it's missing continous play and ramdomization etc... But the main problem is that if there's a space(s) in the paths of mp3-files then cat cuts the line there and assumes that was the path of the file and then tires to find a file which is a rest of the path after the space. Example: /home/dsl/My Music/song.mp3 cat sees that as two files: ''/home/dsl/My' AND 'Music/song.mp3'. I've been trying to use sed to work around this problem, but I haven't got any solution for this problem. Any help? Posted by Zucca on Jan. 30 2007,09:56
Hmm. I might found a solution to this, but It's abit "CPU" consuming...
So after decoding mp3's with mpg123 then encode back to mp3 format suitable for streaming and output them directly to poc. I could say this operation as "tweaking it to work". EDIT: Well I could get only rumble out of it... (at few points I still could hear music.) I tested it by outputting lame's data to a file and then listen it with xmms. EDIT2: Okay. Now it works fine. I used wav stream instead of raw between mpg123 and lame. Here's what I did:
But I'd like to know a way to stream files in my playlist without any encoding/decoding... Posted by mikshaw on Jan. 30 2007,14:53
Ok, if we can back up before you started encoding the files, you said they would stream fine but you had trouble with the format of the playlist. Is this correct?So my gess is all you need to do is find out how to create a properly formatted playlist. I have some questions: What should a poc playlist look like? This is probably the most important issue. Why are you using that redundant cat command? Do you already have playlists made that you're trying to convert? Is creating a playlist from scratch an option? Posted by Zucca on Jan. 30 2007,17:09
M3u playlist simply contain a path in each line (some might have commented lines). These paths are paths to music files. See it for yourself:
Now if you cat file like this it will display just path's to music files on your screen. But if you grab the output of cat and paste it into another cat's as commandline arguments then prints the contents of these files specified in that list. For example: If you have a text file (named index.txt) containing text:
Then you execute:
Well m3u playlist format if the most simple way since only return character is used as mark that seperates the paths. Now. Only problem with cat and this playlist is if the path contains spaces. I need to make it understand that space is not end of file's path, only return character can determine it. Posted by mikshaw on Jan. 30 2007,19:04
I think I misunderstood what you were doing.Do you need both mp321 and poc to do this? I was thinking poc was a player, but i guess I was wrong? I'm not seeing where encoding/decoding is related to filenames with spaces. Are you having two separate problems here? It sounds like you jumped from one issue to the other and back again without fully addressing either issue? Posted by ^thehatsrule^ on Jan. 30 2007,19:09
If you plan on using sed, you could use "s/ /\ /g"If you plan on using a shell script, you could use IFS (i.e. IFS=" " or use 'read') Or you could just remember to never use spaces in filenames :P Posted by Zucca on Jan. 30 2007,20:35
I tried that sed command and it didn't worked.I'm thinking It should be sed -e 's/ /\\ /g'. But I'm not sure about that. Anyway. Everybody needs to sleep sometimes. And now is my time. I'm thinking this over tomorrow. Posted by ^thehatsrule^ on Jan. 30 2007,20:44
Ah you're right, I forgot the double \\ for escape and that single quotes are needed for non-sub.
Posted by Zucca on Jan. 31 2007,18:54
Well It didn't. =D I did like this:
It really printed: "one\ two\ three" But if I had e file named "one two three" and I did this:
It would print an error message like this:
So cat still thinks that "one two three" is actually three seperate files. Posted by mikshaw on Jan. 31 2007,20:04
while read line; docommands done < playlist I still have very little idea of what you're trying to accomplish, but the above inputs lines literally. The cat command should do the same, so I'm thinking there is a problem with the way poc or mpg321 is reading the input. I have an mpg321 script that also didn't work with spaces in filenames, but wrapping the variable which represents the filename in quotes fixed the problem:
Of course this runs a unique instance of mpg321 for each song rather than using a playlist, but the point is that I needed the filename in quotes. Posted by ^thehatsrule^ on Jan. 31 2007,22:01
Heh, what happens if you put double quotes around the outer cat?Personally, I'd just use IFS - it's easy to do and read. Posted by Zucca on Feb. 01 2007,05:38
I don't understad this... You are creating a variable here containing only one return char? EDIT
Now I may know what you mean... Posted by Zucca on Feb. 01 2007,05:53
It worked just fine.But. I'd like to have it on one line. So I did this:
Now It should work but it ain't. =D It tells me:
When it should tell:
Ok. I'm just about to... "Lose it. It means go crazy. Nuts. Insane. Bonzo. No longer in possession of one's faculties. Three fries short of a Happy Meal. WACKO!!" Posted by ^thehatsrule^ on Feb. 01 2007,06:34
Well... you'd have to use something like a for loop to do that...IFS=`printf "\n"`; for each_line in `cat list.txt`; do; cat "$each_line"; done IFS is a special variable in posix shells that indicate the field separator (or something along those lines - usually set to whitespace) Either way, you'll have a couple solutions... just choose one :P Posted by WDef on Feb. 03 2007,20:41
It's probably not worth trying to get things on one line. Using command substitution (backticks) will fail once you get to a certain size and needs to be avoided if you want to process a lot of files.This is what I'd probably do:
This has the advantage that your list of filenames list.txt can be arbitrarily long. Not tried with busybox. Posted by WDef on Feb. 05 2007,12:58
Since I have nothing better to do -Perl gobbles lines at once. Type this in a shell:
Posted by Zucca on Feb. 13 2007,18:08
I think solution to give mp3 stream to poc via stdin in a simple way is something like this:loop (read list of files; ramdomize order;) { cat random mp3 } | poc Poc must be running all the time or clients listening it will be disconnect. That's why we cannot do like this: loop { cat random_mp3 | poc } But I think best way is to make mpg123 to ouput wav stream to lame and then output newly encoded, (low bitrate) stream to poc. Advantages: lower bandwidth usage, no need to make script that randomizes playlist. Disadvantages: more CPU usage. Posted by Zucca on Feb. 13 2007,18:13
BTW.Is there a simple way to grab speaker output? I would like to do something like this: cat /dev/speakers | lame <swithches> | poc Then people could hear what I listen on my computer... ;) Posted by chaostic on Mar. 16 2007,06:31
I know I'm way late on this, but saw this during a search and I figured out how to fix your problem with cating filenames with spaces.
This has cat read the m3u, piping it into sed with changes all the spaces to "\ ". Sed then outputs it to standard out which is redirect to the new file temp.txt, which is identical to mp3list.m3u except for the \s. Then, after that command is done, you redo the recursive cat and pipe that to poc. & to background it if needed/wanted. |