tracker-0.16.2/examples/libtracker-extract/tracker-extract-mockup.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found tracker-extract-mockup.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * Copyright (C) 2011, Your name <Your email address>
  3  *
  4  * This library is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2.1 of the License, or (at your option) any later version.
  8  *
  9  * This library is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with this library; if not, write to the
 16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17  * Boston, MA  02110-1301, USA.
 18  */
 19 
 20 #include <stdio.h>
 21 
 22 /* TODO: Include any 3rd party libraries here. */
 23 
 24 #include <gio/gio.h>
 25 
 26 #include <libtracker-extract/tracker-extract.h>
 27 #include <libtracker-sparql/tracker-sparql.h>
 28 
 29 G_MODULE_EXPORT gboolean
 30 tracker_extract_get_metadata (TrackerExtractInfo *info_)
 31 {
 32 	/* NOTE: This function has to exist, tracker-extract checks
 33 	 * the symbole table for this function and if it doesn't
 34 	 * exist, the module is not loaded to be used as an extractor.
 35 	 */
 36 
 37 	/* File information */
 38 	FILE *f;
 39 	GFileInfo *info;
 40 	GFile *file;
 41 	GError *error = NULL;
 42 	gchar *filename;
 43 	goffset size;
 44 
 45 	/* Data input */
 46 	gchar *title_tagv1;
 47 	gchar *title_tagv2;
 48 	gchar *title_tagv3;
 49 	gchar *title_unknown;
 50 	gchar *lyricist_tagv2;
 51 	gchar *lyricist_unknown;
 52 
 53 	/* Coalesced input */
 54 	const gchar *title;
 55 	gchar *performer;
 56 	gchar *performer_uri;
 57 	const gchar *lyricist;
 58 	gchar *lyricist_uri;
 59 	gchar *album;
 60 	gchar *album_uri;
 61 	gchar *genre;
 62 	gchar *text;
 63 	gchar *recording_time;
 64 	gchar *copyright;
 65 	gchar *publisher;
 66 	gchar *comment;
 67 	gchar *composer;
 68 	gchar *composer_uri;
 69 	gint track_number;
 70 	gint track_count;
 71 	guint32 duration;
 72 	TrackerSparqlBuilder *metadata, *preupdate;
 73 
 74 	metadata = tracker_extract_info_get_metadata_builder (info_);
 75 	preupdate = tracker_extract_info_get_preupdate_builder (info_);
 76 
 77 	/* NOTE: File is not ref'd, so don't unref */
 78 	file = tracker_extract_info_get_file (info_);
 79 	filename = g_file_get_path (file);
 80 	info = g_file_query_info (file,
 81 	                          G_FILE_ATTRIBUTE_STANDARD_SIZE,
 82 	                          G_FILE_QUERY_INFO_NONE,
 83 	                          NULL,
 84 	                          &error);
 85 
 86 	if (G_UNLIKELY (error)) {
 87 		g_message ("Could not get size for '%s', %s",
 88 		           filename,
 89 		           error->message);
 90 		g_error_free (error);
 91 		size = 0;
 92 	} else {
 93 		size = g_file_info_get_size (info);
 94 		g_object_unref (info);
 95 	}
 96 
 97 	/* TODO: Do any pre-checks on the file
 98 	 * (i.e check file size so we don't handle files of 0 size)
 99 	 */
100 	if (size < 64) {
101 		g_free (filename);
102 		return FALSE;
103 	}
104 
105 	/* TODO: Open file */
106 	f = fopen (filename, "r");
107 
108 	if (!f) {
109 		g_free (filename);
110 		return FALSE;
111 	}
112 	
113 	/* TODO: Get data from file.
114 	 *
115 	 * (We will use dummy data for this example)
116 	 */
117 	title_tagv1 = NULL;
118 	title_tagv2 = g_strdup ("Burn The Witch");
119 	title_tagv3 = g_strdup ("");
120 	title_unknown = g_strdup ("Unknown");
121 
122 	lyricist_tagv2 = g_strdup ("Someone");
123 	lyricist_unknown = g_strdup ("Someone");
124 
125 	/* TODO: Close file */
126 	fclose (f);
127 
128 	/* TODO: Make sure we coalesce duplicate values */
129 	title = tracker_coalesce_strip (4, title_tagv1, title_tagv2, title_tagv3, title_unknown);
130 	lyricist = tracker_coalesce_strip (2, lyricist_tagv2, lyricist_unknown);
131 
132 	performer = g_strdup ("Stone Gods");
133 	composer = NULL;
134 	album = g_strdup ("Silver Spoons And Broken Bones");
135 	genre = g_strdup ("Rock");
136 	recording_time = NULL;
137 	publisher = NULL;
138 	text = g_strdup ("Some description");
139 	copyright = g_strdup ("Who knows?");
140 	comment = g_strdup ("I love this track");
141 	track_number = 1;
142 	track_count = 12;
143 	duration = 32;
144 
145 	/* TODO: Do any pre-updates
146 	 *
147 	 * (This involves creating any database nodes for consistent
148 	 *  data objects, for example, an artist which might be used n times)
149 	 */
150 	if (performer) {
151 		performer_uri = tracker_sparql_escape_uri_printf ("urn:artist:%s", performer);
152 
153 		tracker_sparql_builder_insert_open (preupdate, NULL);
154 		tracker_sparql_builder_subject_iri (preupdate, performer_uri);
155 		tracker_sparql_builder_predicate (preupdate, "a");
156 		tracker_sparql_builder_object (preupdate, "nmm:Artist");
157 		tracker_sparql_builder_predicate (preupdate, "nmm:artistName");
158 		tracker_sparql_builder_object_unvalidated (preupdate, performer);
159 		tracker_sparql_builder_insert_close (preupdate);
160 	} else {
161 		performer_uri = NULL;
162 	}
163 
164 	if (composer) {
165 		composer_uri = tracker_sparql_escape_uri_printf ("urn:artist:%s", composer);
166 
167 		tracker_sparql_builder_insert_open (preupdate, NULL);
168 		tracker_sparql_builder_subject_iri (preupdate, composer_uri);
169 		tracker_sparql_builder_predicate (preupdate, "a");
170 		tracker_sparql_builder_object (preupdate, "nmm:Artist");
171 		tracker_sparql_builder_predicate (preupdate, "nmm:artistName");
172 		tracker_sparql_builder_object_unvalidated (preupdate, composer);
173 		tracker_sparql_builder_insert_close (preupdate);
174 	} else {
175 		composer_uri = NULL;
176 	}
177 
178 	if (lyricist) {
179 		lyricist_uri = tracker_sparql_escape_uri_printf ("urn:artist:%s", lyricist);
180 
181 		tracker_sparql_builder_insert_open (preupdate, NULL);
182 		tracker_sparql_builder_subject_iri (preupdate, lyricist_uri);
183 		tracker_sparql_builder_predicate (preupdate, "a");
184 		tracker_sparql_builder_object (preupdate, "nmm:Artist");
185 		tracker_sparql_builder_predicate (preupdate, "nmm:artistName");
186 		tracker_sparql_builder_object_unvalidated (preupdate, lyricist);
187 		tracker_sparql_builder_insert_close (preupdate);
188 	} else {
189 		lyricist_uri = NULL;
190 	}
191 
192 	if (album) {
193 		album_uri = tracker_sparql_escape_uri_printf ("urn:album:%s", album);
194 
195 		tracker_sparql_builder_insert_open (preupdate, NULL);
196 		tracker_sparql_builder_subject_iri (preupdate, album_uri);
197 		tracker_sparql_builder_predicate (preupdate, "a");
198 		tracker_sparql_builder_object (preupdate, "nmm:MusicAlbum");
199 		/* FIXME: nmm:albumTitle is now deprecated
200 		 * tracker_sparql_builder_predicate (preupdate, "nie:title");
201 		 */
202 		tracker_sparql_builder_predicate (preupdate, "nmm:albumTitle");
203 		tracker_sparql_builder_object_unvalidated (preupdate, album);
204 		tracker_sparql_builder_insert_close (preupdate);
205 
206 		if (track_count > 0) {
207 			tracker_sparql_builder_delete_open (preupdate, NULL);
208 			tracker_sparql_builder_subject_iri (preupdate, album_uri);
209 			tracker_sparql_builder_predicate (preupdate, "nmm:albumTrackCount");
210 			tracker_sparql_builder_object_variable (preupdate, "unknown");
211 			tracker_sparql_builder_delete_close (preupdate);
212 
213 			tracker_sparql_builder_where_open (preupdate);
214 			tracker_sparql_builder_subject_iri (preupdate, album_uri);
215 			tracker_sparql_builder_predicate (preupdate, "nmm:albumTrackCount");
216 			tracker_sparql_builder_object_variable (preupdate, "unknown");
217 			tracker_sparql_builder_where_close (preupdate);
218 
219 			tracker_sparql_builder_insert_open (preupdate, NULL);
220 			tracker_sparql_builder_subject_iri (preupdate, album_uri);
221 			tracker_sparql_builder_predicate (preupdate, "nmm:albumTrackCount");
222 			tracker_sparql_builder_object_int64 (preupdate, track_count);
223 			tracker_sparql_builder_insert_close (preupdate);
224 		}
225 	} else {
226 		album_uri = NULL;
227 	}
228 
229 	/* TODO: Do any metadata updates
230 	 *
231 	 * (This is where you can use entities created in the
232 	 *  pre-updates part, like an artist).
233 	 */
234 	tracker_sparql_builder_predicate (metadata, "a");
235 	tracker_sparql_builder_object (metadata, "nmm:MusicPiece");
236 	tracker_sparql_builder_object (metadata, "nfo:Audio");
237 
238 	if (title) {
239 		tracker_sparql_builder_predicate (metadata, "nie:title");
240 		tracker_sparql_builder_object_unvalidated (metadata, title);
241 	}
242 
243 	if (lyricist_uri) {
244 		tracker_sparql_builder_predicate (metadata, "nmm:lyricist");
245 		tracker_sparql_builder_object_iri (metadata, lyricist_uri);
246 		g_free (lyricist_uri);
247 	}
248 
249 	if (performer_uri) {
250 		tracker_sparql_builder_predicate (metadata, "nmm:performer");
251 		tracker_sparql_builder_object_iri (metadata, performer_uri);
252 		g_free (performer_uri);
253 	}
254 
255 	if (composer_uri) {
256 		tracker_sparql_builder_predicate (metadata, "nmm:composer");
257 		tracker_sparql_builder_object_iri (metadata, composer_uri);
258 		g_free (composer_uri);
259 	}
260 
261 	if (album_uri) {
262 		tracker_sparql_builder_predicate (metadata, "nmm:musicAlbum");
263 		tracker_sparql_builder_object_iri (metadata, album_uri);
264 		g_free (album_uri);
265 	}
266 
267 	if (recording_time) {
268 		tracker_sparql_builder_predicate (metadata, "nie:contentCreated");
269 		tracker_sparql_builder_object_unvalidated (metadata, recording_time);
270 		g_free (recording_time);
271 	}
272 
273 	if (genre) {
274 		tracker_sparql_builder_predicate (metadata, "nfo:genre");
275 		tracker_sparql_builder_object_unvalidated (metadata, genre);
276 		g_free (genre);
277 	}
278 
279 	if (copyright) {
280 		tracker_sparql_builder_predicate (metadata, "nie:copyright");
281 		tracker_sparql_builder_object_unvalidated (metadata, copyright);
282 		g_free (copyright);
283 	}
284 
285 	if (comment) {
286 		tracker_sparql_builder_predicate (metadata, "nie:comment");
287 		tracker_sparql_builder_object_unvalidated (metadata, comment);
288 		g_free (comment);
289 	}
290 
291 	if (publisher) {
292 		tracker_sparql_builder_predicate (metadata, "nco:publisher");
293 		tracker_sparql_builder_object_blank_open (metadata);
294 		tracker_sparql_builder_predicate (metadata, "a");
295 		tracker_sparql_builder_object (metadata, "nco:Contact");
296 		tracker_sparql_builder_predicate (metadata, "nco:fullname");
297 		tracker_sparql_builder_object_unvalidated (metadata, publisher);
298 		tracker_sparql_builder_object_blank_close (metadata);
299 		g_free (publisher);
300 	}
301 
302 	if (track_number > 0) {
303 		tracker_sparql_builder_predicate (metadata, "nmm:trackNumber");
304 		tracker_sparql_builder_object_int64 (metadata, track_number);
305 	}
306 
307 	if (duration > 0) {
308 		tracker_sparql_builder_predicate (metadata, "nfo:duration");
309 		tracker_sparql_builder_object_int64 (metadata, duration);
310 	}
311 
312 	if (text) {
313 		/* NOTE: This is for Full Text Search (FTS) indexing content */
314 		tracker_sparql_builder_predicate (metadata, "nie:plainTextContent");
315 		tracker_sparql_builder_object_unvalidated (metadata, text);
316 		g_free (text);
317 	}
318 
319 	/* TODO: Clean up */
320 	g_free (title_tagv1);
321 	g_free (title_tagv2);
322 	g_free (title_tagv3);
323 	g_free (title_unknown);
324 
325 	g_free (lyricist_tagv2);
326 	g_free (lyricist_unknown);
327 
328 	g_free (album);
329 	g_free (composer);
330 	g_free (performer);
331 	g_free (filename);
332 
333 	return TRUE;
334 }