Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

Paste Description for wfarr

Banshee plugin for Xchat.

wfarr
Saturday, June 30th, 2007 at 9:43:43pm UTC 

  1. #!/usr/bin/python
  2.  
  3. # Banshee Plugin for Xchat
  4. # Copyright (C) 2007  Will Farrington <[email protected]>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  
  19. import xchat
  20. import dbus
  21.  
  22. __module_name__ = "Banshee Plugin for Xchat"
  23. __module_version__ = "1.0"
  24. __module_description__ = "Announce music from and control Banshee Music Player."
  25.  
  26. bus = dbus.SessionBus()
  27.  
  28. class Dbus:
  29.     def __init__(self):
  30.         obj = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
  31.         iface = dbus.Interface(obj, 'org.freedesktop.DBus')
  32.         if 'org.gnome.Banshee' in iface.ListNames():
  33.             banshee_obj = bus.get_object('org.gnome.Banshee', '/org/gnome/Banshee/Player')
  34.             global banshee_iface
  35.             banshee_iface = dbus.Interface(banshee_obj, 'org.gnome.Banshee.Core')
  36.         else:
  37.             xchat.prnt("\002Banshee is not registered with DBus. Please start Banshee.\002")
  38.             return
  39.    
  40.     def grab_track_data(self):
  41.         global track_title
  42.         global track_artist
  43.         global track_album
  44.         global track_rating
  45.         global track_pos
  46.         global track_dur
  47.        
  48.         track_title = banshee_iface.GetPlayingTitle()
  49.         track_artist = banshee_iface.GetPlayingArtist()
  50.         track_album = banshee_iface.GetPlayingAlbum()
  51.         track_rating = banshee_iface.GetPlayingRating()
  52.         track_pos = banshee_iface.GetPlayingPosition()
  53.         track_dur = banshee_iface.GetPlayingDuration()
  54.        
  55.         if track_rating == 0:
  56.             track_rating = "Not Rated."
  57.         else:
  58.             track_rating = "%s/5" % track_rating
  59.            
  60.         track_pos = int(track_pos)
  61.         track_dur = int(track_dur)
  62.         track_pos = "%d:%02d" % (track_pos / 60, track_pos % 60)
  63.         track_dur = "%d:%02d" % (track_dur / 60, track_dur % 60)
  64.  
  65. class Commands:
  66.     def mabout(self, word, word_eol, nil):
  67.         xchat.prnt("\002\037%s\037\002" % __module_name__)
  68.         xchat.prnt(" \002About:\002")
  69.         xchat.prnt(" * Author: Will Farrington <[email protected]>")
  70.         xchat.prnt(" * Script Version: %s" % __module_version__)
  71.         xchat.prnt(" \002Help:\002")
  72.         xchat.prnt(" * \037/media\037 - Displays the currently playing track")
  73.         xchat.prnt(" * \037/prev\037 - Skips to the previous track")
  74.         xchat.prnt(" * \037/stop\037 - Stops playback")
  75.         xchat.prnt(" * \037/play\037 - Starts playback")   
  76.         xchat.prnt(" * \037/pause\037 - Pauses playback")
  77.         xchat.prnt(" * \037/next\037 - Skips to the next track")
  78.         xchat.prnt(" * \037/rate n\037 - Rates the song n/5")
  79.        
  80.     def media(self, word, word_eol, nil):
  81.         Dbus().grab_track_data()
  82.         xchat.command("me is listening to: \"%s\" by %s on %s; Rated: %s (%s/%s)" % (track_title, track_artist, track_album, track_rating, track_pos, track_dur))
  83.        
  84.     def next(self, word, word_eol, nil):
  85.         Dbus()
  86.         banshee_iface.Next()
  87.         xchat.prnt("Skipped to next track.")
  88.        
  89.     def prev(self, word, word_eol, nil):
  90.         Dbus()
  91.         banshee_iface.Previous()
  92.         xchat.prnt("Skipped to previous track.")
  93.    
  94.     def play(self, word, word_eol, nil):
  95.         Dbus()
  96.         banshee_iface.Play()
  97.         xchat.prnt("Started playback.")
  98.    
  99.     def pause(self, word, word_eol, nil):
  100.         Dbus()
  101.         banshee_iface.Pause()
  102.         xchat.prnt("Paused playback.")
  103.        
  104.     def rate(self, word, word_eol, new_rating):
  105.         Dbus().grab_track_data()
  106.         new_rating = int(word[1])
  107.         banshee_iface.SetPlayingRating(new_rating)
  108.         xchat.prnt("Rated \"%s\" by %s a %s/5." % (track_title, track_artist, new_rating))
  109.  
  110. xchat.prnt("Loaded \002%s\002:" % __module_name__)
  111. xchat.prnt("Use \002/mabout\002 to display a list of commands.")
  112.  
  113. mabout_hook = xchat.hook_command("mabout", Commands().mabout)
  114. media_hook  = xchat.hook_command("media", Commands().media)
  115. next_hook   = xchat.hook_command("next", Commands().next)
  116. prev_hook   = xchat.hook_command("prev", Commands().prev)
  117. play_hook   = xchat.hook_command("play", Commands().play)
  118. pause_hook  = xchat.hook_command("pause", Commands().pause)
  119. rate_hook   = xchat.hook_command("rate", Commands().rate)
  120.        
  121. def munload(nil):
  122.     xchat.unhook(mabout_hook)
  123.     xchat.unhook(media_hook)
  124.     xchat.unhook(next_hook)
  125.     xchat.unhook(prev_hook)
  126.     xchat.unhook(play_hook)
  127.     xchat.unhook(pause_hook)
  128.     xchat.unhook(rate_hook)
  129.     xchat.prnt("Thanks for using my script! =)")
  130.  
  131. xchat.hook_unload(munload)

Paste Details

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right