=== modified file 'plugins/Makefile' --- plugins/Makefile 2009-02-03 14:10:18 +0000 +++ plugins/Makefile 2009-02-17 10:38:44 +0000 @@ -2,7 +2,7 @@ PLUGINSDIR = /share/exaile/plugins/ INSTALL_PLUGINS = amazoncovers audioscrobbler gnomemmkeys lastfmdynamic \ - lyricwiki notify shoutcast cd lastfmradio + lyricwiki notify shoutcast cd lastfmradio ipod DIST_PLUGINS = amazoncovers audioscrobbler console gnomemmkeys lastfmcovers \ lastfmdynamic lyricsfly lyricwiki notify shoutcast cd lastfmradio \ === added directory 'plugins/ipod' === added file 'plugins/ipod/PLUGININFO' --- plugins/ipod/PLUGININFO 1970-01-01 00:00:00 +0000 +++ plugins/ipod/PLUGININFO 2009-02-17 10:38:23 +0000 @@ -0,0 +1,5 @@ +Version="0.0.1" +Authors=["Andrew Stormont "] +Name="iPod support" +Description="A plugin for iPod support" + === added file 'plugins/ipod/__init__.py' --- plugins/ipod/__init__.py 1970-01-01 00:00:00 +0000 +++ plugins/ipod/__init__.py 2009-02-18 21:10:57 +0000 @@ -0,0 +1,107 @@ +# Exaile 0.2.99 plugin for iPod support, with autodetection +# (c) Copyright 2009 - Andrew Stormont + +import sys +from xl.devices import Device +from xl.collection import Collection +from xl.track import Track, is_valid_track +from xl import providers +from xl import event +import gpod +import dbus + +# iPod device class +class iPod( Device ): + + def __init__( self, volume ): + self.volume = volume + self.name = self.volume.GetProperty( "volume.label" ) + if not self.name: # This ipod has not yet been given a name + self.name = "Apple iPod Music Player" + Device.__init__( self, self.name ) + self.db = None + self.connected = volume.GetProperty( "volume.is_mounted" ) + self.mountpoint = None + self.collection = Collection( "Master" ) + if self.connected: + self.mountpoint = str( volume.GetProperty( "volume.mount_point" ) ) + self.open_db() + self.populate_collection() + + def open_db( self ): + if self.db: + return + else: + self.db = gpod.Database( mountpoint=self.mountpoint ) + + def populate_collection( self ): + for track in self.db.get_master(): + track_path = self.mountpoint + track["ipod_path"].replace(":", "/") + if is_valid_track( track_path ): + track_object = Track( track_path ) + if track_object: + self.collection.add( track_object ) + + def disconnect( self ): + """ + Disconnect (or in this case 'unmount' the ipod) + """ + self.connected = False + self.db = None + + def connect( self ): + """ + Connect (or in this case 'mount' the ipod) + """ + self.connected = True + self.mountpoint = self.volume.GetProperty( "volume.mount_point" ) + self.open_db() + self.populate_collection() + +# iPod provider handled +class iPodHandler( providers.ProviderHandler ): + + name="ipod" + + def __init__( self, service_name="ipod" ): + providers.ProviderHandler.__init__( self, service_name ) + self.bus = None + + def get_udis(self, hal): + # Based on the code from: https://bugs.launchpad.net/exaile/+bug/135915 + self.bus = hal.bus # BAD + ret = [] + dev_udi_list = hal.hal.FindDeviceStringMatch ('portable_audio_player.type', 'ipod') + for udi in dev_udi_list: + vol_udi_list = hal.hal.FindDeviceStringMatch ('info.parent', udi) + for vol_udi in vol_udi_list: + vol_obj = hal.bus.get_object ('org.freedesktop.Hal', vol_udi) + vol = dbus.Interface (vol_obj, 'org.freedesktop.Hal.Device') + # The first partition contains ipod firmware, which cannot be mounted + if int( vol.GetProperty('volume.partition.number') ) != 1: + ret.append( vol_udi ) + return ret + + def is_type( self, device, capabilities ): + parent_udi = device.GetProperty( "info.parent" ) + parent_proxy = self.bus.get_object( "org.freedesktop.Hal", parent_udi ) + parent_iface = dbus.Interface( parent_proxy, 'org.freedesktop.Hal.Device' ) + parent_protocols = parent_iface.GetProperty( "portable_audio_player.access_method.protocols" ) + return ( "ipod" in parent_protocols ) + + def device_from_udi( self, hal, udi ): + device_proxy = hal.bus.get_object( "org.freedesktop.Hal", udi ) + device_iface = dbus.Interface( device_proxy, 'org.freedesktop.Hal.Device' ) + return iPod( device_iface ) + +ipod_provider = None + +def enable( exaile ): + global ipod_provider + ipod_provider = iPodHandler() + providers.register( "hal", ipod_provider ) + +def disable( exaile ): + global ipod_provider + providers.unregister( "hal", ipod_provider ) + ipod_provider = None \ No newline at end of file