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


Groups > comp.lang.python > #68512 > unrolled thread

Re: extract stream title from the output of mplayer

Started byJabba Laci <jabba.laci@gmail.com>
First post2014-03-18 18:51 +0100
Last post2014-03-18 18:51 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#68512 — Re: extract stream title from the output of mplayer

FromJabba Laci <jabba.laci@gmail.com>
Date2014-03-18 18:51 +0100
SubjectRe: extract stream title from the output of mplayer
Message-ID<mailman.8256.1395165114.18130.python-list@python.org>
> 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())

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web