how to get information of a running prog in python

J

Jimmy

Well, i know it may be a little non-python thing, however, I can think
of no place better to post this question :)

can anyone tell me, in python, how to obtain some information of a
running program?
paticularly, if i am playing some music in audacious or other media
player, how can i get the the name and some other info of current
playing song? It seems that audicious doesn't output on run-time
 
D

Dan Upton

Well, i know it may be a little non-python thing, however, I can think
of no place better to post this question :)

can anyone tell me, in python, how to obtain some information of a
running program?
paticularly, if i am playing some music in audacious or other media
player, how can i get the the name and some other info of current
playing song? It seems that audicious doesn't output on run-time

In most cases, you'll probably need some sort of API, either in the
program itself or through some sort of plugin, that lets external
programs query it. For instance, there are some plugins to WinAmp
that allow external programs (like Last.FM or Mog-O-Matic) to see what
track is currently playing. You may also be able to do something like
get the window title (again, WinAmp's title bar usually includes the
artist and title) and parse it out. I don't really know that there's
anything specific to Python for accessing these though, and it may
vary depending on media player.

Just my two cents...

-dan
 
J

Jimmy

In most cases, you'll probably need some sort of API, either in the
program itself or through some sort of plugin, that lets external
programs query it. For instance, there are some plugins to WinAmp
that allow external programs (like Last.FM or Mog-O-Matic) to see what
track is currently playing. You may also be able to do something like
get the window title (again, WinAmp's title bar usually includes the
artist and title) and parse it out. I don't really know that there's
anything specific to Python for accessing these though, and it may
vary depending on media player.

Just my two cents...

-dan

thanks!

In linux, I am always obfuscated by sort of APIs. Like how to get
title information of a running program?
where am I supposed to find these APIs
 
I

Ivan Illarionov

Well, i know it may be a little non-python thing, however, I can think
of no place better to post this question :)

can anyone tell me, in python, how to obtain some information of a
running program?
paticularly, if i am playing some music in audacious or other media
player, how can i get the the name and some other info of current
playing song? It seems that audicious doesn't output on run-time

In case of Audatious running on X11 all you need is Python X library
http://python-xlib.sourceforge.net/

And something like:

from Xlib import display

dpy = display.Display()
root = dpy.screen().root

NET_WM_NAME = dpy.intern_atom('_NET_WM_NAME')
UTF8_STRING = dpy.intern_atom('UTF8_STRING')

for win in root.query_tree().children:
try:
window_title = win.get_full_property(NET_WM_NAME,
UTF8_STRING).value
except AttributeError:
continue
if window_title.endswith('Audacious'):
song = window_title.split(' - ')[:-1]
if song:
print song

-- Ivan
 
D

Dan Upton

thanks!

In linux, I am always obfuscated by sort of APIs. Like how to get
title information of a running program?
where am I supposed to find these APIs

In the documentation for each application? Somebody a little more
familiar with the specific apps you're interested in might be able to
help you more, especially in the case of open-source programs that
usually have developer communities. Also, you can find some
information (although I don't know that it'll be enough to help you)
in files in /proc/$pid on Linux -- type 'man proc' in your shell to
see what you can get out of it and if anything looks helpful for you.
 
G

George Sakkis

thanks!

In linux, I am always obfuscated by sort of APIs. Like how to get
title information of a running program?
where am I supposed to find these APIs

I think you're a little confused about how computers work in general
and what a program can do, and you expect there is some general
superprogram able to decipher what an arbitrary other running program
does. The sentence "how to get title information of a running program"
doesn't even make sense for most programs since they don't play music
anyway.

Your best bet is if the *specific* program you're interested in (e.g.
audacious) exposes this information programmatically in some way. It's
up to the developers of this application if and how they choose to do
it. Even if they do it, there's no requirement that the same API will
work for any other program of the same category, unless there is some
popular industry standard that most applications implement.

In short, you'll get more helpful replies at the audacious newsgroup.

HTH,
George
 
I

Ivan Illarionov

I think you're a little confused about how computers work in general and
what a program can do, and you expect there is some general superprogram
able to decipher what an arbitrary other running program does. The
sentence "how to get title information of a running program" doesn't
even make sense for most programs since they don't play music anyway.

Your best bet is if the *specific* program you're interested in (e.g.
audacious) exposes this information programmatically in some way. It's
up to the developers of this application if and how they choose to do
it. Even if they do it, there's no requirement that the same API will
work for any other program of the same category, unless there is some
popular industry standard that most applications implement.

In short, you'll get more helpful replies at the audacious newsgroup.

HTH,
George

George, have you read my post in this thread? What OP wants is actually
possible and it's quite easy. X server is the "superprogram" that knows
the names of all GUI window titles.

-- Ivan
 
J

Jimmy

Well, i know it may be a little non-python thing, however, I can think
of no place better to post this question :)
can anyone tell me, in python, how to obtain some information of a
running program?
paticularly, if i am playing some music in audacious or other media
player, how can i get the the name and some other info of current
playing song? It seems that audicious doesn't output on run-time

In case of Audatious running on X11 all you need is Python X libraryhttp://python-xlib.sourceforge.net/

And something like:

from Xlib import display

dpy = display.Display()
root = dpy.screen().root

NET_WM_NAME = dpy.intern_atom('_NET_WM_NAME')
UTF8_STRING = dpy.intern_atom('UTF8_STRING')

for win in root.query_tree().children:
try:
window_title = win.get_full_property(NET_WM_NAME,
UTF8_STRING).value
except AttributeError:
continue
if window_title.endswith('Audacious'):
song = window_title.split(' - ')[:-1]
if song:
print song

-- Ivan

Thanks!
I also found a thing called 'audacious announcer' which can output
detail information of the playing track.
actually I'm working on a small program to display lyrics while
playing music in media player.
 
G

Gabriel Genellina

En Tue, 13 May 2008 01:22:52 -0300, Ivan Illarionov
George, have you read my post in this thread? What OP wants is actually
possible and it's quite easy. X server is the "superprogram" that knows
the names of all GUI window titles.

That relies on the fact that audacious (or whatever player used) actually
includes the song name as part of its window title. As G. Sakkis said,
this depends on the specific program used. And what about "some other info
of current playing song"?
 
J

Jimmy

En Tue, 13 May 2008 01:22:52 -0300, Ivan Illarionov
<[email protected]> escribió:





That relies on the fact that audacious (or whatever player used) actually
includes the song name as part of its window title. As G. Sakkis said,
this depends on the specific program used. And what about "some other info
of current playing song"?

since it's for lyrics displaying. you have to know time of where it is
playing,
the control of user, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top