Plsplay: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
A very handy script to allow easy command line playback of a "pls" file. Uses a [[regular expression]] to suck out a URL and feed it to mplayer for playback.
= plsplay =


== Discussion ==
A script to ....


Annoyingly, mplayer can't be used to directly play a "pls" file (common format for Internet radio stations). However, mplayer almost always *can* be used to play the stream, you just need to feed it the direct URL of the stream, which listed in the pls file itself (the pls is simply a text file giving one or more possible URLs of the feed). In this case, a simple Python script extracts the URLs and passes it on to mplayer to do the actual work. An optional numeric parameter inidicates which URL to use if multiple URLs are present in the file.
== Usage ==


== Code ==
<source lang="bash">
ls *.pls
plsplay wfmu.pls
</source>


<source lang="python">
#!/usr/bin/python


import re, sys, os


"""
<source lang="bash">
usage:
plsplay wfmu.pls 2
plsplay pls-or-other-textfile-path [index] [dumpfile]
</source>


where:
index is a 1-based index in case of multiple URL matches
"""


# urlfinder = re.compile(r"([a-z]+://[-a-zA-Z0-9./?=&+%_:]*)")
== Code ==
urlfinder = re.compile(r"[a-z]+://[-a-zA-Z0-9./?=&+%_:]*")


# read groupindex (1-based), ie which URL match to use
[[Include(source:cookbook plsplay)]]
# default is first matched URL
groupindex = 1
if len(sys.argv) >= 3:
groupindex = int(sys.argv[2])
 
# optional dump file
dumpfile = None
if len(sys.argv) >= 4:
dumpfile = sys.argv[3]
 
inp = open(sys.argv[1])
fc = inp.read()
 
matches=urlfinder.findall(fc)
if len(matches) > 0:
url = matches[groupindex-1]
 
if url:
print "found url:", url
if dumpfile:
os.system("mplayer -slave %s -dumpstream -dumpfile %s & sleep 5; (cat %s | mplayer -cache 32000 -)" % (url, dumpfile, dumpfile))
else:
os.system("mplayer %s" % url)
else:
print "no url found"
</source>

Latest revision as of 20:29, 23 September 2010

plsplay

A script to ....

Usage

ls *.pls
plsplay wfmu.pls


plsplay wfmu.pls 2


Code

Include(source:cookbook plsplay)