HydrogenAudio

Hosted Forums => foobar2000 => General - (fb2k) => Topic started by: ayuyaia on 2010-04-11 21:46:13

Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-04-11 21:46:13
While foobar2000 1.01 runs pretty much flawlessly under Wine on ubuntu (just install as portable using Wine 1.1.42 on karmic, or check the corresponding forum posts), the tray notification balloons displaying the current track info do not work.  I'd like to share a fairly easy way to provide these notifications for gnome, using gnome's built-in notification system.

The basic idea is as follows:
1) Use the np_simple plugin to write the "now playing" info to a bash script which, when executed, calls the gnome notification daemon.
2) Use the built-in linux kernel inotify system to automatically run this script whenever it changes, via incron. The advantage of this is a very low overhead compared to constantly polling a file for changes or such.

I'm sure the following setup could be extended and/or made more elegant, but it works nicely, at least for me
In the following, substitute your full foobar2000 directory path wherever you see $FBPATH.

First, install the foo_np_simple plugin (aka Now Playing Simple). Then, use synaptic to install the incron package. If you do not already have the required package for the "notify-send" command, install that as well (run "notify-send --help" from the command line to check).

Run foobar and, in the Now Playing Simple section of the preferences, set:
- the filename to $FBPATH/npnotify (use the Wine (Windows) version of the path of course)
- the encoding to UTF-8 *without* header
- the events you would like to have a notification on
- the formatting string to contain the script:
Code: [Select]
#!/bin/bash$char(10)
notify-send -u normal -t 6000 $if(%ispaused%,
"[%artist% - ][%title%]" "[%album%$char(10)][%playback_time%/][%length%]",
"[%artist% - ][%title%]" "[%album%$char(10)]
$ifequal(%playback_time_seconds%,0,[%length%],[%playback_time%/][%length%])")$char(10)
This is just an example of course - you can modify the script to change the now playing notification. The "-t 6000" sets the length of time the notification balloon is shown in milliseconds. Note the gnome notifications allow for line breaks in the second argument only.

Now play a track to generate the npnotify file. Go to the $FBPATH directory and use "chmod +x npnotify" to make it executable. You can give it a trial run with "./npnotify".

Call up your favourite editor and make a second script file "nprun" in $FBPATH containing
Code: [Select]
#!/bin/bash
$FBPATH/npnotify
"chmod +x nprun" to make it executable. This detour is necessary because for some reason incron doesn't seem to like both watching npnotify for changes and executing it.

Now to set up the incron task. Make sure root can run incron tasks by checking that /etc/incron.allow contains a line "root". Then, enter the command "sudo incrontab -e". This will bring up an editor; add the line
Code: [Select]
$FBPATH/npnotify IN_CLOSE_WRITE $FBPATH/nprun

exit and save.

Everything should now work fine! If not, try restarting the incron daemon: "sudo incrond -k" followed by "sudo incrond"

It would be great if someone were to further improve this setup. In particular, the "notify-send" command has an "-i" option which allows an image to be displayed in the notification balloon. It would be nice to have the correct album art displayed along with the track info...
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: demonAfro on 2010-04-13 23:35:18
Nice post, thanks; had always wondered about doing something like this.

Ran into a small problem (running kde4.4 on gentoo if that matters) where the popup was not showing, but fixed it

Code: [Select]
DISPLAY=:0.0 notify-send ...


or getting the DISPLAY somewhere into the environment works.

Also ran "incrontab -e" as the user (the man page doesn't say you need to be in any groups). The root notifications looked a little bit odd too.

Cheers! 
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-04-14 11:18:51
Glad you liked it! Yes, incron tasks can of course be set for any user - I chose root because I read somewhere that this was recommended, not sure why. Whether it looks any different probably depends on the details of one's configuration, as it doesn't for me.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: Mar2zz on 2010-04-14 11:49:55
nice thx. will look into it.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: Anas on 2010-04-14 19:06:54
Thanks I was looking for a something like this some time now. Had a few attempts myself, but never got anything to work. Unfortunately this doesn't work for me either. Did everything exactly as detailed. icrond is running, but it doesn't seem to detect any changes.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-04-14 19:42:57
You can check to see what incron is actually doing by looking at /var/log/syslog. There will be a line for each time a task is triggered, and/or any error messages. Also, have you tried restarting the daemon, as I mentioned in my original post?
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: FooForThought on 2010-04-16 04:17:20
It would be great if someone were to further improve this setup. In particular, the "notify-send" command has an "-i" option which allows an image to be displayed in the notification balloon. It would be nice to have the correct album art displayed along with the track info...

Here you go:
Code: [Select]
#!/bin/bash

# Author   : Anonymous
# Version : 1.0
# License : n/a
# Date : 2010 04/15
# Requires : foobar2000, foo_np_simple, notify-send
# Script Name : fb2000_notify.sh
# Description : Script to display Now Playing' info via 'foo_np_simple'
# component and 'notify-send'.
#
# Notes   :  n/a
#
# Acknowledge :  thanks to original authors
# Resources  :  n/a
#==============

# -- User Constants - User can specify these variables as necessary -----------
# Location (full path) of 'foo_np_simple' file:
NPFILE='/home/user_name/.wine/drive_c/Program Files/Foobar2000/now_playing/np.txt'
# -
# Directory where you will store cover art thumbnail image used by notify-send.
# Note: using the same directory where the 'foo_np_simple' file is kept might
#   be a good place for the thunmail.
IMGDIR='/home/user_name/.wine/drive_c/Program Files/Foobar2000_02/now_playing'
#-
# Full path to alternate image (if no cover art exists).
IMGALT='/home/user_name/.wine/drive_c/Program Files/Foobar2000_02/default.jpg'
#-
# Specify replacement string for '&' character in message body. See function,
# 'f_fix_notify_bug', notes below.
AMPALT='And'
#-
# Strings to add to image thumbnail file. For example, if original image file
# name 'cover' (excluding extension), then new file will become
# 'cover_thumbnail', assumimg default values are used.
SEP_NAME='_'
IMGFILE_XTRA_NAME='thumbnail'
#-
# Size in pixels of thumbnail image used in 'notify-send' pop-up. This values
# is the height dimension and will automatically generate the width to maintain
# aspect ratio.
THUMB_SIZE=96
#-
# User name for controlling xhost, etc.
NOTIFUNAME='user_name'

# Also see the 'f_convert_image' function to modify image boder, filter,
# unsharp mask, etc. Make a backup copy and play around.


# -- Other Constants - DO NOT CHANGE ------------------------------------------
# Separator between file name and extension
SEP_EXT='.'
# Path separator
SEP_PATH='/'
# Extension for thumbnail image. This must be 'png' as it supports
# transparency necessary for proper display of image in notify-send pop-up.
IMGFILE_CONVERT_EXT='png'

# -- Functions ----------------------------------------------------------------
function f_get_npinfo {
# Get 'Now Playing' info from user-specified file and set some variables
# required by the script. The variables are assigned values based on
# specific lines from the file:
#  Line 1 - used for 'notify-send' message summary
#  Line 2 to Line n-2 - used for 'notify-send' message body
#  Line n-1 - used as the directory to search for 'Now Playing' cover art

count=0
while read -r line; do
line_array[$count]="$line\n"
let count=$count+1
done < "$NPFILE"

msg_line_summary=0
let msg_lines_body=${#line_array[@]}-2
let msg_line_dir=${#line_array[@]}-1

msg_summary=$(echo -e "${line_array[$msg_line_summary]}")
msg_body=$(echo -e "${line_array[@]:1:$msg_lines_body}")
cover_dir=$(echo -n "${line_array[$msg_line_dir]}")

}

function f_fix_notify_bug {
# Notify send fails to print the message body if it contains an ampersand
# (&). It is possible there are other characters that introduce odd
# behavior, but no others have been noted yet. Also, the same behavior did
# not seem to apply to the message summary.

# Remove '&'s from message body and replace with user-specified
# alternative.
msg_body=$(echo "$msg_body" | sed "s/&/${AMPALT}/g")

}

function f_get_image {
# Search directory of currently playing audio file for image file. Image
# file in this directory is assumed to be the cover art image. The image
# will be used to create the thumbnail for the 'notify-send' pop-up.

IFS=$''

cover_dir=$(echo $cover_dir | sed -e 's/[a-zA-Z]://' -e 's/\\n//g' -e 's/\\/\//g')

for item in "${cover_dir}/"*; do
if [ -f "$item" ]; then
mime=$(file -ib "$item")
result=$(echo $mime | grep 'image')
if [ $result ]; then
imgfile="$item"
break
else
imgfile="$IMGALT"
fi
fi
done;

unset IFS

}

function f_convert_image {
# Convert cover art:
#  Step 1: create thumbnail
#  Step 2: apply drop shadow

if [ -n "$imgfile" ]; then
# Resize image
convert -depth 24 \
-background transparent \
-thumbnail x${THUMB_SIZE} \
-quality 100 \
-bordercolor '#000000' \
-border 2x2 \
-filter Lanczos \
-unsharp 0x1.5+1+0 \
"$imgfile" \
"$imgfile_resized"

# Create drop shadow
convert "$imgfile_resized" \
\( +clone -background black -shadow 60x5+10+10 \) \
+swap \
-background transparent \
-layers merge \
+repage \
"$imgfile_resized"
fi

}

function f_notify {
# Create the 'notify-send' pop-up.

# Set some vars
notifuname="$NOTIFUNAME"
namecheck=$(who | grep -E "\b${notifuname}\b")
#notificon="user-info"
notificon="$imgfile_resized"

# Set X display (needed when terminal app launches GUI app)
export DISPLAY=:0.0

# Test whether specified user is logged in
if [ -n "$namecheck" ]; then
# Test whether X is running
isx=$(xdpyinfo | head -20 | grep "X.Org")
# Test whether screen has been blanked by xscreensaver
if [ -n "$isx" ]; then

# Add user to xhost (will be removed before script exits)
# otherwise xscreensaver-command will not work properly.
# [url=http://www.leidinger.net/X/xhost.html]http://www.leidinger.net/X/xhost.html[/url]
xhost +nis:${notifuname}@ > /dev/null

is_scrblank=$(xscreensaver-command -time 2> /dev/null| grep "screen non-blanked")

# Above command issues an error message ('no saver status on
# root window.') if screensaver has not been invoked since daemon
# was started. Therefore, if error status (1), it means the screen
# is not blanked and notifier should be issued to desktop.
is_err=$?

# Debug
# echo $is_scrblank
# echo $is_err

if [ -n "$is_scrblank" ] || [ !"$is_err" ]; then
# Send desktop notification
notify-send \
--icon="$notificon" \
--expire-time=6000 \
--urgency=normal \
"${msg_summary}" "${msg_body}"
fi
fi
fi

# Remove user from xhost
xhost -nis:${notifuname}@ > /dev/null

}

# -- Main ---------------------------------------------------------------------
# Call functions and assign values to additional variables.

f_get_npinfo
f_fix_notify_bug
f_get_image

imgfile_base=$( basename "$imgfile" )
imgfile_base_noext="${imgfile_base%.*}"
imgfile_thumbnail="${imgfile_base_noext}${SEP_NAME}${IMGFILE_XTRA_NAME}${SEP_EXT}${IMGFILE_CONVERT_EXT}"
imgfile_resized="${IMGDIR}${SEP_PATH}${imgfile_thumbnail}"

f_convert_image
f_notify

exit

The above code has a section at the beginning (User Constants) that needs some attention before the script can be used. I don't ordinarily like putting user configuration in scripts, but this was quickly put together (relatively speaking). I definitely should have done it in Perl or Python.

Here is the foo_np_simple code I inserted in foobar2000:
Code: [Select]
$if(%isplaying%,
$if(%TITLE%,%TITLE%,%filename_ext%)
$char(10)
$char(10)
Artist: [%album artist%]
$char(10)
Album: [%album%]
$char(10)
Genre: [%genre%]
$char(10)
Sub-Genre: [%sub-genre%]
$char(10)
$char(10)
%codec% ● %bitrate%kbps ● %samplerate%Hz ● %channels%
$char(10)
$directory_path(%path%)
$char(10),)

Notice a couple of things:

1) the bash script is not part of the text that foo_np_simple sends to its file. The 'now playing' info and the script are kept separate. The script reads in the file data. As such, the incron table entry (I used my regular user account for the table rather than root) looks like this:

Code: [Select]
/some/path\ with\ spaces/now_playing.txt IN_CLOSE_WRITE fb2000_notify.sh

2) The notify-send message takes this form:
Code: [Select]
message summary
message body

The above example formatting text takes the same form but with one added piece of output: the directory where the currently playing audio file is located (it's assumed the cover art is in that directory).

So, a couple of things need to be considered if / when modifying the example I provided:

a. the first entry that creates output to the np_simple file needs to be your desired notify-send summary (conditional functions, etc. that don't produce output to the file don't count ... notice the actual first line of the formatting string is the conditional, %isplaying%). In the above example the first item that produces output (and which will be the notify-send summary) is:
Code: [Select]
($if(%TITLE%,%TITLE%,%filename_ext%)

The entry could be [%genre%] if you like, but I doubt many people would choose that. Bottom line, this entry will be BOLD and set apart above the message body in the notify-send message.

b. A really critical issue is that the last output item MUST be the directory where the album art is located ALWAYS followed by a blank line.
This is taken care of in the example above by the following:
Code: [Select]
$directory_path(%path%)
$char(10)

The reason it is critical is that the directory is required to retrieve the related album art. You should not change this unless you recode the related portions of the script.

Anything that is placed between your desired summary entry and the directory entry (essentially, these items in between are the body of the notify-send message) can be whatever you like with spacing to suit you.

You might want to use my example formatting first to make sure things are working before you venture into modifications.

I think that's it for now.

PS
Unsharp mask on the thumbnail cover art image created by the script is not optimal ... it looks decent, but I wanted it to be visible initially to let you know it was there. Feel free to tweak the settings.

PSS
I don't have any real issues with pretty_pop, and the standard info balloons work for me on mousing-over the tray icon, so I really don't know if this is something I'll continue to use. Coding it was mostly an exercise to see how it could be done.

-- Screen-shot attached:
(http://img202.imageshack.us/img202/4108/foobar2000notifycropsm.th.png) (http://img202.imageshack.us/i/foobar2000notifycropsm.png/)
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: FooForThought on 2010-04-16 13:01:01
I just noticed the header information of the script I posted is a little messed up. I have  templates I use for various scripts (one for bash, perl python etc.), and I didn't clean this one up before posting. It should have read:

Code: [Select]
# Author      : Anonymous
# Version     : 1.0
# License     : n/a
# Date        : 2010 04/15
# Requires    : foobar2000, foo_np_simple, notify-send, incron
# Script Name : fb2000_notify
# Description : Script to display Now Playing' info via 'foo_np_simple'
#               component, 'incron', and 'notify-send'.
#
# Notes       : n/a
#
# Acknowledge : Thanks to HydrogenAudio.com member, ayuyaia, for the inspiration:
#               http://www.hydrogenaudio.org/forums/index.php?showtopic=80221
#
# Resources   : The following resources may be useful for understanding
#               and using this script:
#               http://inotify.aiken.cz/?section=incron&page=about&lang=en
#               http://www.digipedia.pl/man/doc/view/notify-send.1/
#               http://www.galago-project.org/specs/notification/0.9/index.html#introduction
#               http://www.imagemagick.org/
#               http://redskiesatnight.com/2005/04/06/sharpening-using-image-magick/
#               http://www.dylanbeattie.net/magick/filters/result.html
#==============


Also, just an FYI: I had to add my user to group 'incron' to get incron to work properly on Arch. Could be necessary on other systems as well.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-04-16 15:59:52
Wow, thanks FooForThought, nice extension! Looking forward to trying it out...

Btw I used to use foo_popupplus under Windows, but that doen't seem to work with Wine.
Anyway, one advantage of going the notify-sign route is that the notifications are automatically themed to fit in with one's desktop.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: FooForThought on 2010-04-16 16:35:48
Wow, thanks FooForThought, nice extension! Looking forward to trying it out...

Btw I used to use foo_popupplus under Windows, but that doen't seem to work with Wine.
Anyway, one advantage of going the notify-sign route is that the notifications are automatically themed to fit in with one's desktop.


You're welcome.

I use foo_prettypop which requires .Net, and .Net version 2.0 has worked well enough so far with Wine for the purpose of that component. Pretty Popup is very customizable, but it does have a few annoyances on Linux / Wine, especially related to the preferences page in Foobar2000.

Yes, libnotify auto-themes to the user's environment, but it takes its cues from parts of the theme that aren't necessarily what a user would want for pop-ups. I would prefer to be able to set solid colors instead of the two-toned scheme it uses and especially, I would like to be able to change the geometry. The pop-ups scale okay in the vertical dimension automatically according to content, but the width is immutable.

------
By the way, does this forum automatically close editing of posts after a given amount of time (this is really going to make organization of the info difficult)? I thought I had seen many posts here where the authors changed / updated content over long periods of time, but my posts here can no longer be edited. Maybe the only long-term editable content is the first post in a thread?

Anyway, I can't edit my previous posts, and I forgot to include in the 'Requires' section of the script that 'imagemagick' is necessary. It's an important one to have left out, but I did supply a link to the website, so maybe that (or the fact that the script would fail) was a good enough clue to install it.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-04-16 17:15:35
Quote
I use foo_prettypop which requires .Net

Well, it's good to have a couple of different ways to go, depending on one's preferences. Personally, I prefer to avoid having to install .NET.

Quote
Yes, libnotify auto-themes to the user's environment, but it takes its cues from parts of the theme that aren't necessarily what a user would want for pop-ups. I would prefer to be able to set solid colors instead of the two-toned scheme it uses and especially, I would like to be able to change the geometry.

I suspect this depends on the window manager you are using. With gnome on ubuntu and the standard theme, the notifications are solid coloured single-tone with rounded edges, which I quite like.  This suggests to me the details must be customizeable somewhere.

Quote
By the way, does this forum automatically close editing of posts after a given amount of time (this is really going to make organization of the info difficult)?

I encountered the same annoying problem. Maybe there is a workaround?
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: demonAfro on 2010-04-16 17:49:47
I suspect this depends on the window manager you are using. With gnome on ubuntu and the standard theme, the notifications are solid coloured single-tone with rounded edges, which I quite like.  This suggests to me the details must be customizeable somewhere.

I quite like the KDE popup; they are themed the same as the rest of my desktop
(http://imgur.com/noMTl.png)
But as you say not very customisable; the image gets plonked as an icon and everything breaks if the lines are too long. I know other apps can put larger pictures and progress bars, but I think that is well beyond the scope of a simple notify-send.

Also, if you want to bind a keystroke to pop up you could set the action to "touch" your file so incron picks it up.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: FooForThought on 2010-04-16 18:53:36
Quote
I use foo_prettypop which requires .Net

Well, it's good to have a couple of different ways to go, depending on one's preferences. Personally, I prefer to avoid having to install .NET.

Quote
Yes, libnotify auto-themes to the user's environment, but it takes its cues from parts of the theme that aren't necessarily what a user would want for pop-ups. I would prefer to be able to set solid colors instead of the two-toned scheme it uses and especially, I would like to be able to change the geometry.

I suspect this depends on the window manager you are using. With gnome on ubuntu and the standard theme, the notifications are solid coloured single-tone with rounded edges, which I quite like.  This suggests to me the details must be customizeable somewhere.


Yep. Definitely nice to have a few options, especially since all the methods I utilize are dependent on other developers continuing to maintain their software. If one fails due to incompatibilities, I can switch to another. The issue of maintenance is very apparent in this thread as foo_np_simple, foo_prettypop, incron, and Wine .Net support are pretty stale. The only reason I was able to write this script is because I had previously used foo_np_simple with dzen to place the 'now playing' information on the desktop (hey, yet another method  ) and had a copy of 'foo_np_simpe' on my hard-drive. I was otherwise unable to find a copy online, and the developer's site is down.

In regard, to libnotify's pop-up, I can change the two-tone scheme to solid colors, but that puts a severe crimp in my theme's appearance and usability. The vertical strip of color on the left-side of the pop-up is controlled by the Gnome-theme's 'Selected Items' color, and the remainder of the pop-up's color is dependent on the Gnome-theme's 'Input Boxes' color. It's an either or thing, when it could easily be independently configurable. If your pop-ups on Ubuntu are not tied to the Gnome theme n the same way, it is definitely Canonical hacking the source code. The rounded corners I'm not sure about .. may be a hack as well. I have Ubuntu installed, but I haven't upgraded to the latest version, so I'm disinclined to check against an older install.

I'm certainly keeping an open mind about the solution under discussion, however. It's in use right now while I'm listening and typing. Let me know how it works out for you. I'm already formulating responses to stumbling blocks I think you may encounter, but hopefully things go smoothly.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: FooForThought on 2010-04-16 18:57:45
<snip>
Also, if you want to bind a keystroke to pop up you could set the action to "touch" your file so incron picks it up.


Those KDE screen-shots look nice, but they almost buried the best part of your post. Excellent suggestion.

Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-04-16 19:36:50
Quote
I was otherwise unable to find a copy [of foo_np_simple] online

Here is a link to the foo_np_simple plugin (http://skipyrich.com/wiki/Foobar2000:Now_Playing_Simple) which currently works. (I wish I could edit the original post to add it there!)

Regarding future support, I thought that was one of the advantages of going this route, since it only depends on foo_np_simple which I don't think is likely to break because it is so, well, simple (but, famous last words, etc). Incron and libnotify seem unlikely to disappear and do the brunt of the work. The main drawback, as you point out, is the flipside of this: customizing the popup (beyond changing its contents) is totally dependent on what the window manager/libnotify will let you do. (e.g. I quite like the KDE look as well, but it is very different from what I get under gnome on ubuntu 9.10.)

This (http://blogs.gnome.org/mccann/2010/01/31/taking-notice/) is the latest info I could find on libnotify under gnome, maybe it is useful to you if you wish to further investigate customizeability? Unfortunately I couldn't find some more straightforward documentation. I'm rather surprised at this actually, you'd think it would be part of putting together a theme.

Since I was aiming for a rather minimalistic notification popup, and I am very happy with the way it looks on my system already, the method works well for me (at the moment at least - and if things begin to fail I can hope for your pre-formulated responses  ).
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: FooForThought on 2010-04-16 20:00:43
Quote
I was otherwise unable to find a copy [of foo_np_simple] online

Here is a link to the foo_np_simple plugin (http://skipyrich.com/wiki/Foobar2000:Now_Playing_Simple) which currently works. (I wish I could edit the original post to add it there!)


Hmm. Since I began this project day-before-yesterday, http://skipyrich.com/ (http://skipyrich.com/) was unreachable. I originally tried to download the file from the link in the Foobar2000 Wiki section on components at various times. I thought at first maybe just that page had been removed, but the whole domain was unreachable. I had given it up for dead, but it's working now.

Thanks for correcting me on that.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-04-17 00:23:22
Just to add, FYI: Some rooting around reveals that Canonical uses notify-osd (http://macslow.net/?p=454) as its notification daemon (screenshots at that link). Customizing this package seems possible (http://mupuf.org/blog/article/22/) but requires recompiling to change some options. The current state of play regarding linux notification daemons does not seem entirely optimal
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-04-17 14:01:35
For those adding cover art to their notifications: Embedded mp3 (id3v2) album art can easily be extracted via the command line tool eyeD3 (http://eyed3.nicfit.net/) using the -i option. (Btw, on ubuntu, eyeD3 is available via synaptic.)
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: FooForThought on 2010-04-18 01:25:15
For those adding cover art to their notifications: Embedded mp3 (id3v2) album art can easily be extracted via the command line tool eyeD3 (http://eyed3.nicfit.net/) using the -i option. (Btw, on ubuntu, eyeD3 is available via synaptic.)


I began a python / pygtk re-write today just so I could use a config file for my pop-up preferences (color, size, geometry, etc.) instead of relying on notify-send. I'm about 90% complete, not including adding the ability to extract embedded art. The latter seems like a good feature to have, but I don't personally use it, so I'll have to put some thought into how to implement it in such a way that makes sense to the majority of those who might use it.

I'm headed out now, and tomorrow's 'yard-work' day , so it may be Monday or so before I get back here with the script.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-04-18 01:54:36
Quote
I began a python / pygtk re-write today...

Nice one!

Btw eyeD3 is a python module, the command line tool is just a wrapper/demo.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: callisto on 2010-04-18 13:14:01
Nice work!
With my limited linux / scripting knowledge for me the question comes up, if this is also possible for OS X... since I'm using fb2k on a Mac. If it's possible, this would be super duper awesome
Please let me know...
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-04-19 13:21:28
Thought I'd add a screenshot of the gnome/ubuntu notifications with albumart. (Btw, as mentioned above, it seems the image size is fixed for the notify-osd version of notify-sign.)
(http://imgur.com/0w1SK.png)
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: FooForThought on 2010-04-21 14:59:22
Nice work!
With my limited linux / scripting knowledge for me the question comes up, if this is also possible for OS X... since I'm using fb2k on a Mac. If it's possible, this would be super duper awesome
Please let me know...


Since the python version doesn't rely on external (OS-specific) processes (it's pure python), the only thing you would have to worry about is whether you have an application that can monitor file changes. On Linux we're using 'incron', at least that is the consensus in this thread. I don't know what's available for Mac.

----

Speaking of the python version: I said I would post a version Monday or so. Obviously that's changed since it's now Wednesday. When I said the script was 90% complete, it was. I was looking at some refactoring and adding the 'extract image from file' code. Well, I decided to add some additional functionality that isn't that difficult to code, but definitely added to the schedule which is now competing with other obligations. It's also become a little tedious since the 'big bang' of seeing the pop-up work occurred days ago and now it's just refactoring, exception handling, documentation, etc.

I'll get the script posted as soon as I can (I'm not talking months ... just a matter of days). I'll probably post screen-shots first just to let you see what it looks like in the meantime.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: callisto on 2010-04-22 13:23:39
Since the python version doesn't rely on external (OS-specific) processes (it's pure python), the only thing you would have to worry about is whether you have an application that can monitor file changes. On Linux we're using 'incron', at least that is the consensus in this thread. I don't know what's available for Mac.

I tried looking a little bit around for that kind of program. If I understand this perl script (http://www.macosxhints.com/article.php?story=20031001073403810) right, it does the monitoring you say I would need! (website (http://hayne.net/MacDev/WatchFile/))

Now I'm asking me what renders the balloon, the OS? I mean I'm using Growl for other programs, so Growl does that... and somehow I think it would be possible to trigger some growl event. Well, first I'll wait for you to finish the python version, before abusing this thread with my questions...
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-04-22 14:23:07
I have no experience with OS X, but that perl script you posted (while it might work) would not be ideal, since it has to be running continuously in the background. The idea behind incron is that the kernel of your operating system can trigger actions, e.g. whenever a file is modified. I am not sure what the OS X equivalent is - maybe kqueue or FSEvents? (of which I know nothing but the names...)

To render the ballon in the way described in my original post, you need something equivalent to the notify-sign command. Yes, when notify-sign is executed, the operating system (more precisely, its appropriate library) renders the balloon. In fact (doing a quick google) Growl looks like what you need! In particular, growlnotify (http://growl.info/extras.php#growlnotify) which even has a similar syntax to notify-sign.

Whether you have the file watching component (whatever approach you use) call a script that runs growlnotify, or call FooForThought's upcoming python program, basically depends on what you want your notification balloons to look like. In the first case it will be determined to some extent by Growl.

Hope this helps!
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-04-22 15:27:14
Re OS X: a friend suggested maybe launchd - WatchPaths (http://en.wikipedia.org/wiki/Launchd) would work? more info here (http://www.macgeekery.com/tips/all_about_launchd_items_and_how_to_make_one_yourself)
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: callisto on 2010-04-22 16:10:09
Thank you very much, I will check those out...
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: FooForThought on 2010-04-23 10:55:52
Now I'm asking me what renders the balloon, the OS? I mean I'm using Growl for other programs, so Growl does that... and somehow I think it would be possible to trigger some growl event. Well, first I'll wait for you to finish the python version, before abusing this thread with my questions...


As I said previously, the Python version is self-contained except for the 'file-watching' facility.* So, nothing like notify-send or growl is required to generate the pop-ups. They are created with PyGtk code within the script. That was the whole point of switching to Python in the first place: so the pop-ups could be customized.

There are quite a few options currently available in the code for customization (see the screen-shot which contains an image of the config file open in a text editor). You can even change the image from the left-side to the right-side of the pop-up if you desire. The screen-shot only shows color changes, but I promise, everything you see (and even what you can't see) in the config works .


Note:
As ayuyaia pointed out regarding scripting the file-monitoring process (as with the Perl code you found), it is not ideal. If that was the way to go, I could have built that functionality into the Python script easily enough (or even the bash script). Still could. Nah. Hopefully you'll find a suitable alternative for Mac.

Screen-shot:
(http://img693.imageshack.us/img693/3033/fb2000notify2sm3.th.png) (http://img693.imageshack.us/i/fb2000notify2sm3.png/)
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: callisto on 2010-04-23 17:30:29
I guess lauchnd and growlnotify are the programs I need!
So far I've managed to write the bash script with np_simple which works with growlnotify and to monitor this file with a personal lauchnd deamon. I've also got the cover art working... (screenshot (http://i6.photobucket.com/albums/y245/Callistou/foobar2000/foobar-notify.jpg))
Problems: I cannot run the bash script from my deamon (it can only run applications?) and it always openes an annoying terminal window (if startet manually).
But I like what I've got so far
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-04-23 18:09:53
@callisto: Sounds like you're almost there

Quote
Problems: I cannot run the bash script from my deamon (it can only run applications?) and it always openes an annoying terminal window (if startet manually).


No idea what the problem is of course, but you could try running the application "bash" and passing the script as a command line parameter?
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: callisto on 2010-04-27 00:17:23
Hell yeah, I've made it!
Maybe there are some MacUser out there, who want to know how. Here we go:

>> Only tested on Mac OS X 10.6.3 <<

Programs needed:
foo_np_simple (http://skipyrich.com/wiki/Foobar2000:Now_Playing_Simple)
growlnotify (http://growl.info/) (mount Growl-1.2.dmg, install Growl if you don't already have, navigate to Extras/growlnotify, install by following containing instructions)
Lingon (http://sourceforge.net/projects/lingon/files/) to easily create the needed launchd deamon for file monitoring.

Steps:
1:
configure foo_np_simple and create npnotify
example:
Code: [Select]
$if(%isplaying%,#!/bin/bash$char(10)/usr/local/bin/growlnotify -m "[%artist%]" --image ''/path/to/your/music/$directory(%path%)/Front.jpg'' "[%title%]"$char(10)exit 0,)
go here (http://growl.info/extras.php) for more information on how to use growlnotify
(see first post from ayuyaia for complete setup)

2:
- create nprun (see first post)

3:
- launch Lingon
- add new User Deamon
- name it something like com.foobar2000.npnotify
- on "What" choose your nprun file
- on "When" got to "Run it if this file is modified" and choose your npnotify file
- save! (quit Lingon)

4:
reboot to enable your launchd deamon and you're done!
Now everything should work

(http://img227.imageshack.us/img227/4648/foonotifyosx.th.png) (http://img227.imageshack.us/i/foonotifyosx.png/)

Thank you ayuyaia and FooForThought for the initial idea and your help on this!

callisto
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: jacobbrett on 2010-05-08 00:23:11
This looks excellent! I was working on my own script a few weeks before you posted this, but I didn't have time to work out the logic for it. I was having trouble getting the popup to act as Rhythmbox does. (e.g. pausing then playing again doesn't display the title again).
I used foo_np_simple to output the details to a txt file, then wrote a simple bash script with while and for loops to determine when and if to display a popup, using libnotify-bin.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: IvoP123 on 2010-05-24 12:04:50
Here you go: (...)


i'm not very good with this so if someone can explain how to get this working... I modified user constants in script, but now what? Where should i save the script? Do i need to follow the same steps like in first post or what?
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-05-24 16:56:22
@IvoP123: It's probably a good idea to make sure the (simpler) variant from the original post works... at least read it and maybe some of the follow-up posts to understand how it is meant to work. For the version you are talking about, you can put the script (fb2000_notify.sh) anywhere you like (the foobar directory or your home directory are natural choices), the important thing is that the incron table entry points to it (include the complete path there) and that it is executable (use chmod +x).
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: IvoP123 on 2010-05-27 16:14:50
@IvoP123: It's probably a good idea to make sure the (simpler) variant from the original post works... at least read it and maybe some of the follow-up posts to understand how it is meant to work. For the version you are talking about, you can put the script (fb2000_notify.sh) anywhere you like (the foobar directory or your home directory are natural choices), the important thing is that the incron table entry points to it (include the complete path there) and that it is executable (use chmod +x).


Thanks! I managed to get it working. Only thing is that there is no image on popup although cover.jpg is in the same folder as playing file. Anyone got any idea?

One question also... when i play some file and after 1 second i play another, notification of the first file will be displayed for 6 seconds and after that the second will be displayed which is pretty annoying... i would like it to be displayed instantly
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-05-28 02:17:43
Quote
when i play some file and after 1 second i play another, notification of the first file will be displayed for 6 seconds and after that the second will be displayed which is pretty annoying... i would like it to be displayed instantly

The notifications are displayed by the window manager, so if you find a way to tell the window manager to remove the currently displayed notification (if any) you can do this. Not sure if this is possible though.

Quote
Only thing is that there is no image on popup although cover.jpg is in the same folder as playing file.

Try running notify-send from the command line with the option -i .../cover.jpg to check that images are displayed correctly. If that works, investigate the script - probably there is a problem with the directory paths, so it can't find the file at some point... (Btw, if you are using the ubuntu version of gnome, you might want to remove the image resize/dropshadow bit, since the ubuntu notifications have a fixed image size which is quite small.)
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: IvoP123 on 2010-05-28 09:30:24
Quote
Try running notify-send from the command line with the option -i .../cover.jpg to check that images are displayed correctly. If that works, investigate the script - probably there is a problem with the directory paths, so it can't find the file at some point... (Btw, if you are using the ubuntu version of gnome, you might want to remove the image resize/dropshadow bit, since the ubuntu notifications have a fixed image size which is quite small.)


I tried but nofify-send -i doesn't seem to work  It says no summary specified. Tried jpg and png images but no luck... I googled but couldn't find the solution. What could be the problem? 
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-05-28 09:58:20
Odd. Did you try something like
Code: [Select]
notify-send -i "/home/ivop123/foobar2000/coverart/cover.jpg" "Summary" "Body"

(point being to specify the full path)
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: IvoP123 on 2010-05-29 01:16:01
Odd. Did you try something like
Code: [Select]
notify-send -i "/home/ivop123/foobar2000/coverart/cover.jpg" "Summary" "Body"

(point being to specify the full path)


that was the problem. I managed to get it working. Thanks!    So, i guess in ubuntu 10.04 cover is small sized and there is nothing i can do about it?
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-05-29 01:50:37
Quote
So, i guess in ubuntu 10.04 cover is small sized and there is nothing i can do about it?

Not that I know of - it seems to be a limitation of the notify library they are using. See discussion earlier in this thread.
You could ask FooForThought if he could post his python notifications (see above) which were designed to get around this problem...
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: Jacklewis on 2010-05-31 08:54:37
is it possible to move the notify-send position to another part of the screen, or make it fade out slow?
thanks for your contribution works great

http://img709.imageshack.us/f/screenshotlmj.png/ (http://img709.imageshack.us/f/screenshotlmj.png/)
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-06-11 02:01:34
Those wishing to customize the ubuntu notifications (notify-osd) might enjoy playing around with this patched version (nb I have not tried this out myself):
http://lucidfox.org/posts/view/575 (http://lucidfox.org/posts/view/575)
http://m-del.net/2010/04/personnaliser-les...cations-ubuntu/ (http://m-del.net/2010/04/personnaliser-les-notifications-ubuntu/)
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-06-11 11:06:55
Those wishing to customize the ubuntu notifications (notify-osd)...

Turns out there is even a GUI config dialog for this patch:
http://maketecheasier.com/easily-customize...ucid/2010/05/26 (http://maketecheasier.com/easily-customize-notifyosd-ubuntu-lucid/2010/05/26)
(http://images.maketecheasier.com/2010/05/notifyosd-main-screen.png)
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ayuyaia on 2010-06-14 21:14:10
I've now tried out the patched notify-osd and it works great. Many of the size settings seem to be relative to the GONME application font size. It's possible to set larger font sizes (>100%) in the config file (.notify-osd) but not via the GUI.

With the following trick, it's possible to have different notification settings for foobar than for all the other applications using notify-osd (e.g. if you want foobar notifications to have larger images, but other apps not to have huge icons in their notifications): Have incron run as a different user than your usual login (e.g. use root, as suggested in the original post). Then when incron calls the notification script, it will run as that user, who has his own .notify-osd and gnome theme settings of course. So if you change .notify-osd etc only for that user, it won't affect notifications displayed by other applications (e.g. if you use root, .notify-osd goes into the /root directory.)

What does not seem to be possible is centering the text vertically - at least I have not found a way to do this.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: Jacklewis on 2010-07-15 03:18:02
Now I'm asking me what renders the balloon, the OS? I mean I'm using Growl for other programs, so Growl does that... and somehow I think it would be possible to trigger some growl event. Well, first I'll wait for you to finish the python version, before abusing this thread with my questions...


As I said previously, the Python version is self-contained except for the 'file-watching' facility.* So, nothing like notify-send or growl is required to generate the pop-ups. They are created with PyGtk code within the script. That was the whole point of switching to Python in the first place: so the pop-ups could be customized.

There are quite a few options currently available in the code for customization (see the screen-shot which contains an image of the config file open in a text editor). You can even change the image from the left-side to the right-side of the pop-up if you desire. The screen-shot only shows color changes, but I promise, everything you see (and even what you can't see) in the config works .


Note:
As ayuyaia pointed out regarding scripting the file-monitoring process (as with the Perl code you found), it is not ideal. If that was the way to go, I could have built that functionality into the Python script easily enough (or even the bash script). Still could. Nah. Hopefully you'll find a suitable alternative for Mac.

Screen-shot:
(http://img693.imageshack.us/img693/3033/fb2000notify2sm3.th.png) (http://img693.imageshack.us/i/fb2000notify2sm3.png/)


where can i get the config script? and how would I get it to work thanks
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: kode54 on 2011-01-05 12:00:38
Bump from hell to report that the latest wine now supports proper balloon tips, although they're themed Windows 2000 or older style. Better than nothing, I guess.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: jacobbrett on 2011-01-07 23:02:59
Bump from hell to report that the latest wine now supports proper balloon tips, although they're themed Windows 2000 or older style. Better than nothing, I guess.

Great! Though, I can't seem to make the balloon disappear by clicking it...just stays there for a good 10 seconds.
Title: Now Playing notification balloons for foobar on ubuntu+Wine
Post by: ernstblaauw on 2012-02-27 22:06:00
Thanks for this script! I managed to get balloon tips in Ubuntu 11.10. I had to change some parts to get it working:

I guess this is all I had to change, really great to have foobar showing balloons! Thanks for this thread!