I am writing a simple Python interface to play and record Internet radio channels (e.g. from shoutcast) using mplayer (in a subprocess). When a user clicks on a station, the following code is run:
url = http://77.111.88.131:8010 # only an example cmd = "mplayer %s" % url p = subprocess.Popen(cmd.split(), shell=False) wait = os.waitpid(p.pid, 1) return int(p.pid)
This works great, the flow begins to play as it should. Although I would like to somehow parse the name of the stream. It seems I need to get the name from mplayer output. This is the output when I play the stream in the terminal:
$ mplayer http://77.111.88.131:8010
MPlayer 1.0rc4-4.4.5 (C) 2000-2010 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing http://77.111.88.131:8010.
Resolving 77.111.88.131 for AF_INET6 ...
Couldn't resolve name for AF_INET6: 77.111.88.131
Connecting to server 77.111.88.131 [77.111.88.131]: 8010 ...
Name: Justmusic.Fm
Genre: House
Website: http://www.justmusic.fm
Public: yes
Bitrate: 192kbit / s
Cache size set to 320 KBytes
Cache fill: 0.00% (0 bytes)
ICY Info: StreamTitle = '(JustMusic.FM) Basement - Zajac, Migren live at Justmusic 2010-10-09'; StreamUrl = 'http: //www.justmusic.fm';
Cache fill: 17.50% (57344 bytes)
Audio only file format detected.
Then it starts until it stops. So the question is, how can I get "Basement" (JustMusic.FM) - Zajac, Migren live on Justmusic 2010-10-09 "and still allow the process? I don’t think subprocess () actually saves the output, but I could be wrong. Any help is greatly appreciated :)
source share