Esempio n. 1
0
 def _grab(self):
     """Grab the media key control."""
     LOG.debug("Grabing media keys")
     self._interface.GrabMediaPlayerKeys(
             "spotty", 0,
             dbus_interface='org.gnome.SettingsDaemon.MediaKeys')
     self._grabbed = True
Esempio n. 2
0
File: core.py Progetto: keto/spotty
 def _call_spotify(self, method):
     """Helper to call spotify method."""
     if not self.connected:
         LOG.debug("Not connected")
         return
     self.spotifyservice.get_dbus_method(method,
             "org.mpris.MediaPlayer2.Player")()
Esempio n. 3
0
File: core.py Progetto: keto/spotty
 def __call__(self, *args, **kwargs):
     try:
         return self._callback(*args, **kwargs)
     except Exception as exc:
         LOG.error("Listener %s (%s, %s) failed:%s" %
                 (self, args, kwargs, exc))
         if not self._ignore_errors:
             raise
Esempio n. 4
0
File: cli.py Progetto: keto/spotty
 def cb_track_changed(self, **info):
     """Spotty track_changed handler."""
     LOG.debug("Track changed")
     if not self._quiet:
         artist = info.get("artist", u"")
         title = info.get("title", u"")
         print("%s - %s" % (artist, title))
     self.terminate()
Esempio n. 5
0
 def notifyservice(self):
     """Lazy binding to dbus notification interface."""
     if self._notifyservice == None:
         try:
             proxy = self.spotify.bus.get_object(
                     "org.freedesktop.Notifications",
                     "/org/freedesktop/Notifications")
             self._notifyservice = dbus.Interface(proxy,
                     "org.freedesktop.Notifications")
         except Exception, exobj:
             LOG.error("Notification service connectin failed: %s" % exobj)
Esempio n. 6
0
File: core.py Progetto: keto/spotty
 def connect(self):
     """Connect to spotify dbus interface."""
     LOG.debug("Connecting")
     try:
         self.spotifyservice = self.bus.get_object(
                 "com.spotify.qt", "/org/mpris/MediaPlayer2")
         self.spotifyservice.connect_to_signal(
                 "PropertiesChanged", self._cb_track_changed)
         self.connected = True
         self.state_changed.send(True)
     except Exception, exobj:
         LOG.error("Connection to Spotify failed: %s" % exobj)
Esempio n. 7
0
File: cli.py Progetto: keto/spotty
def main():
    """Commandline entry point."""
    DBusGMainLoop(set_as_default=True)
    options, _ = parse_opts()
    if options.debug:
        LOG.setLevel(logging.DEBUG)
    if not options.command:
        return

    gobject.threads_init()
    cli = SpottyCLI(options.quiet)
    cli.start()
    cli.send_command(options.command)
    if options.command not in ["Previous"]:
        cli.join(2)
    cli.terminate()
    return 0
Esempio n. 8
0
File: core.py Progetto: keto/spotty
 def _cb_track_changed(self, *args):
     """Metadata change listener."""
     clear_data = {}
     try:
         data = args[1]["Metadata"]
     except (IndexError, KeyError):
         return
     if not data:
         return
     for key, name in META_MAP.items():
         clear_data[key] = data.get(name, None)
     # Parse year
     if clear_data["date"]:
         clear_data["year"] = clear_data["date"].split("-")[0]
     else:
         clear_data["year"] = None
     if isinstance(clear_data["artist"], dbus.Array):
         clear_data["artist"] = " - ".join(clear_data["artist"])
     # TODO: Convert all the dbus data types
     LOG.debug(str(clear_data))
     self._current_track = clear_data
     self.track_changed.send(**clear_data)
Esempio n. 9
0
File: cli.py Progetto: keto/spotty
 def send_command(self, command):
     """Send given command to Spotify."""
     LOG.debug("Sending command")
     if self._spot.connected:
         getattr(self._spot, command)()
         LOG.debug("Command sent")
     else:
         LOG.error("Failed to connect spotify")
Esempio n. 10
0
 def cb_handle_mediakey(self, app, key):
     """Media key event callback."""
     LOG.debug("Media key event %s %s" % (app, key))
     if app != "spotty":
         return
     if self._interface is None:
         LOG.error("Disconnected, but got media key?!?!?!")
         return
     if key not in self.KEY_MAP:
         LOG.debug("No method to handle key %s" % key)
         return
     action = getattr(self.spotify, self.KEY_MAP[key], None)
     if action:
         action()
     else:
         LOG.error("%s has no method %s" %
                 (self.spotify, self.KEY_MAP[key]))
Esempio n. 11
0
File: core.py Progetto: keto/spotty
 def _cb_spotify_spy(self, *args):
     """DBus listener for spying spotify start/quit."""
     try:
         name, old, new = args
     except (ValueError, TypeError):
         LOG.error("Bad values: %s" % args)
     if name != "com.spotify.qt":
         return
     if not old and new:
         LOG.debug("Spotify appeared!")
         self.connect()
     elif old and not new:
         LOG.debug("Spotify went away")
         self.spotifyservice = None
         self.connected = False
         self.state_changed.send(False)
     else:
         LOG.debug("Spotify dbus interface did something weird")
Esempio n. 12
0
 def fetch(self, url):
     """Fetch cover image based on URL."""
     _, file_name = os.path.split(url)
     cover_file, exists = self._check_cache(file_name)
     if not exists:
         LOG.debug("Downloading %s", url)
         try:
             open(cover_file, "w").write(urllib2.urlopen(url).read())
         except Exception:
             LOG.error("Failed to download: %s", url)
             traceback.print_exc()
     else:
         LOG.debug("Cover in cache")
     return cover_file
Esempio n. 13
0
 def cb_track_changed(self, *_, **info):
     """Track change callback listener."""
     if info.has_key("art_url"):
         LOG.debug("fetching art url %s" % info["art_url"])
         return {"cover": self.fetch(info["art_url"])}
Esempio n. 14
0
File: core.py Progetto: keto/spotty
def main():
    """Entry point"""
    # TODO configuration file handling and commandline options
    options, _ = parse_args()
    if options.debug:
        LOG.setLevel(logging.DEBUG)
    DBusGMainLoop(set_as_default=True)
    spotify = SpotifyControl()
    # Load plugins
    enabled = ["GnomeMediaKeys", "Notify", "CoverFetcher"]
    plugins = {}
    LOG.debug("Loading plugins...")
    for entry in pkg_resources.iter_entry_points("spotty.plugin"):
        plugin = entry.load()
        if plugin.__name__ not in enabled:
            LOG.debug("%s not enabled, skipping...", plugin.__name__)
            continue
        LOG.debug("Loading plugin %s", plugin.__name__)
        try:
            plugins[plugin.__name__] = plugin.load(spotify)
        except Exception:
            LOG.error("Failed to load %s", plugin.__name__)
            traceback.print_exc()
    
    # Start the mainloop
    spotify.connect()
    loop = gobject.MainLoop()
    signal.signal(signal.SIGINT, lambda *args: loop.quit())
    loop.run()
    # Unload plugins
    for name, plugin in plugins.iteritems():
        LOG.debug("Unloading %s", name)
        try:
            plugin.unload()
        except Exception:
            LOG.error("Failed to unload %s", name)
            traceback.print_exc()
Esempio n. 15
0
File: cli.py Progetto: keto/spotty
 def terminate(self):
     """Terminates the mainloop."""
     if self._loop.is_running():
         LOG.debug("Terminating mainloop")
         self._loop.quit()
Esempio n. 16
0
File: cli.py Progetto: keto/spotty
 def run(self):
     LOG.debug("Starting mainloop")
     self._loop.run()
     LOG.debug("Mainloop ended")
Esempio n. 17
0
 def _release(self):
     """Release the media key control."""
     LOG.debug("Releasing media keys")
     self._interface.ReleaseMediaPlayerKeys("spotty",
             dbus_interface='org.gnome.SettingsDaemon.MediaKeys')
     self._grabbed = False