Beispiel #1
0
static gboolean
get_video_play_url_cb (GVimeoVideoURLData *url_data)
{
  gchar *url = NULL;
  TotemPlParser *parser;
  TotemPlParserResult res;

  parser = totem_pl_parser_new ();
  g_signal_connect (parser, "entry-parsed",
                    G_CALLBACK (entry_parsed_cb), &url);
  res = totem_pl_parser_parse (parser,
                               url_data->vimeo_url,
                               FALSE);
  if (res != TOTEM_PL_PARSER_RESULT_SUCCESS)
    url_data->callback (NULL, url_data->user_data);
  else
    url_data->callback (url, url_data->user_data);
  g_clear_object (&parser);

  g_object_unref (url_data->vimeo);
  g_free (url_data->vimeo_url);
  g_slice_free (GVimeoVideoURLData, url_data);

  return FALSE;
}
void
rb_iradio_source_add_from_playlist (RBIRadioSource *source,
				    const char     *uri)
{
	TotemPlParser *parser = totem_pl_parser_new ();
	char *real_uri;

	real_uri = guess_uri_scheme (uri);
	if (real_uri)
		uri = real_uri;

	g_signal_connect_object (parser, "entry-parsed",
				 G_CALLBACK (handle_playlist_entry_cb),
				 source, 0);
	g_object_set (parser, "recurse", FALSE, NULL);

	switch (totem_pl_parser_parse (parser, uri, FALSE)) {
	case TOTEM_PL_PARSER_RESULT_UNHANDLED:
	case TOTEM_PL_PARSER_RESULT_IGNORED:
		/* maybe it's the actual stream URL, then */
		rb_iradio_source_add_station (source, uri, NULL, NULL);
		break;

	default:
	case TOTEM_PL_PARSER_RESULT_SUCCESS:
	case TOTEM_PL_PARSER_RESULT_ERROR:
		break;
	}
	g_object_unref (parser);
	g_free (real_uri);
}
G_MODULE_EXPORT gboolean
tracker_extract_get_metadata (TrackerExtractInfo *info)
{
	TotemPlParser *pl;
	TrackerSparqlBuilder *metadata;
	PlaylistMetadata data;
	GFile *file;
	gchar *uri;

	pl = totem_pl_parser_new ();
	file = tracker_extract_info_get_file (info);
	uri = g_file_get_uri (file);
	metadata = tracker_extract_info_get_metadata_builder (info);

	data.track_counter = PLAYLIST_DEFAULT_NO_TRACKS;
	data.total_time =  PLAYLIST_DEFAULT_DURATION;
	data.title = NULL;
	data.metadata = metadata;

	g_object_set (pl, "recurse", FALSE, "disable-unsafe", TRUE, NULL);

	g_signal_connect (G_OBJECT (pl), "playlist-started", G_CALLBACK (playlist_started), &data);
	g_signal_connect (G_OBJECT (pl), "entry-parsed", G_CALLBACK (entry_parsed), &data);

	tracker_sparql_builder_predicate (metadata, "a");
	tracker_sparql_builder_object (metadata, "nmm:Playlist");
	tracker_sparql_builder_object (metadata, "nfo:MediaList");

	if (totem_pl_parser_parse (pl, uri, FALSE) == TOTEM_PL_PARSER_RESULT_SUCCESS) {
		if (data.title != NULL) {
			g_message ("Playlist title:'%s'", data.title);
			tracker_sparql_builder_predicate (metadata, "nie:title");
			tracker_sparql_builder_object_unvalidated (metadata, data.title);
			g_free (data.title);
		} else {
			g_message ("Playlist has no title, attempting to get one from filename");
			tracker_guarantee_title_from_file (metadata, "nie:title", NULL, uri, NULL);
		}

		if (data.total_time > 0) {
			tracker_sparql_builder_predicate (metadata, "nfo:listDuration");
			tracker_sparql_builder_object_int64 (metadata, data.total_time);
		}

		if (data.track_counter > 0) {
			tracker_sparql_builder_predicate (metadata, "nfo:entryCounter");
			tracker_sparql_builder_object_int64 (metadata, data.track_counter);
		}
	} else {
		g_warning ("Playlist could not be parsed, no error given");
	}

	g_object_unref (pl);
	g_free (uri);

	return TRUE;
}
gboolean
brasero_project_open_audio_playlist_project (const gchar *uri,
					     BraseroBurnSession *session,
					     gboolean warn_user)
{
	TotemPlParser *parser;
	TotemPlParserResult result;
	GFile *file;
	char *_uri;

	file = g_file_new_for_commandline_arg (uri);
	_uri = g_file_get_uri (file);
	g_object_unref (file);

	parser = totem_pl_parser_new ();
	g_object_set (parser,
		      "recurse", FALSE,
		      "disable-unsafe", TRUE,
		      NULL);

	g_signal_connect (parser,
			  "playlist-started",
			  G_CALLBACK (brasero_project_playlist_playlist_started),
			  session);

	g_signal_connect (parser,
			  "entry-parsed",
			  G_CALLBACK (brasero_project_playlist_entry_parsed),
			  session);

	result = totem_pl_parser_parse (parser, _uri, FALSE);
	if (result != TOTEM_PL_PARSER_RESULT_SUCCESS) {
		if (warn_user)
			brasero_project_invalid_project_dialog (_("It does not seem to be a valid Brasero project"));
	}

	g_free (_uri);
	g_object_unref (parser);

	return (result == TOTEM_PL_PARSER_RESULT_SUCCESS);
}
static char *
get_special_url (GFile *file)
{
	char *path, *orig_uri, *uri, *mime_type;
	TotemPlParser *parser;
	TotemPlParserResult res;

	path = g_file_get_path (file);

	mime_type = g_content_type_guess (path, NULL, 0, NULL);
	g_free (path);
	if (g_strcmp0 (mime_type, "application/x-cd-image") != 0) {
		g_free (mime_type);
		return NULL;
	}
	g_free (mime_type);

	uri = NULL;
	orig_uri = g_file_get_uri (file);

	parser = totem_pl_parser_new ();
	g_signal_connect (parser, "entry-parsed",
			  G_CALLBACK (entry_parsed_cb), &uri);

	res = totem_pl_parser_parse (parser, orig_uri, FALSE);

	g_free (orig_uri);
	g_object_unref (parser);

	if (res == TOTEM_PL_PARSER_RESULT_SUCCESS)
		return uri;

	g_free (uri);

	return NULL;
}
gboolean
rb_podcast_parse_load_feed (RBPodcastChannel *data,
			    const char *file_name,
			    gboolean existing_feed,
			    GError **error)
{
	GFile *file;
	GFileInfo *fileinfo;
	TotemPlParser *plparser;

	data->url = g_strdup (file_name);

	/* if the URL has a .rss, .xml or .atom extension (before the query string),
	 * don't bother checking the MIME type.
	 */
	if (rb_uri_could_be_podcast (file_name, &data->is_opml) || existing_feed) {
		rb_debug ("not checking mime type for %s (should be %s file)", file_name,
			  data->is_opml ? "OPML" : "Podcast");
	} else {
		GError *ferror = NULL;
		char *content_type;

		rb_debug ("checking mime type for %s", file_name);

		file = g_file_new_for_uri (file_name);
		fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, &ferror);
		if (ferror != NULL) {
			g_set_error (error,
				     RB_PODCAST_PARSE_ERROR,
				     RB_PODCAST_PARSE_ERROR_FILE_INFO,
				     _("Unable to check file type: %s"),
				     ferror->message);
			g_object_unref (file);
			g_clear_error (&ferror);
			return FALSE;
		}

		content_type = g_file_info_get_attribute_as_string (fileinfo, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
		g_object_unref (file);
		g_object_unref (fileinfo);

		if (content_type != NULL
		    && strstr (content_type, "html") == NULL
		    && strstr (content_type, "xml") == NULL
		    && strstr (content_type, "rss") == NULL
		    && strstr (content_type, "opml") == NULL) {
			g_set_error (error,
				     RB_PODCAST_PARSE_ERROR,
				     RB_PODCAST_PARSE_ERROR_MIME_TYPE,
				     _("Unexpected file type: %s"),
				     content_type);
			g_free (content_type);
			return FALSE;
		} else if (content_type != NULL
			   && strstr (content_type, "opml") != NULL) {
			data->is_opml = TRUE;
		}

		g_free (content_type);
	}

	plparser = totem_pl_parser_new ();
	g_object_set (plparser, "recurse", FALSE, "force", TRUE, NULL);
	g_signal_connect (G_OBJECT (plparser), "entry-parsed", G_CALLBACK (entry_parsed), data);
	g_signal_connect (G_OBJECT (plparser), "playlist-started", G_CALLBACK (playlist_started), data);
	g_signal_connect (G_OBJECT (plparser), "playlist-ended", G_CALLBACK (playlist_ended), data);

	if (totem_pl_parser_parse (plparser, file_name, FALSE) != TOTEM_PL_PARSER_RESULT_SUCCESS) {
		rb_debug ("Parsing %s as a Podcast failed", file_name);
		g_set_error (error,
			     RB_PODCAST_PARSE_ERROR,
			     RB_PODCAST_PARSE_ERROR_XML_PARSE,
			     _("Unable to parse the feed contents"));
		g_object_unref (plparser);
		return FALSE;
	}
	g_object_unref (plparser);

	/* treat empty feeds, or feeds that don't contain any downloadable items, as
	 * an error.
	 */
	if (data->posts == NULL) {
		rb_debug ("Parsing %s as a podcast succeeded, but the feed contains no downloadable items", file_name);
		g_set_error (error,
			     RB_PODCAST_PARSE_ERROR,
			     RB_PODCAST_PARSE_ERROR_NO_ITEMS,
			     _("The feed does not contain any downloadable items"));
		return FALSE;
	}

	rb_debug ("Parsing %s as a Podcast succeeded", file_name);
	return TRUE;
}