Example #1
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self, server, **kwargs)

        self.next_id = 1000
        self.config = kwargs
        self.name = kwargs.get("name", "gallery2Store")

        self.wmc_mapping = {"16": 1000}

        self.update_id = 0
        self.store = {}

        self.gallery2_server_url = self.config.get("server_url", "http://localhost/gallery2")
        self.gallery2_username = self.config.get("username", None)
        self.gallery2_password = self.config.get("password", None)

        self.store[1000] = Gallery2Item(
            1000,
            {"title": "Gallery2", "gallery2_id": "0", "mimetype": "directory"},
            None,
            "directory",
            self.urlbase,
            Container,
            update=True,
        )
        self.store[1000].store = self

        self.gallery2_remote = Gallery(self.gallery2_server_url, 2)
        if not None in [self.gallery2_username, self.gallery2_password]:
            d = self.gallery2_remote.login(self.gallery2_username, self.gallery2_password)
            d.addCallback(lambda x: self.retrieveAlbums("0", self.store[1000]))
            d.addCallback(self.init_completed)
        else:
            d = self.retrieveAlbums("0", self.store[1000])
            d.addCallback(self.init_completed)
Example #2
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self, server, **kwargs)

        self.next_id = 1000
        self.config = kwargs
        self.name = kwargs.get('name', 'gallery2Store')

        self.wmc_mapping = {'16': 1000}

        self.update_id = 0
        self.store = {}

        self.gallery2_server_url = self.config.get('server_url', 'http://localhost/gallery2')
        self.gallery2_username = self.config.get('username', None)
        self.gallery2_password = self.config.get('password', None)

        self.store[1000] = Gallery2Item(1000, {'title': 'Gallery2', 'gallery2_id': '0', 'mimetype': 'directory'}, None,
                                                        'directory', self.urlbase, Container, update=True)
        self.store[1000].store = self

        self.gallery2_remote = Gallery(self.gallery2_server_url, 2)
        if not None in [self.gallery2_username, self.gallery2_password]:
            d = self.gallery2_remote.login(self.gallery2_username, self.gallery2_password)
            d.addCallback(lambda x: self.retrieveAlbums('0', self.store[1000]))
            d.addCallback(self.init_completed)
        else:
            d = self.retrieveAlbums('0', self.store[1000])
            d.addCallback(self.init_completed)
Example #3
0
    def __init__(self, server, **kwargs):

        if server.coherence.config.get('use_dbus', 'no') != 'yes':
            raise Exception('this backend needs use_dbus enabled in the configuration')
        BackendStore.__init__(self, server, **kwargs)

        self.config = kwargs
        self.name = kwargs.get('name', 'Tracker')

        self.update_id = 0
        self.token = None

        self.songs = 0
        self.albums = 0
        self.artists = 0
        self.playlists = 0
        self.genres = 0

        self.videos = 0
        self.images = 0

        self.bus = dbus.SessionBus()
        tracker_object = self.bus.get_object(BUS_NAME, OBJECT_PATH)
        self.tracker_interface = dbus.Interface(tracker_object, 'org.freedesktop.Tracker')
        self.search_interface = dbus.Interface(tracker_object, 'org.freedesktop.Tracker.Search')
        self.keywords_interface = dbus.Interface(tracker_object, 'org.freedesktop.Tracker.Keywords')
        self.metadata_interface = dbus.Interface(tracker_object, 'org.freedesktop.Tracker.Metadata')
        self.query_id = -1

        self.containers = {}
        self.tracks = {}
        self.containers[ROOT_CONTAINER_ID] = \
                    Container(ROOT_CONTAINER_ID, -1, self.name, store=self)

        def queries_finished(r):
            louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)

        def queries_failed(r):
            error = ''
            louie.send('Coherence.UPnP.Backend.init_failed', None, backend=self, msg=error)

        services = kwargs.get('service', 'Music,Videos,Images')
        services = map(lambda x: x.strip().lower(), services.split(','))

        l = []
        mapping = {'music': self.get_tracks,
                    'videos': self.get_videos,
                    'images': self.get_images}
        for service in services:
            try:
                l.append(mapping[service]())
            except KeyError:
                self.warning('Wrong Tracker service definition - %r', service)
        if len(l) > 0:
            dl = defer.DeferredList(l)
            dl.addCallback(queries_finished)
            dl.addErrback(lambda x: louie.send('Coherence.UPnP.Backend.init_failed', None, backend=self, msg='Connection to Tracker service(s) failed!'))
        else:
            louie.send('Coherence.UPnP.Backend.init_failed', None, backend=self, msg='No Tracker service defined!')
Example #4
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self,server,**kwargs)
        self.warning("__init__ MediaStore %r", kwargs)
        self.db = kwargs['db']
        self.plugin = kwargs['plugin']

        self.wmc_mapping.update({'4': lambda : self.get_by_id(AUDIO_ALL_CONTAINER_ID),    # all tracks
                                 '7': lambda : self.get_by_id(AUDIO_ALBUM_CONTAINER_ID),    # all albums
                                 '6': lambda : self.get_by_id(AUDIO_ARTIST_CONTAINER_ID),    # all artists
                                })

        self.next_id = CONTAINER_COUNT
        self.albums = None
        self.artists = None
        self.tracks = None

        self.urlbase = kwargs.get('urlbase','')
        if( len(self.urlbase) > 0 and self.urlbase[len(self.urlbase)-1] != '/'):
            self.urlbase += '/'

        try:
            self.name = kwargs['name']
        except KeyError:
            self.name = "Rhythmbox on %s" % self.server.coherence.hostname

        query = self.db.query_new()
        self.info(query)
        self.db.query_append(query, [rhythmdb.QUERY_PROP_EQUALS, rhythmdb.PROP_TYPE, self.db.entry_type_get_by_name('song')])
        qm = self.db.query_model_new(query)
        self.db.do_full_query_async_parsed(qm, query)

        self.album_query = self.db.property_model_new(rhythmdb.PROP_ALBUM)
        self.album_query.props.query_model = qm

        self.artist_query = self.db.property_model_new(rhythmdb.PROP_ARTIST)
        self.artist_query.props.query_model = qm

        self.containers = {}
        self.containers[ROOT_CONTAINER_ID] = \
                Container( ROOT_CONTAINER_ID,-1, "Rhythmbox on %s" % self.server.coherence.hostname)

        self.containers[AUDIO_ALL_CONTAINER_ID] = \
                Container( AUDIO_ALL_CONTAINER_ID,ROOT_CONTAINER_ID, 'All tracks',
                          children_callback=self.children_tracks,
                          store=self,play_container=True)
        self.containers[ROOT_CONTAINER_ID].add_child(self.containers[AUDIO_ALL_CONTAINER_ID])

        self.containers[AUDIO_ALBUM_CONTAINER_ID] = \
                Container( AUDIO_ALBUM_CONTAINER_ID,ROOT_CONTAINER_ID, 'Albums',
                          children_callback=self.children_albums)
        self.containers[ROOT_CONTAINER_ID].add_child(self.containers[AUDIO_ALBUM_CONTAINER_ID])

        self.containers[AUDIO_ARTIST_CONTAINER_ID] = \
                Container( AUDIO_ARTIST_CONTAINER_ID,ROOT_CONTAINER_ID, 'Artists',
                          children_callback=self.children_artists)
        self.containers[ROOT_CONTAINER_ID].add_child(self.containers[AUDIO_ARTIST_CONTAINER_ID])

        louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)
Example #5
0
    def __init__(self, server, **kwargs):

        if server.coherence.config.get('use_dbus','no') != 'yes':
            raise Exception('this backend needs use_dbus enabled in the configuration')

        BackendStore.__init__(self,server,**kwargs)
        self.config = kwargs
        self.name = kwargs.get('name','TV')

        self.update_id = 0
        self.channel_groups = []

        if kwargs.get('enable_destroy','no') == 'yes':
            self.upnp_DestroyObject = self.hidden_upnp_DestroyObject

        self.bus = dbus.SessionBus()
        dvb_daemon_recordingsStore = self.bus.get_object(BUS_NAME,RECORDINGSSTORE_OBJECT_PATH)
        dvb_daemon_manager = self.bus.get_object(BUS_NAME,MANAGER_OBJECT_PATH)
    
        self.store_interface = dbus.Interface(dvb_daemon_recordingsStore, 'org.gnome.DVB.RecordingsStore')
        self.manager_interface = dbus.Interface(dvb_daemon_manager, 'org.gnome.DVB.Manager')
    
        dvb_daemon_recordingsStore.connect_to_signal('Changed', self.recording_changed,
                dbus_interface='org.gnome.DVB.RecordingsStore')

        self.containers = {}
        self.containers[ROOT_CONTAINER_ID] = \
                    Container(ROOT_CONTAINER_ID,-1,self.name,store=self)
        self.containers[RECORDINGS_CONTAINER_ID] = \
                    Container(RECORDINGS_CONTAINER_ID,ROOT_CONTAINER_ID,'Recordings',store=self)
        self.containers[CHANNELS_CONTAINER_ID] = \
                    Container(CHANNELS_CONTAINER_ID,ROOT_CONTAINER_ID,'Channels',store=self)
        self.containers[CHANNEL_GROUPS_CONTAINER_ID] = \
                    Container(CHANNEL_GROUPS_CONTAINER_ID, ROOT_CONTAINER_ID, 'Channel Groups',
                    store=self)

        self.containers[ROOT_CONTAINER_ID].add_child(self.containers[RECORDINGS_CONTAINER_ID])
        self.containers[ROOT_CONTAINER_ID].add_child(self.containers[CHANNELS_CONTAINER_ID])
        self.containers[ROOT_CONTAINER_ID].add_child(self.containers[CHANNEL_GROUPS_CONTAINER_ID])

        def query_finished(r):
            louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)

        def query_failed(error):
            self.error("ERROR: %s", error)
            louie.send('Coherence.UPnP.Backend.init_failed', None, backend=self, msg=error)

        # get_device_groups is called after get_channel_groups,
        # because we need channel groups first
        channel_d = self.get_channel_groups()
        channel_d.addCallback(self.get_device_groups)
        channel_d.addErrback(query_failed)

        d = defer.DeferredList((channel_d, self.get_recordings()))
        d.addCallback(query_finished)
        d.addErrback(query_failed)
Example #6
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self,server)
        self.next_id = 1000
        self.name = kwargs.get('name','my media')
        self.content = kwargs.get('content',None)
        if self.content != None:
                if isinstance(self.content,basestring):
                    self.content = [self.content]
                l = []
                for a in self.content:
                    l += a.split(',')
                self.content = l
        else:
            self.content = xdg_content()
        if self.content == None:
            self.content = 'tests/content'
        if not isinstance( self.content, list):
            self.content = [self.content]
        self.urlbase = kwargs.get('urlbase','')
        ignore_patterns = kwargs.get('ignore_patterns',[])

        if self.urlbase[len(self.urlbase)-1] != '/':
            self.urlbase += '/'
        self.server = server
        self.store = {}

        try:
            self.inotify = INotify()
        except:
            self.inotify = None

        if kwargs.get('enable_destroy','no') == 'yes':
            self.upnp_DestroyObject = self.hidden_upnp_DestroyObject

        self.ignore_file_pattern = re.compile('|'.join(['^\..*'] + list(ignore_patterns)))
        parent = None
        self.update_id = 0
        if len(self.content)>1:
            UPnPClass = classChooser('root')
            id = self.getnextID()
            parent = self.store[id] = FSItem( id, parent, 'media', 'root', self.urlbase, UPnPClass, update=True)

        for path in self.content:
            if isinstance(path,(list,tuple)):
                path = path[0]
            if self.ignore_file_pattern.match(path):
                continue
            self.walk(path, parent, self.ignore_file_pattern)

        self.wmc_mapping.update({'14': 0,
                                 '15': 0,
                                 '16': 0,
                                 '17': 0
                                })

        louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)
Example #7
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self, server, **kwargs)
        BansheeDB.__init__(self, kwargs.get("db_path"))
        self.update_id = 0
        self.name = kwargs.get('name', 'Banshee')

        self.containers = {}
        self.containers[ROOT_CONTAINER_ID] = Container(ROOT_CONTAINER_ID,
                                                       -1, self.name, store=self)
        louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)
Example #8
0
    def __init__(self, server, *args, **kwargs):
        BackendStore.__init__(self, server, **kwargs)

        self.name = kwargs.get('name', 'BBC')
        self.refresh = int(kwargs.get('refresh', 1)) * (60 * 60)

        self.next_id = 1000
        self.update_id = 0
        self.last_updated = None
        self.store = {}
        d = self.update_data()
        d.addCallback(self.init_completed)
Example #9
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self, server, **kwargs)

        self.next_id = 1000
        self.config = kwargs
        self.name = kwargs.get("name", "AxisCamStore")

        self.update_id = 0
        self.store = {}

        self.wmc_mapping = {"8": 1000}

        self.init_completed()
    def __init__(self, server, *args, **kwargs):
        BackendStore.__init__(self,server,**kwargs)
        self.next_id = 1000
        self.name = kwargs.get('name','Apple Trailers')
        self.refresh = int(kwargs.get('refresh', 8)) * (60 *60)

        self.trailers = {}

        self.wmc_mapping = {'15': 0}

        dfr = self.update_data()
        # first get the first bunch of data before sending init_completed
        dfr.addCallback(lambda x: self.init_completed())
Example #11
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self,server,**kwargs)
        self.next_id = 10000
        self.name = kwargs.get('name','Flickr')
        self.proxy = kwargs.get('proxy','false')
        self.refresh = int(kwargs.get('refresh',60))*60

        self.limit = int(kwargs.get('limit',100))


        self.flickr_userid = kwargs.get('userid',None)
        self.flickr_password = kwargs.get('password',None)
        self.flickr_permissions = kwargs.get('permissions',None)

        if self.proxy in [1,'Yes','yes','True','true']:
            self.proxy = True
        else:
            self.proxy = False

        ignore_patterns = kwargs.get('ignore_patterns',[])
        ignore_file_pattern = re.compile('|'.join(['^\..*'] + list(ignore_patterns)))

        self.wmc_mapping = {'16': 0}

        self.update_id = 0
        self.flickr = Proxy('http://api.flickr.com/services/xmlrpc/')
        self.flickr_api_key = '837718c8a622c699edab0ea55fcec224'
        self.flickr_api_secret = '30a684822c341c3c'
        self.store = {}
        self.uploads = {}

        self.refresh_store_loop = task.LoopingCall(self.refresh_store)
        self.refresh_store_loop.start(self.refresh, now=False)

        #self.server.coherence.store_plugin_config(self.server.uuid, {'test':'äöüß'})

        self.flickr_userid = kwargs.get('userid',None)
        self.flickr_password = kwargs.get('password',None)
        self.flickr_permissions = kwargs.get('permissions','read')

        self.flickr_authtoken = kwargs.get('authtoken',None)

        if(self.flickr_authtoken == None and
           self.server.coherence.writeable_config() == True):
            if not None in (self.flickr_userid,self.flickr_password):
                d = self.flickr_authenticate_app()
                d.addBoth(lambda x: self.init_completed())
                return
            
        self.init_completed()
Example #12
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self,server,**kwargs)

        self.next_id = 1000
        self.config = kwargs
        self.name = kwargs.get('name','LastFMStore')

        self.update_id = 0
        self.store = {}

        self.wmc_mapping = {'4': 1000}


        louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)
Example #13
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self, server, **kwargs)
        self.next_id = 1000
        self.config = kwargs
        self.name = kwargs.get('name', 'iTV')

        self.update_id = 0
        self.store = {}

        self.wmc_mapping = {'4': 1000}

        self.shoutcast_ws_url = self.config.get('genrelist', SHOUTCAST_WS_URL)

        self.init_completed()
Example #14
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self,server,**kwargs)
        self.next_id = 1000
        self.config = kwargs
        self.name = kwargs.get('name','iRadioStore')

        self.update_id = 0

        self.wmc_mapping = {'4': 1000}


        self.store = {}

        self.init_completed()
Example #15
0
    def __init__(self, server, *args, **kwargs):
        BackendStore.__init__(self, server, **kwargs)

        self.name = kwargs.get('name', 'SWR3')
        self.opml = kwargs.get('opml', 'http://www.swr3.de/rdf-feed/podcast/')
        self.encoding = kwargs.get('encoding', "ISO-8859-1")
        self.refresh = int(kwargs.get('refresh', 1)) * (60 * 60)

        self.next_id = 1000
        self.update_id = 0
        self.last_updated = None
        self.store = {ROOT_CONTAINER_ID: Container(ROOT_CONTAINER_ID, self, -1, self.name)}

        self.parse_opml()
        self.init_completed()
Example #16
0
	def __init__(self, server, *args, **kwargs):
		# first we inizialize our heritage
		BackendStore.__init__(self,server,**kwargs)
		
		self.cache_directory = kwargs.get('cache_directory', '/tmp/coherence-cache')
		if not exists(self.cache_directory):
			makedirs(self.cache_directory)
		self.cache_maxsize = kwargs.get('cache_maxsize', 100000000)
		self.buffer_size = kwargs.get('buffer_size', 750000)
 
		# When a Backend is initialized, the configuration is given as keyword
		# arguments to the initialization. We receive it here as a dicitonary
		# and allow some values to be set:

		# the name of the MediaServer as it appears in the network
		self.name = kwargs.get('name', 'iPlayer')

		# timeout between updates in hours:
		self.refresh = int(kwargs.get('refresh', 1)) * (60 *60)

		# internally used to have a new id for each item
		self.next_id = 1000

		# the UPnP device that's hosting that backend, that's already done
		# in the BackendStore.__init__, just left here the sake of completeness
		self.server = server

		# initialize our Iplayer container (no parent, this is the root)
		self.container = IplayerContainer(None, self.ROOT_ID, "iPlayer")

		# but as we also have to return them on 'get_by_id', we have our local
		# store of videos per id:
		self.everything = {}

		# we tell that if an XBox sends a request for videos we'll
		# map the WMC id of that request to our local one
		self.wmc_mapping = {'15': 0}

		# and trigger an update of the data
		dfr = self.update_data()

		# So, even though the initialize is kind of done, Coherence does not yet
		# announce our Media Server.
		# Coherence does wait for signal send by us that we are ready now.
		# And we don't want that to happen as long as we don't have succeeded
		# in fetching some first data, so we delay this signaling after the update is done:
		dfr.addCallback(self.init_completed)
		dfr.addCallback(self.queue_update)
Example #17
0
    def __init__(self, server, **kwargs):

        if server.coherence.config.get('use_dbus','no') != 'yes':
            raise Exception('this backend needs use_dbus enabled in the configuration')

        BackendStore.__init__(self, server, **kwargs)
        
        self.state_update_id = 0

        self.bus = dbus.SessionBus()
        # We have one ScheduleRecording service for each device group
        # TODO use one ScheduledRecording for each device group
        self.device_group_interface = None

        dvbd_recorder = self.device_group_interface.GetRecorder()
        self.recorder_interface = self.bus.get_object(BUS_NAME, dvdb_recorder)
Example #18
0
    def __init__(self, server, *args, **kwargs):
        # first we inizialize our heritage
        BackendStore.__init__(self,server,**kwargs)

        # When a Backend is initialized, the configuration is given as keyword
        # arguments to the initialization. We receive it here as a dicitonary
        # and allow some values to be set:

        # the name of the MediaServer as it appears in the network
        self.name = kwargs.get('name', 'Lolcats')

        # timeout between updates in hours:
        self.refresh = int(kwargs.get('refresh', 1)) * (60 *60)

        # the UPnP device that's hosting that backend, that's already done
        # in the BackendStore.__init__, just left here the sake of completeness
        self.server = server

        # internally used to have a new id for each item
        self.next_id = 1000

        # we store the last update from the rss feed so that we know if we have
        # to parse again, or not:
        self.last_updated = None

        # initialize our lolcats container (no parent, this is the root)
        self.container = LolcatsContainer(None, self.ROOT_ID)

        # but as we also have to return them on 'get_by_id', we have our local
        # store of images per id:
        self.images = {}

        # we tell that if an XBox sends a request for images we'll
        # map the WMC id of that request to our local one
        self.wmc_mapping = {'16': 0}

        # and trigger an update of the data
        dfr = self.update_data()

        # So, even though the initialize is kind of done, Coherence does not yet
        # announce our Media Server.
        # Coherence does wait for signal send by us that we are ready now.
        # And we don't want that to happen as long as we don't have succeeded
        # in fetching some first data, so we delay this signaling after the update is done:
        dfr.addCallback(self.init_completed)
        dfr.addCallback(self.queue_update)
Example #19
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self,server,**kwargs)
        self.warning("__init__ MediaStore %r", kwargs)
        """
        self.wmc_mapping.update({'4': lambda : self.get_by_id(SERIES_CONTAINER_ID),    # all series
                                 '7': lambda : self.get_by_id(MOVIES_CONTAINER_ID)
                                 })
        """
        self.server = server
        self.smewt_db = kwargs.get("smewt_db", None)
        self.urlbase = kwargs.get("urlbase", "")
        self.only_available = kwargs.get("only_available", True)
        self.series = None
        self.episodes = None
        
        self.next_id = 0
        self.items = {}
        self.ids = {}
        
        try:
            self.name = kwargs['name']
        except KeyError:
            self.name = "Smewt on %s" % self.server.coherence.hostname

        self.root_container = Container(self, self.name, -1)
        
        self.warning("Adding all series")
        self.add_container('All series', lambda pid: advSeries(self, self.smewt_db, parent_id=pid))
        self.warning("Adding all movies")
        self.add_container('All movies', lambda pid: allMovies(self, self.smewt_db, parent_id=pid))
        self.warning("Adding movies by genre")
        self.add_container('Movies by genre', lambda pid: moviesByProperty(self, self.smewt_db, 'genres', parent_id=pid))
        self.warning("Adding movies by year")
        self.add_container('Movies by year', lambda pid: moviesByProperty(self, self.smewt_db, 'year', getProperty = lambda x: [x.get('year', None)], parent_id=pid))
        self.warning("Adding movies by director")
        self.add_container('Movies by director', lambda pid: moviesByProperty(self, self.smewt_db, 'director', parent_id=pid))
        self.warning("Adding movies by cast")
        self.add_container('Movies by cast', lambda pid: moviesByProperty(self, self.smewt_db, 'cast', getProperty = lambda x: [act.split('--')[0] for act in x.get('cast', [])], parent_id=pid))
        
        louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)
        self.warning("End of __init__")
Example #20
0
    def __init__(self, server, **kwargs):

        if server.coherence.config.get('use_dbus','no') != 'yes':
            raise Exception, 'this backend needs use_dbus enabled in the configuration'

        BackendStore.__init__(self,server,**kwargs)
        self.config = kwargs
        self.name = kwargs.get('name','TV')

        self.update_id = 0

        if kwargs.get('enable_destroy','no') == 'yes':
            self.upnp_DestroyObject = self.hidden_upnp_DestroyObject

        self.bus = dbus.SessionBus()
        dvb_daemon = self.bus.get_object(BUS_NAME,OBJECT_PATH)
        self.store_interface = dbus.Interface(dvb_daemon, 'org.gnome.DVB.RecordingsStore')

        dvb_daemon.connect_to_signal('Changed', self.recording_changed, dbus_interface='org.gnome.DVB.RecordingsStore')

        self.containers = {}
        self.containers[ROOT_CONTAINER_ID] = \
                    Container(ROOT_CONTAINER_ID,-1,self.name,store=self)
        self.containers[RECORDINGS_CONTAINER_ID] = \
                    Container(RECORDINGS_CONTAINER_ID,ROOT_CONTAINER_ID,'Recordings',store=self)
        self.containers[ROOT_CONTAINER_ID].add_child(self.containers[RECORDINGS_CONTAINER_ID])

        def query_finished(r):
            louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)

        def query_failed(r):
            error = ''
            louie.send('Coherence.UPnP.Backend.init_failed', None, backend=self, msg=error)

        d = self.get_recordings()
        d.addCallback(query_finished)
        d.addErrback(lambda x: louie.send('Coherence.UPnP.Backend.init_failed', None, backend=self, msg='Connection to DVB Daemon failed!'))
Example #21
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self,server,**kwargs)
        self.info("MediaStore __init__")
        self.update_id = 0

        self.medialocation = kwargs.get('medialocation','tests/content/audio')
        self.coverlocation = kwargs.get('coverlocation',None)
        if self.coverlocation is not None and self.coverlocation[-1] != '/':
            self.coverlocation = self.coverlocation + '/'
        self.mediadb = kwargs.get('mediadb',MEDIA_DB)

        self.name = kwargs.get('name','MediaStore')

        self.containers = {}
        self.containers[ROOT_CONTAINER_ID] = \
                Container( ROOT_CONTAINER_ID,-1, self.name)

        self.wmc_mapping.update({'4': lambda : self.get_by_id(AUDIO_ALL_CONTAINER_ID),    # all tracks
                                 '7': lambda : self.get_by_id(AUDIO_ALBUM_CONTAINER_ID),    # all albums
                                 '6': lambda : self.get_by_id(AUDIO_ARTIST_CONTAINER_ID),    # all artists
                                })


        louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)
Example #22
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self, server, **kwargs)
        self.next_id = 1000
        self.name = kwargs.get('name', 'my media')
        self.content = kwargs.get('content', None)
        if self.content != None:
            if isinstance(self.content, str):
                self.content = [self.content]
            l = []
            for a in self.content:
                l += a.split(',')
            self.content = l
        else:
            self.content = xdg_content()
            self.content = [x[0] for x in self.content]
        if self.content == None:
            self.content = 'tests/content'
        if not isinstance(self.content, list):
            self.content = [self.content]
        self.content = Set([os.path.abspath(x) for x in self.content])
        ignore_patterns = kwargs.get('ignore_patterns', [])
        self.store = {}

        self.inotify = None

        if kwargs.get('enable_inotify', 'yes') == 'yes':
            if INotify:
                try:
                    self.inotify = INotify()
                except Exception as msg:
                    self.info("%s", msg)
            else:
                self.info("%s", no_inotify_reason)
        else:
            self.info("FSStore content auto-update disabled upon user request")

        if kwargs.get('enable_destroy', 'no') == 'yes':
            self.upnp_DestroyObject = self.hidden_upnp_DestroyObject

        self.import_folder = kwargs.get('import_folder', None)
        if self.import_folder != None:
            self.import_folder = os.path.abspath(self.import_folder)
            if not os.path.isdir(self.import_folder):
                self.import_folder = None

        self.ignore_file_pattern = re.compile('|'.join(['^\..*'] +
                                                       list(ignore_patterns)))
        parent = None
        self.update_id = 0
        if (len(self.content) > 1
                or utils.means_true(kwargs.get('create_root', False))
                or self.import_folder != None):
            UPnPClass = classChooser('root')
            id = str(self.getnextID())
            parent = self.store[id] = FSItem(id,
                                             parent,
                                             'media',
                                             'root',
                                             self.urlbase,
                                             UPnPClass,
                                             update=True,
                                             store=self)

        if self.import_folder != None:
            id = str(self.getnextID())
            self.store[id] = FSItem(id,
                                    parent,
                                    self.import_folder,
                                    'directory',
                                    self.urlbase,
                                    UPnPClass,
                                    update=True,
                                    store=self)
            self.import_folder_id = id

        for path in self.content:
            if isinstance(path, (list, tuple)):
                path = path[0]
            if self.ignore_file_pattern.match(path):
                continue
            try:
                path = path.encode('utf-8')  # patch for #267
                self.walk(path, parent, self.ignore_file_pattern)
            except Exception as msg:
                self.warning('on walk of %r: %r', path, msg)
                import traceback
                self.debug(traceback.format_exc())

        self.wmc_mapping.update({'14': '0', '15': '0', '16': '0', '17': '0'})

        louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)
Example #23
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self, server, **kwargs)
        self.next_id = 1000
        self.name = kwargs.get('name', 'my media')
        self.content = kwargs.get('content', None)
        if self.content is not None:
            if isinstance(self.content, str):
                self.content = [self.content]
            cl = []
            for a in self.content:
                cl += a.split(',')
            self.content = cl
        else:
            self.content = xdg_content()
            self.content = [x[0] for x in self.content]
        if self.content is None:
            self.content = 'tests/content'
        if not isinstance(self.content, list):
            self.content = [self.content]
        self.content = set([os.path.abspath(x) for x in self.content])
        ignore_patterns = kwargs.get('ignore_patterns', [])
        self.store = {}

        self.inotify = None

        if kwargs.get('enable_inotify', 'yes') == 'yes':
            if INotify:
                try:
                    self.inotify = INotify()
                    self.inotify.startReading()
                except Exception as msg:
                    self.error(f'inotify disabled: {msg}')
                    self.inotify = None
            else:
                self.info(f'{no_inotify_reason}')
        else:
            self.info('FSStore content auto-update disabled upon user request')

        if kwargs.get('enable_destroy', 'no') == 'yes':
            self.upnp_DestroyObject = self.hidden_upnp_DestroyObject

        self.import_folder = kwargs.get('import_folder', None)
        if self.import_folder is not None:
            self.import_folder = os.path.abspath(self.import_folder)
            if not os.path.isdir(self.import_folder):
                self.import_folder = None

        self.ignore_file_pattern = re.compile(r'|'.join([r'^\..*'] +
                                                        list(ignore_patterns)))
        parent = None
        self.update_id = 0
        if (len(self.content) > 1
                or utils.means_true(kwargs.get('create_root', False))
                or self.import_folder is not None):
            UPnPClass = classChooser('root')
            id = str(self.getnextID())
            try:
                parent = self.store[id] = FSItem(id,
                                                 parent,
                                                 'media',
                                                 'root',
                                                 self.urlbase,
                                                 UPnPClass,
                                                 update=True,
                                                 store=self)
            except Exception as e:
                self.error(
                    f'Error on setting self.store[id], Error on FSItem: {e}')
                exit(1)

        if self.import_folder is not None:
            id = str(self.getnextID())
            self.store[id] = FSItem(id,
                                    parent,
                                    self.import_folder,
                                    'directory',
                                    self.urlbase,
                                    UPnPClass,
                                    update=True,
                                    store=self)
            self.import_folder_id = id
        for bytesPath in self.content:
            if isinstance(bytesPath, (list, tuple)):
                path = str(path[0])
            else:
                path = str(bytesPath)
            if self.ignore_file_pattern.match(path):
                continue
            try:
                self.walk(path, parent, self.ignore_file_pattern)
            except Exception as msg:
                self.warning(f'on walk of {path!r}: {msg!r}')
                import traceback
                self.debug(traceback.format_exc())

        self.wmc_mapping.update({'14': '0', '15': '0', '16': '0', '17': '0'})

        self.init_completed = True
Example #24
0
    def __init__(self, server, **kwargs):

        if server.coherence.config.get('use_dbus', 'no') != 'yes':
            raise Exception(
                'this backend needs use_dbus enabled in the configuration')
        BackendStore.__init__(self, server, **kwargs)

        self.config = kwargs
        self.name = kwargs.get('name', 'Tracker')

        self.update_id = 0
        self.token = None

        self.songs = 0
        self.albums = 0
        self.artists = 0
        self.playlists = 0
        self.genres = 0

        self.videos = 0
        self.images = 0

        self.bus = dbus.SessionBus()
        tracker_object = self.bus.get_object(BUS_NAME, OBJECT_PATH)
        self.tracker_interface = dbus.Interface(tracker_object,
                                                'org.freedesktop.Tracker')
        self.search_interface = dbus.Interface(
            tracker_object, 'org.freedesktop.Tracker.Search')
        self.keywords_interface = dbus.Interface(
            tracker_object, 'org.freedesktop.Tracker.Keywords')
        self.metadata_interface = dbus.Interface(
            tracker_object, 'org.freedesktop.Tracker.Metadata')
        self.query_id = -1

        self.containers = {}
        self.tracks = {}
        self.containers[ROOT_CONTAINER_ID] = Container(ROOT_CONTAINER_ID,
                                                       -1,
                                                       self.name,
                                                       store=self)

        def queries_finished(r):
            self.init_completed = True

        def queries_failed(r):
            error = 'Query failed'
            self.on_init_failed(msg=error)

        services = kwargs.get('service', 'Music,Videos,Images')
        services = [x.strip().lower() for x in services.split(',')]

        ml = []
        mapping = {
            'music': self.get_tracks,
            'videos': self.get_videos,
            'images': self.get_images,
        }
        for service in services:
            try:
                ml.append(mapping[service]())
            except KeyError:
                self.warning(f'Wrong Tracker service definition - {service}')
        if len(ml) > 0:
            dl = defer.DeferredList(ml)
            dl.addCallback(queries_finished)
            dl.addErrback(lambda x: self.on_init_failed(
                msg='Connection to Tracker service(s) failed!'))
        else:
            self.on_init_failed(msg='No Tracker service defined!')
Example #25
0
    def __init__(self, server, *args, **kwargs):
        print "TestStore kwargs", kwargs
        BackendStore.__init__(self, server, **kwargs)
        self.name = kwargs.get('name', 'TestServer')
        self.next_id = 1000
        self.update_id = 0
        self.store = {}

        self.store[ROOT_CONTAINER_ID] = \
                        Container(ROOT_CONTAINER_ID,self,-1, self.name)

        items = kwargs.get('item', [])
        if not isinstance(items, list):
            items = [items]

        for item in items:
            if isinstance(item, basestring):
                xml = parse_xml(item)
                print xml.getroot()
                item = {}
                for child in xml.getroot():
                    item[child.tag] = child.text
            type = item.get('type', 'file')
            try:
                name = item.get('title', None)
                if type == 'file':
                    location = FilePath(item.get('location'))
                if type == 'url':
                    location = item.get('location')

                mimetype = item.get('mimetype')
                item_id = self.get_next_id()

                extension = item.get('extension')
                if extension == None:
                    extension = ''
                if len(extension) and extension[0] != '.':
                    extension = '.' + extension

                if extension != None:
                    item_id = str(item_id) + extension

                if type in ('file', 'url'):
                    new_item = Item(self.store[ROOT_CONTAINER_ID], item_id,
                                    name, location,
                                    self.urlbase + str(item_id))
                elif type == 'gstreamer':
                    pipeline = item.get('pipeline')
                    try:
                        pipeline = GStreamerPipeline(pipeline, mimetype)
                        new_item = ResourceItem(self.store[ROOT_CONTAINER_ID],
                                                item_id, name, pipeline,
                                                self.urlbase + str(item_id))
                    except NameError:
                        self.warning(
                            "Can't enable GStreamerPipeline, probably pygst not installed"
                        )
                        continue

                elif type == 'process':
                    pipeline = item.get('command')
                    pipeline = ExternalProcessPipeline(pipeline, mimetype)
                    new_item = ResourceItem(self.store[ROOT_CONTAINER_ID],
                                            item_id, name, pipeline,
                                            self.urlbase + str(item_id))

                try:
                    new_item.upnp_class = self.get_upnp_class(
                        item.get('upnp_class', 'object.item'))
                except:
                    pass
                #item.description = u'some text what's the file about'
                #item.date = something
                #item.size = something
                new_item.mimetype = mimetype
                new_item.fourth_field = item.get('fourth_field', '*')

                self.store[ROOT_CONTAINER_ID].add_child(new_item)
                self.store[item_id] = new_item

            except:
                import traceback
                self.warning(traceback.format_exc())

        #print self.store

        self.init_completed()
Example #26
0
    def __init__(self, server, *args, **kwargs):
        print "TestStore kwargs", kwargs
        BackendStore.__init__(self, server, **kwargs)
        self.name = kwargs.get('name', 'TestServer')
        self.next_id = 1000
        self.update_id = 0
        self.store = {}

        self.store[ROOT_CONTAINER_ID] = \
                        Container(ROOT_CONTAINER_ID, self, -1, self.name)

        items = kwargs.get('item', [])
        if not isinstance(items, list):
            items = [items]

        for item in items:
            if isinstance(item, basestring):
                xml = etree.fromstring(item)
                item = {}
                for child in xml:
                    item[child.tag] = child.text
            type = item.get('type', 'file')
            try:
                name = item.get('title', None)
                if type == 'file':
                    location = FilePath(item.get('location'))
                if type == 'url':
                    location = item.get('location')

                mimetype = item.get('mimetype')
                item_id = self.get_next_id()

                extension = item.get('extension')
                if extension == None:
                    extension = ''
                if len(extension) and extension[0] != '.':
                    extension = '.' + extension

                if extension != None:
                    item_id = str(item_id) + extension

                if type in ('file', 'url'):
                    new_item = Item(self.store[ROOT_CONTAINER_ID], item_id, name, location, self.urlbase + str(item_id))
                elif type == 'gstreamer':
                    pipeline = item.get('pipeline')
                    try:
                        pipeline = GStreamerPipeline(pipeline, mimetype)
                        new_item = ResourceItem(self.store[ROOT_CONTAINER_ID], item_id, name, pipeline, self.urlbase + str(item_id))
                    except NameError:
                        self.warning("Can't enable GStreamerPipeline, probably pygst not installed")
                        continue

                elif type == 'process':
                    pipeline = item.get('command')
                    pipeline = ExternalProcessPipeline(pipeline, mimetype)
                    new_item = ResourceItem(self.store[ROOT_CONTAINER_ID], item_id, name, pipeline, self.urlbase + str(item_id))

                try:
                    new_item.upnp_class = self.get_upnp_class(item.get('upnp_class', 'object.item'))
                except:
                    pass
                #item.description = u'some text what's the file about'
                #item.date = something
                #item.size = something
                new_item.mimetype = mimetype
                new_item.fourth_field = item.get('fourth_field', '*')

                self.store[ROOT_CONTAINER_ID].add_child(new_item)
                self.store[item_id] = new_item

            except:
                import traceback
                self.warning(traceback.format_exc())
        #print self.store

        self.init_completed()
Example #27
0
    def __init__(self, server, **kwargs):
        BackendStore.__init__(self, server, **kwargs)
        self.warning("__init__ MediaStore %r", kwargs)
        self.db = kwargs['db']
        self.plugin = kwargs['plugin']

        self.wmc_mapping.update({
            '4':
            lambda: self.get_by_id(AUDIO_ALL_CONTAINER_ID),  # all tracks
            '7':
            lambda: self.get_by_id(AUDIO_ALBUM_CONTAINER_ID),  # all albums
            '6':
            lambda: self.get_by_id(AUDIO_ARTIST_CONTAINER_ID),  # all artists
        })

        self.next_id = CONTAINER_COUNT
        self.albums = None
        self.artists = None
        self.tracks = None

        self.urlbase = kwargs.get('urlbase', '')
        if (len(self.urlbase) > 0
                and self.urlbase[len(self.urlbase) - 1] != '/'):
            self.urlbase += '/'

        try:
            self.name = kwargs['name']
        except KeyError:
            self.name = "Rhythmbox on %s" % self.server.coherence.hostname

        query = self.db.query_new()
        self.info(query)
        self.db.query_append(query, [
            rhythmdb.QUERY_PROP_EQUALS, rhythmdb.PROP_TYPE,
            self.db.entry_type_get_by_name('song')
        ])
        qm = self.db.query_model_new(query)
        self.db.do_full_query_async_parsed(qm, query)

        self.album_query = self.db.property_model_new(rhythmdb.PROP_ALBUM)
        self.album_query.props.query_model = qm

        self.artist_query = self.db.property_model_new(rhythmdb.PROP_ARTIST)
        self.artist_query.props.query_model = qm

        self.containers = {}
        self.containers[ROOT_CONTAINER_ID] = \
                Container( ROOT_CONTAINER_ID,-1, "Rhythmbox on %s" % self.server.coherence.hostname)

        self.containers[AUDIO_ALL_CONTAINER_ID] = \
                Container( AUDIO_ALL_CONTAINER_ID,ROOT_CONTAINER_ID, 'All tracks',
                          children_callback=self.children_tracks,
                          store=self,play_container=True)
        self.containers[ROOT_CONTAINER_ID].add_child(
            self.containers[AUDIO_ALL_CONTAINER_ID])

        self.containers[AUDIO_ALBUM_CONTAINER_ID] = \
                Container( AUDIO_ALBUM_CONTAINER_ID,ROOT_CONTAINER_ID, 'Albums',
                          children_callback=self.children_albums)
        self.containers[ROOT_CONTAINER_ID].add_child(
            self.containers[AUDIO_ALBUM_CONTAINER_ID])

        self.containers[AUDIO_ARTIST_CONTAINER_ID] = \
                Container( AUDIO_ARTIST_CONTAINER_ID,ROOT_CONTAINER_ID, 'Artists',
                          children_callback=self.children_artists)
        self.containers[ROOT_CONTAINER_ID].add_child(
            self.containers[AUDIO_ARTIST_CONTAINER_ID])

        louie.send('Coherence.UPnP.Backend.init_completed', None, backend=self)
Example #28
0
    def __init__(self, server, *args, **kwargs):
        # first we initialize our heritage
        BackendStore.__init__(self, server, **kwargs)

        reload(sys)
        sys.setdefaultencoding('utf-8')

        # When a Backend is initialized, the configuration is given as keyword
        # arguments to the initialization. We receive it here as a dictionary
        # and allow some values to be set:

        # the name of the MediaServer as it appears in the network
        self.name = kwargs.get('name', 'Google Music')

        # timeout between updates in hours:
        self.refresh = int(kwargs.get('refresh', 1)) * (60 * 60)

        # the UPnP device that's hosting that backend, that's already done
        # in the BackendStore.__init__, just left here the sake of completeness
        self.server = server

        # initialize our containers
        self.container = GmusicContainer(None, ROOT_ID, "Google Music")
        self.container.tracks = GmusicContainer(self.container, TRACKS_ID, "Tracks")
        self.container.albums = GmusicContainer(self.container, ALBUM_ID, "Albums")
        self.container.playlists = GmusicContainer(self.container, PLAYLIST_ID, "Playlists")

        self.container.children.append(self.container.tracks)
        self.container.children.append(self.container.albums)
        self.container.children.append(self.container.playlists)

        # but as we also have to return them on 'get_by_id', we have our local
        # store of items per id:
        self.tracks = {}
        self.albums = {}
        self.artists = {}
        self.playlists = {}

        # we tell that if an XBox sends a request for images we'll
        # map the WMC id of that request to our local one
        # Todo: What the hell is going on here?
        # self.wmc_mapping = {'16': 0}

        self.username = kwargs.get('username', '')
        self.password = kwargs.get('password', '')
        self.device_id = kwargs.get('device_id', '')

        self.api = Mobileclient()

        if not self.login():
            self.info("Could not login")
            return

        # and trigger an update of the data
        dfr = self.update_data()

        # So, even though the initialize is kind of done, Coherence does not yet
        # announce our Media Server.
        # Coherence does wait for signal send by us that we are ready now.
        # And we don't want that to happen as long as we don't have succeeded
        # in fetching some first data, so we delay this signaling after the update is done:
        dfr.addCallback(self.init_completed)
        dfr.addCallback(self.queue_update)