Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68512

Re: extract stream title from the output of mplayer

References <CAOuJsM=ehKxRDmJ=2HXUCi6OZ8g0OBjQG87RQ+NWuCeBFKKedw@mail.gmail.com> <CAPTjJmp7QYgW_6fsJ91-roGD-DwHD_s=s_HaD14SxvwrbiK9Aw@mail.gmail.com>
From Jabba Laci <jabba.laci@gmail.com>
Date 2014-03-18 18:51 +0100
Subject Re: extract stream title from the output of mplayer
Newsgroups comp.lang.python
Message-ID <mailman.8256.1395165114.18130.python-list@python.org> (permalink)

Show all headers | View raw


> Python. (Or s/guess/hop/ if you prefer!) There are many ways this
> could be done; what have you tried, what partly worked, what did
> something unexpected?

Hi,

I managed to solve the problem. In the man of mplayer I found how to
quit after X seconds: "-endpos X". See my solution below.

Best,

Laszlo

============

import re
import shlex
from subprocess import PIPE, Popen

URL = 'http://relay2.slayradio.org:8000/'


def get_exitcode_stdout_stderr(cmd):
    """
    Execute the external command and get its exitcode, stdout and stderr.
    """
    args = shlex.split(cmd)

    proc = Popen(args, stdout=PIPE, stderr=PIPE)
    out, err = proc.communicate()
    exitcode = proc.returncode
    #
    return exitcode, out, err


def get_title():
    cmd = "mplayer -endpos 1 -ao null {url}".format(url=URL)
    out = get_exitcode_stdout_stderr(cmd)[1]

    for line in out.split("\n"):
#        print(line)
        if line.startswith('ICY Info:'):
            match = re.search(r"StreamTitle='(.*)';StreamUrl=", line)
            title = match.group(1)
            return title

def main():
    print(get_title())

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: extract stream title from the output of mplayer Jabba Laci <jabba.laci@gmail.com> - 2014-03-18 18:51 +0100

csiph-web