def test_publication_date(self): media = Grl.Media.new() date_string = "2001-02-03T04:05:06Z" date = Grl.date_time_from_iso8601 (date_string) self.assertTrue(media.get_publication_date() is None) media.set_publication_date(date) d = media.get_publication_date() self.assertTrue(d is not None) self.assertEqual(d.get_year(), 2001) self.assertEqual(d.get_month(), 2) self.assertEqual(d.get_day_of_month(), 3) self.assertEqual(d.get_hour(), 4) self.assertEqual(d.get_minute(), 5) self.assertEqual(d.get_second(), 6) self.assertEqual(d.format("%FT%H:%M:%S%Z"), date.format("%FT%H:%M:%S%Z")) # date only date_string = "2001-02-03" date = Grl.date_time_from_iso8601 (date_string) media.set_publication_date(date) d = media.get_publication_date() self.assertTrue(d is not None) self.assertEqual(d.get_year(), 2001) self.assertEqual(d.get_month(), 2) self.assertEqual(d.get_day_of_month(), 3) self.assertEqual(d.get_hour(), 12) self.assertEqual(d.get_minute(), 0) self.assertEqual(d.get_second(), 0) self.assertEqual(d.format("%FT%H:%M:%S%Z"), date.format("%FT%H:%M:%S%Z")) self.assertEqual(d.format("%FT%H:%M:%S%Z"), date_string + "T12:00:00UTC")
def __init__(self, coremodel, coreselection): super().__init__() self._coremodel = coremodel self._coreselection = coreselection self._search_wrappers = {} self._thumbnail_sources = [] self._thumbnail_sources_timeout = None self._wrappers = {} self._tracker_wrapper = TrackerWrapper() self._tracker_wrapper.bind_property("tracker-available", self, "tracker-available", GObject.BindingFlags.SYNC_CREATE) self._tracker_wrapper.connect("notify::tracker-available", self._on_tracker_available_changed) Grl.init(None) self._registry = Grl.Registry.get_default() config = Grl.Config.new("grl-lua-factory", "grl-theaudiodb-cover") config.set_api_key(self._theaudiodb_api_key) self._registry.add_config(config) self._registry.connect('source-added', self._on_source_added) self._registry.connect('source-removed', self._on_source_removed) self._registry.load_all_plugins(True)
def __init__(self, source, coremodel, core_selection, grilo): super().__init__() self._coremodel = coremodel self._core_selection = core_selection self._grilo = grilo self._source = source self._model = self._coremodel.props.songs self._albums_model = self._coremodel.props.albums self._album_ids = {} self._artists_model = self._coremodel.props.artists Grl.init(None) self._fast_options = Grl.OperationOptions() self._fast_options.set_resolution_flags( Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY) self._full_options = Grl.OperationOptions() self._full_options.set_resolution_flags( Grl.ResolutionFlags.FULL | Grl.ResolutionFlags.IDLE_RELAY) # self._initial_fill(self._source) # self._initial_albums_fill(self._source) self._initial_artists_fill(self._source)
def search(self, q, callback, data=None): options = self.options.copy() self._search_callback_counter = 0 @log def _search_callback(source, param, item, remaining, data, error): if error: logger.warning( "Error {}: {}".format(error.domain, error.message)) callback(source, param, item, remaining, data) self._search_callback_counter += 1 @log def _multiple_search_callback(source, param, item, remaining, data, error): if error: logger.warning( "Error {}: {}".format(error.domain, error.message)) callback(source, param, item, remaining, data) if self.search_source: if self.search_source.get_id().startswith('grl-upnp'): options.set_type_filter(Grl.TypeFilter.AUDIO) self.search_source.search(q, self.METADATA_KEYS, options, _search_callback, data) else: Grl.multiple_search( [self.props.sources[key] for key in self.props.sources if key != 'grl-tracker-source'], q, self.METADATA_KEYS, options, _multiple_search_callback, data)
def _cancel_current_operation(self): if self._ui_state.op_ongoing: if not self._ui_state.multiple: self._ui_state.cur_op_source.cancel(self._ui_state.cur_op_id) else: Grl.multiple_cancel(self._ui_state.cur_op_id) self._ui_state.op_ongoing = False
def __init__(self): GObject.GObject.__init__(self) self.playlist_path = GLib.build_filenamev([GLib.get_user_data_dir(), "gnome-music", "playlists"]) if not (GLib.file_test(self.playlist_path, GLib.FileTest.IS_DIR)): GLib.mkdir_with_parents(self.playlist_path, int("0755", 8)) Grl.init(None) self.options = Grl.OperationOptions() self.options.set_resolution_flags(Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY) self.full_options = Grl.OperationOptions() self.full_options.set_resolution_flags(Grl.ResolutionFlags.FULL | Grl.ResolutionFlags.IDLE_RELAY) self.sources = {} self.blacklist = ['grl-filesystem', 'grl-bookmarks', 'grl-metadata-store', 'grl-podcasts'] self.tracker = None self.changed_media_ids = [] self.pending_event_id = 0 self.changes_pending = {'Albums': False, 'Artists': False, 'Songs': False} self.pending_changed_medias = [] self.registry = Grl.Registry.get_default() self.sparqltracker = TrackerWrapper().tracker
def test_publication_date(self): media = Grl.Media.new() date_string = "2001-02-03T04:05:06Z" date = Grl.date_time_from_iso8601(date_string) self.assertTrue(media.get_publication_date() is None) media.set_publication_date(date) d = media.get_publication_date() self.assertTrue(d is not None) self.assertEqual(d.get_year(), 2001) self.assertEqual(d.get_month(), 2) self.assertEqual(d.get_day_of_month(), 3) self.assertEqual(d.get_hour(), 4) self.assertEqual(d.get_minute(), 5) self.assertEqual(d.get_second(), 6) self.assertEqual(d.format("%FT%H:%M:%S%Z"), date.format("%FT%H:%M:%S%Z")) # date only date_string = "2001-02-03" date = Grl.date_time_from_iso8601(date_string) media.set_publication_date(date) d = media.get_publication_date() self.assertTrue(d is not None) self.assertEqual(d.get_year(), 2001) self.assertEqual(d.get_month(), 2) self.assertEqual(d.get_day_of_month(), 3) self.assertEqual(d.get_hour(), 12) self.assertEqual(d.get_minute(), 0) self.assertEqual(d.get_second(), 0) self.assertEqual(d.format("%FT%H:%M:%S%Z"), date.format("%FT%H:%M:%S%Z")) self.assertEqual(d.format("%FT%H:%M:%S%Z"), date_string + "T12:00:00UTC")
def __init__(self, method_name): super(TestMediaPlugin, self).__init__(method_name) Grl.init([]) self.registry = Grl.Registry.get_default() self.registry.load_all() sources = self.registry.get_sources(False) if sources: self.plugin = sources[0]
def _init(): Grl.init([]) registry = Grl.Registry.get_default() fs_config = Grl.Config.new("grl-filesystem", None) fs_config.set_string("base-path", _tempdir) registry.add_config(fs_config) registry.load_by_id("grl-filesystem")
def __init__(self, method_name): super(TestMetadataSource, self).__init__(method_name) Grl.init([]) self.registry = Grl.Registry.get_default() self.registry.load_all() ops = Grl.SupportedOps(Grl.SupportedOps.RESOLVE | Grl.SupportedOps.SET_METADATA) sources = self.registry.get_sources_by_operations(ops, False) if sources: self.metadata_source = sources[0]
def __init__(self, application): """Initiate the CoreGrilo object :param Application application: The Application instance to use """ super().__init__() self._application = application self._coremodel = self._application.props.coremodel self._coreselection = application.props.coreselection self._log = application.props.log self._search_wrappers = {} self._thumbnail_sources = [] self._thumbnail_sources_timeout = None self._wrappers = {} self._tracker_wrapper = TrackerWrapper(application) self._tracker_wrapper.bind_property("tracker-available", self, "tracker-available", GObject.BindingFlags.SYNC_CREATE) GLib.setenv("GRL_PLUGIN_RANKS", self._grl_plugin_ranks, True) Grl.init(None) self._registry = Grl.Registry.get_default() config = Grl.Config.new("grl-lua-factory", "grl-theaudiodb-cover") config.set_api_key(self._theaudiodb_api_key) self._registry.add_config(config) self._registry.connect('source-added', self._on_source_added) self._registry.connect('source-removed', self._on_source_removed) self._registry.load_all_plugins(False) tracker_available_state = self._tracker_wrapper.props.tracker_available if tracker_available_state != TrackerState.AVAILABLE: self._tracker_wrapper.connect("notify::tracker-available", self._on_tracker_available_changed) else: self._on_tracker_available_changed(None, None) for plugin in self._registry.get_plugins(False): plugin_id = plugin.get_id() # Activate the Tracker plugin only when TrackerWrapper # is available by listening to the tracker-available # property, so skip it here. if plugin_id != "grl-tracker3": try: self._registry.activate_plugin_by_id(plugin_id) except GLib.GError: self._log.debug( "Failed to activate {} plugin.".format(plugin_id)) weakref.finalize(self, Grl.deinit)
def __init__(self, method_name): super(TestRegistry, self).__init__(method_name) Grl.init([]) self.registry = Grl.Registry.get_default() plugin_paths = util.GRL_PLUGIN_PATH.split(':') for path in plugin_paths: if path: entries = os.listdir(path) self.EXISTING_LIBRARY_PATH = os.path.join(path, entries[0]) break print self.EXISTING_LIBRARY_PATH
def _init(): Grl.init([]) registry = Grl.Registry.get_default() fs_config = Grl.Config.new("grl-filesystem", None) fs_config.set_string("base-path", _tempdir) registry.add_config(fs_config) try: registry.load_plugin_by_id("grl-filesystem") except GLib.Error: pass
def __init__(self, source, application, tracker_wrapper): """Initialize the Tracker wrapper :param Grl.TrackerSource source: The Tracker source to wrap :param Application application: Application instance :param TrackerWrapper tracker_wrapper: The TrackerWrapper instance """ super().__init__() self._application = application coremodel = application.props.coremodel self._log = application.props.log self._songs_model = Gio.ListStore.new(CoreSong) coremodel.props.songs_proxy.append(self._songs_model) self._source = None self._albums_model = Gio.ListStore.new(CoreAlbum) coremodel.props.albums_proxy.append(self._albums_model) self._album_ids = {} self._artists_model = Gio.ListStore.new(CoreArtist) coremodel.props.artists_proxy.append(self._artists_model) self._artist_ids = {} self._hash = {} self._song_search_proxy = coremodel.props.songs_search_proxy self._album_search_model = coremodel.props.albums_search self._artist_search_model = coremodel.props.artists_search self._batch_changed_media_ids = {} self._content_changed_timeout = None self._tracker_playlists = None self._tracker_wrapper = tracker_wrapper self._notificationmanager = application.props.notificationmanager self._song_search_tracker = Gfm.FilterListModel.new(self._songs_model) self._song_search_tracker.set_filter_func(lambda a: False) self._song_search_proxy.append(self._song_search_tracker) self._fast_options = Grl.OperationOptions() self._fast_options.set_resolution_flags( Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY) self._full_options = Grl.OperationOptions() self._full_options.set_resolution_flags( Grl.ResolutionFlags.FULL | Grl.ResolutionFlags.IDLE_RELAY) self._content_changed_id = None self.props.source = source self._initial_songs_fill() self._initial_albums_fill() self._initial_artists_fill()
def test_default_values(self): options = Grl.OperationOptions() self.assertEqual(options.get_skip(), 0) self.assertEqual(options.get_count(), Grl.COUNT_INFINITY) self.assertEqual(options.get_flags(), Grl.MetadataResolutionFlags.NORMAL) self.assertEqual(options.get_type_filter(), Grl.TypeFilter.ALL)
def test_key_filters_with_caps(self): caps = Grl.Caps() release_date = GLib.DateTime.new_utc(1994, 1, 1, 12, 0, 0) caps.set_key_filter( [Grl.METADATA_KEY_ARTIST, Grl.METADATA_KEY_CREATION_DATE]) options = Grl.OperationOptions.new(caps) self.assertTrue( options.set_key_filter_value(Grl.METADATA_KEY_ARTIST, "NOFX")) self.assertFalse( options.set_key_filter_value(Grl.METADATA_KEY_ALBUM, "Punk in Drublic")) self.assertTrue( options.set_key_filter_value(Grl.METADATA_KEY_CREATION_DATE, release_date)) filter_list = options.get_key_filter_list() filter_list.sort() expected_filters = [ Grl.METADATA_KEY_ARTIST, Grl.METADATA_KEY_CREATION_DATE ] expected_filters.sort() self.assertEqual(filter_list, expected_filters) self.assertEqual(options.get_key_filter(Grl.METADATA_KEY_ARTIST), "NOFX") self.assertEqual(options.get_key_filter(Grl.METADATA_KEY_ALBUM), None) filter_date = options.get_key_filter(Grl.METADATA_KEY_CREATION_DATE) self.assertTrue(filter_date is not None) self.assertEqual(filter_date.format("%FT%H:%M:%S:%Z"), release_date.format("%FT%H:%M:%S:%Z"))
def _add_search_item(self, source, param, item, remaining=0, data=None): if not item: if (grilo._search_callback_counter == 0 and grilo.search_source): self.props.search_state = Search.State.NO_RESULT return if data != self.model: return artist = utils.get_artist_name(item) album = utils.get_album_title(item) key = '%s-%s' % (artist, album) if key not in self._albums: self._albums[key] = Grl.Media() self._albums[key].set_title(album) self._albums[key].add_artist(artist) self._albums[key].set_source(source.get_id()) self._albums[key].songs = [] self._add_item( source, None, self._albums[key], 0, [self.model, 'album']) self._add_item( source, None, self._albums[key], 0, [self.model, 'artist']) self._albums[key].songs.append(item) self._add_item(source, None, item, 0, [self.model, 'song'])
def __init__(self): super(MainWindow, self).__init__(type=Gtk.WindowType.TOPLEVEL) self.connect('destroy', self._quit) self.set_title('Grilo Test UI using introspection') Grl.init([]) self._ui_state = UIState() self.BROWSE_KEYS = self._lookup_browse_keys() self.METADATA_KEYS = self._lookup_metadata_keys() self._launchers = UriLaunchers() self._setup_ui() self._load_plugins() self.show_all()
def _metadata_cb(self, source, media, data, error): if media != self._ui_state.cur_md_media: return metadata_model = MetadataListStore() self._contents_window.get_metadata().set_model(metadata_model) if media: keys = media.get_keys() for key in keys: value = media.get(key) desc = Grl.metadata_key_get_desc(key) metadata_model.append((desc, value)) print('%(keyname)s: %(keyvalue)s' % { 'keyname': desc, 'keyvalue': value }) if (isinstance(media, Grl.MediaAudio) or \ isinstance(media, Grl.MediaVideo) or \ isinstance(media, Grl.MediaImage)): self._ui_state.last_url = media.get_url() if self._ui_state.last_url: self._show_btn.set_sensitive(True) else: self._show_btn.set_sensitive(False)
def __init__(self, media=None, query=None, tag_text=None, source=None, coremodel=None, coreselection=None, grilo=None, tracker=None): super().__init__() if media: self.props.pl_id = media.get_id() self.props.title = utils.get_media_title(media) self.props.count = media.get_childcount() self.props.creation_date = media.get_creation_date() self.props.query = query self.props.tag_text = tag_text self._model = None self._source = source self._coremodel = coremodel self._coreselection = coreselection self._grilo = grilo self._tracker = tracker self._fast_options = Grl.OperationOptions() self._fast_options.set_resolution_flags( Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY) self._songs_todelete = []
def _add_search_item(self, source, param, item, remaining=0, data=None): if not item: if grilo._search_callback_counter == 0 and grilo.search_source: self.emit('no-music-found') return if data != self.model: return artist = utils.get_artist_name(item) album = utils.get_album_title(item) composer = item.get_composer() key = '%s-%s' % (artist, album) if key not in self._albums: self._albums[key] = Grl.Media() self._albums[key].set_title(album) self._albums[key].add_artist(artist) self._albums[key].set_composer(composer) self._albums[key].set_source(source.get_id()) self._albums[key].songs = [] self._add_item(source, None, self._albums[key], 0, [self.model, 'album']) self._add_item(source, None, self._albums[key], 0, [self.model, 'artist']) self._albums[key].songs.append(item) self._add_item(source, None, item, 0, [self.model, 'song'])
def __init__(self, source, coremodel, coreselection, grilo, tracker_wrapper): """Initialize GrlTrackerPlaylists. :param Grl.TrackerSource source: The Tracker source to wrap :param CoreModel coremodel: CoreModel instance to use models from :param CoreSelection coreselection: CoreSelection instance to use :param CoreGrilo grilo: The CoreGrilo instance :param TrackerWrapper tracker_wrapper: The TrackerWrapper instance """ super().__init__() self._coremodel = coremodel self._coreselection = coreselection self._grilo = grilo self._source = source self._model = self._coremodel.props.playlists self._model_filter = self._coremodel.props.playlists_filter self._pls_todelete = [] self._tracker = tracker_wrapper.props.tracker self._fast_options = Grl.OperationOptions() self._fast_options.set_resolution_flags( Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY) self._initial_playlists_fill()
def __init__(self, source, application, tracker_wrapper, songs_hash): """Initialize GrlTrackerPlaylists. :param Grl.TrackerSource source: The Tracker source to wrap :param Application application: Application instance :param TrackerWrapper tracker_wrapper: The TrackerWrapper instance :param dict songs_hash: The songs hash table """ super().__init__() self._application = application self._coremodel = application.props.coremodel self._log = application.props.log self._source = source self._model = self._coremodel.props.playlists self._model_filter = self._coremodel.props.playlists_filter self._user_model_filter = self._coremodel.props.user_playlists_filter self._pls_todelete = [] self._songs_hash = songs_hash self._tracker = tracker_wrapper.props.local_db self._tracker_wrapper = tracker_wrapper self._notificationmanager = application.props.notificationmanager self._window = application.props.window self._user_model_filter.set_filter_func(self._user_playlists_filter) self._fast_options = Grl.OperationOptions() self._fast_options.set_resolution_flags( Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY) self._initial_playlists_fill()
def __init__(self, source, application): """Initialize a search wrapper Initialize a generic Grilo source search wrapper. :param Grl.Source source: The Grilo source to wrap :param Application application: Application instance """ super().__init__() self._application = application self._coreselection = application.props.coreselection self._log = application.props.log self._source = source coremodel = application.props.coremodel self._song_search_proxy = coremodel.props.songs_search_proxy self._song_search_store = Gio.ListStore.new(CoreSong) # FIXME: Workaround for adding the right list type to the proxy # list model. self._song_search_model = Gfm.FilterListModel.new( self._song_search_store) self._song_search_model.set_filter_func(lambda a: True) self._song_search_proxy.append(self._song_search_model) self._fast_options = Grl.OperationOptions() self._fast_options.set_count(25) self._fast_options.set_resolution_flags( Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY)
def __init__(self): super().__init__() self.playlist_path = GLib.build_filenamev( [GLib.get_user_data_dir(), "gnome-music", "playlists"]) if not (GLib.file_test(self.playlist_path, GLib.FileTest.IS_DIR)): GLib.mkdir_with_parents(self.playlist_path, int("0755", 8)) Grl.init(None) self.options = Grl.OperationOptions() self.options.set_resolution_flags(Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY) self.full_options = Grl.OperationOptions() self.full_options.set_resolution_flags( Grl.ResolutionFlags.FULL | Grl.ResolutionFlags.IDLE_RELAY) self.props.sources = {} self.blacklist = [ 'grl-filesystem', 'grl-bookmarks', 'grl-metadata-store', 'grl-podcasts', 'grl-spotify-cover' ] self.tracker = None self.changed_media_ids = [] self.pending_event_id = 0 self.changes_pending = { 'Albums': False, 'Artists': False, 'Songs': False } self.pending_changed_medias = [] self._thumbnail_sources = [] self._thumbnail_sources_timeout = None self.registry = Grl.Registry.get_default() self._tracker_wrapper = TrackerWrapper() self.tracker_sparql = self._tracker_wrapper.props.tracker self._tracker_wrapper.bind_property( "tracker-available", self, "tracker-available", GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE) self._find_sources()
def test_key_range_filtered_search(self): caps = self.plugin.get_caps(Grl.SupportedOps.SEARCH) options = Grl.OperationOptions.new(caps) # For now, we provide date _and_ time because of # https://bugzilla.gnome.org/show_bug.cgi?id=650968 start = Grl.date_time_from_iso8601("1989-07-13T00:00:00Z") end = Grl.date_time_from_iso8601("1989-07-15T00:00:00Z") start.ref() end.ref() options.set_key_range_filter_value(Grl.METADATA_KEY_MODIFICATION_DATE, start, end) l = self.plugin.search_sync( "a", [Grl.METADATA_KEY_ID, Grl.METADATA_KEY_MODIFICATION_DATE], options) expected_result = sorted(self._old_files) path_list = sorted(m.get_id() for m in l) self.assertEqual(path_list, expected_result)
def search(self, q, callback, data=None): options = self.options.copy() @log def _search_callback(source, param, item, remaining, data, error): callback(source, param, item, remaining, data) if self.search_source: if self.search_source.get_id().startswith('grl-upnp'): options.set_type_filter(Grl.TypeFilter.AUDIO) self.search_source.search(q, self.METADATA_KEYS, options, _search_callback, data) else: Grl.multiple_search([self.sources[key] for key in self.sources if key != 'grl-tracker-source'], q, self.METADATA_KEYS, options, _search_callback, data)
def __init__(self): super().__init__() self.playlist_path = GLib.build_filenamev([GLib.get_user_data_dir(), "gnome-music", "playlists"]) if not (GLib.file_test(self.playlist_path, GLib.FileTest.IS_DIR)): GLib.mkdir_with_parents(self.playlist_path, int("0755", 8)) Grl.init(None) self.options = Grl.OperationOptions() self.options.set_resolution_flags(Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY) self.full_options = Grl.OperationOptions() self.full_options.set_resolution_flags(Grl.ResolutionFlags.FULL | Grl.ResolutionFlags.IDLE_RELAY) self.props.sources = {} self.blacklist = [ 'grl-filesystem', 'grl-bookmarks', 'grl-metadata-store', 'grl-podcasts', 'grl-spotify-cover' ] self.tracker = None self.changed_media_ids = [] self.pending_event_id = 0 self.changes_pending = {'Albums': False, 'Artists': False, 'Songs': False} self.pending_changed_medias = [] self._thumbnail_sources = [] self._thumbnail_sources_timeout = None self.registry = Grl.Registry.get_default() self._tracker_wrapper = TrackerWrapper() self.tracker_sparql = self._tracker_wrapper.props.tracker self._tracker_wrapper.bind_property( "tracker-available", self, "tracker-available", GObject.BindingFlags.BIDIRECTIONAL | GObject.BindingFlags.SYNC_CREATE) self._find_sources()
def test_key_range_filtered_search(self): caps = self.plugin.get_caps(Grl.SupportedOps.SEARCH) options = Grl.OperationOptions.new(caps) # For now, we provide date _and_ time because of # https://bugzilla.gnome.org/show_bug.cgi?id=650968 start = Grl.date_time_from_iso8601("1989-07-13T00:00:00Z") end = Grl.date_time_from_iso8601("1989-07-15T00:00:00Z") start.ref() end.ref() options.set_key_range_filter_value(Grl.METADATA_KEY_MODIFICATION_DATE, start, end) l = self.plugin.search_sync("a", [Grl.METADATA_KEY_ID, Grl.METADATA_KEY_MODIFICATION_DATE], options) expected_result = sorted(self._old_files) path_list = sorted(m.get_id() for m in l) self.assertEqual(path_list, expected_result)
def _populate_model(self): query = """ SELECT rdf:type(?song) ?song AS ?tracker_urn tracker:id(?entry) AS ?id nie:url(?song) AS ?url nie:title(?song) AS ?title nmm:artistName(nmm:performer(?song)) AS ?artist nie:title(nmm:musicAlbum(?song)) AS ?album nfo:duration(?song) AS ?duration ?tag AS ?favourite nie:contentAccessed(?song) AS ?last_played_time nie:usageCounter(?song) AS ?play_count WHERE { ?playlist a nmm:Playlist ; a nfo:MediaList ; nfo:hasMediaFileListEntry ?entry . ?entry a nfo:MediaFileListEntry ; nfo:entryUrl ?url . ?song a nmm:MusicPiece ; a nfo:FileDataObject ; nie:url ?url . OPTIONAL { ?song nao:hasTag ?tag . FILTER( ?tag = nao:predefined-tag-favorite ) } FILTER ( %(filter_clause)s ) FILTER ( NOT EXISTS { ?song a nmm:Video } && NOT EXISTS { ?song a nmm:Playlist } ) } ORDER BY nfo:listPosition(?entry) """.replace('\n', ' ').strip() % { 'filter_clause': 'tracker:id(?playlist) = ' + self.props.pl_id } def _add_to_playlist_cb(source, op_id, media, remaining, user_data, error): if not media: self.props.count = self._model.get_n_items() self.emit("playlist-loaded") return coresong = CoreSong(media, self._coreselection, self._grilo) if coresong not in self._songs_todelete: self._model.append(coresong) options = Grl.OperationOptions() options.set_resolution_flags(Grl.ResolutionFlags.FAST_ONLY | Grl.ResolutionFlags.IDLE_RELAY) self._source.query(query, self.METADATA_KEYS, options, _add_to_playlist_cb, None)
def test_key_filter(self): caps = Grl.Caps() self.assertEqual(caps.get_key_filter(), []) keys = [Grl.METADATA_KEY_ARTIST, Grl.METADATA_KEY_ALBUM] caps.set_key_filter(keys) self.assertEqual(caps.get_key_filter(), keys) self.assertTrue(caps.is_key_filter(Grl.METADATA_KEY_ARTIST)) self.assertTrue(caps.is_key_filter(Grl.METADATA_KEY_ALBUM)) self.assertFalse(caps.is_key_filter(Grl.METADATA_KEY_INVALID)) self.assertFalse(caps.is_key_filter( Grl.METADATA_KEY_MODIFICATION_DATE))
def _store_btn_clicked_cb(self, *args): selection = self._browser_window.get_browser().get_selection() success, model, iter = selection.get_selected() if success: source = model.get_value(iter, BrowserListStore.SOURCE_COLUMN) container = model.get_value(iter, BrowserListStore.CONTENT_COLUMN) # dialog = StoreContentDialog(self) if dialog.run() == Gtk.ResponseType.OK: url = dialog.get_url() if url: media = Grl.Media() media.set_url(url) else: media = Grl.MediaBox() media.set_title(dialog.get_title()) media.set_description(dialog.get_description()) source.store(container, media, self._store_cb, None) dialog.destroy()
def __init__(self, coremodel, coreselection): super().__init__() self._coremodel = coremodel self._coreselection = coreselection self._search_wrappers = {} self._thumbnail_sources = [] self._thumbnail_sources_timeout = None self._wrappers = {} Grl.init(None) self._registry = Grl.Registry.get_default() config = Grl.Config.new("grl-lua-factory", "grl-theaudiodb-cover") config.set_api_key(self._theaudiodb_api_key) self._registry.add_config(config) self._registry.connect('source-added', self._on_source_added) self._registry.connect('source-removed', self._on_source_removed) self._registry.load_all_plugins(True)
def search(self, source, text): self._cancel_current_operation() state = OperationState(text) if source: search_id = source.search(text, self.BROWSE_KEYS, 0, self.BROWSE_CHUNK_SIZE, self.BROWSE_FLAGS, self._search_cb, state) else: search_id = Grl.multiple_search(None, text, self.BROWSE_KEYS, self.BROWSE_MAX_COUNT, self.BROWSE_FLAGS, self._search_cb, state) self._clear_panes() self._operation_started(source, search_id, source is None)
def _metadata_cb(self, source, media, data, error): if media != self._ui_state.cur_md_media: return metadata_model = MetadataListStore() self._contents_window.get_metadata().set_model(metadata_model) if media: keys = media.get_keys() for key in keys: value = str(media.get(key)) desc = Grl.metadata_key_get_desc(key) metadata_model.append((desc, value)) print ('%(keyname)s: %(keyvalue)s' % {'keyname':desc, 'keyvalue':value}) if (isinstance(media, Grl.MediaAudio) or \ isinstance(media, Grl.MediaVideo) or \ isinstance(media, Grl.MediaImage)): self._ui_state.last_url = media.get_url() if self._ui_state.last_url: self._show_btn.set_sensitive(True) else: self._show_btn.set_sensitive(False)
media.set_publication_date(date) d = media.get_publication_date() self.assertTrue(d is not None) self.assertEqual(d.get_year(), 2001) self.assertEqual(d.get_month(), 2) self.assertEqual(d.get_day_of_month(), 3) self.assertEqual(d.get_hour(), 4) self.assertEqual(d.get_minute(), 5) self.assertEqual(d.get_second(), 6) self.assertEqual(d.format("%FT%H:%M:%S%Z"), date.format("%FT%H:%M:%S%Z")) # date only date_string = "2001-02-03" date = Grl.date_time_from_iso8601 (date_string) media.set_publication_date(date) d = media.get_publication_date() self.assertTrue(d is not None) self.assertEqual(d.get_year(), 2001) self.assertEqual(d.get_month(), 2) self.assertEqual(d.get_day_of_month(), 3) self.assertEqual(d.get_hour(), 12) self.assertEqual(d.get_minute(), 0) self.assertEqual(d.get_second(), 0) self.assertEqual(d.format("%FT%H:%M:%S%Z"), date.format("%FT%H:%M:%S%Z")) self.assertEqual(d.format("%FT%H:%M:%S%Z"), date_string + "T12:00:00UTC") # who said "this is ugly" ? Grl.init([]) registry = Grl.Registry.get_default() registry.load_by_id("grl-filesystem")
query = None if isinstance(item, Grl.MediaAudio): query = Query.get_album_for_song_id(item_id) else: query = Query.get_album_for_album_id(item_id) options = self.full_options.copy() options.set_count(1) self.search_source.query(query, self.METADATA_THUMBNAIL_KEYS, options, callback, data) @log def get_playlist_with_id(self, playlist_id, callback): options = self.options.copy() query = Query.get_playlist_with_id(playlist_id) self.tracker.query(query, self.METADATA_KEYS, options, callback, None) @log def get_playlist_song_with_id(self, playlist_id, entry_id, callback): options = self.options.copy() query = Query.get_playlist_song_with_id(playlist_id, entry_id) self.tracker.query(query, self.METADATA_KEYS, options, callback, None) Grl.init(None) grilo = Grilo()