By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

how to get information of a running prog in python

P: n/a
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
Jun 27 '08 #1
Share this Question
Share on Google+
9 Replies


P: n/a
On Mon, May 12, 2008 at 10:19 PM, Jimmy <mc**********@gmail.comwrote:
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
--
http://mail.python.org/mailman/listinfo/python-list
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
Jun 27 '08 #2

P: n/a
On May 13, 10:36 am, "Dan Upton" <up...@virginia.eduwrote:
On Mon, May 12, 2008 at 10:19 PM, Jimmy <mcknight0...@gmail.comwrote:
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
--
http://mail.python.org/mailman/listinfo/python-list

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
Jun 27 '08 #3

P: n/a
On Mon, 12 May 2008 19:19:05 -0700, Jimmy wrote:
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
Jun 27 '08 #4

P: n/a
On Mon, May 12, 2008 at 11:02 PM, Jimmy <mc**********@gmail.comwrote:
On May 13, 10:36 am, "Dan Upton" <up...@virginia.eduwrote:

On Mon, May 12, 2008 at 10:19 PM, Jimmy <mcknight0...@gmail.comwrote:
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
--
http://mail.python.org/mailman/listinfo/python-list
>
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
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.
Jun 27 '08 #5

P: n/a
On May 12, 11:02*pm, Jimmy <mcknight0...@gmail.comwrote:
On May 13, 10:36 am, "Dan Upton" <up...@virginia.eduwrote:
On Mon, May 12, 2008 at 10:19 PM, Jimmy <mcknight0...@gmail.comwrote:
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
*--
*http://mail.python.org/mailman/listinfo/python-list
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 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
Jun 27 '08 #6

P: n/a
On Mon, 12 May 2008 20:29:46 -0700, George Sakkis wrote:
On May 12, 11:02┬*pm, Jimmy <mcknight0...@gmail.comwrote:
>On May 13, 10:36 am, "Dan Upton" <up...@virginia.eduwrote:
On Mon, May 12, 2008 at 10:19 PM, Jimmy <mcknight0...@gmail.com>
wrote:
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 --
┬*http://mail.python.org/mailman/listinfo/python-list
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 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
Jun 27 '08 #7

P: n/a
On May 13, 11:18 am, Ivan Illarionov <ivan.illario...@gmail.com>
wrote:
On Mon, 12 May 2008 19:19:05 -0700, Jimmy wrote:
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.
Jun 27 '08 #8

P: n/a
En Tue, 13 May 2008 01:22:52 -0300, Ivan Illarionov
<iv*************@gmail.comescribiˇ:
On Mon, 12 May 2008 20:29:46 -0700, George Sakkis wrote:
>On Mon, May 12, 2008 at 10:19 PM, Jimmy <mcknight0...@gmail.com>
wrote:

*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 --
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.

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"?

--
Gabriel Genellina

Jun 27 '08 #9

P: n/a
On May 13, 4:41 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Tue, 13 May 2008 01:22:52 -0300, Ivan Illarionov
<ivan.illario...@gmail.comescribiˇ:
On Mon, 12 May 2008 20:29:46 -0700, George Sakkis wrote:
On Mon, May 12, 2008 at 10:19 PM, Jimmy <mcknight0...@gmail.com>
wrote:
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 --
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.
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"?

--
Gabriel Genellina
since it's for lyrics displaying. you have to know time of where it is
playing,
the control of user, etc.
Jun 27 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.