/* discoverer.c generated by valac 0.11.4, the Vala compiler
 * generated from discoverer.vala, do not modify */

#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include <gst/pbutils/pbutils.h>
#include <gst/gst.h>
#include <stdio.h>

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _gst_mini_object_unref0(var) ((var == NULL) ? NULL : (var = (gst_mini_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))



gboolean query_is_directory (GFile* file);
gboolean query_is_file (GFile* file);
void enumerate (GFile* directory);
void get_track_info (GFile* file);
gint _vala_main (gchar** args, int args_length1);


gboolean query_is_directory (GFile* file) {
	gboolean result = FALSE;
	GFileType _tmp0_;
	g_return_val_if_fail (file != NULL, FALSE);
	_tmp0_ = g_file_query_file_type (file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL);
	result = _tmp0_ == G_FILE_TYPE_DIRECTORY;
	return result;
}


gboolean query_is_file (GFile* file) {
	gboolean result = FALSE;
	GFileType _tmp0_;
	g_return_val_if_fail (file != NULL, FALSE);
	_tmp0_ = g_file_query_file_type (file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL);
	result = _tmp0_ != G_FILE_TYPE_DIRECTORY;
	return result;
}


void enumerate (GFile* directory) {
	GFileEnumerator* _tmp0_ = NULL;
	GFileEnumerator* enumerator;
	GFileInfo* file_info;
	GError * _inner_error_ = NULL;
	g_return_if_fail (directory != NULL);
	_tmp0_ = g_file_enumerate_children (directory, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &_inner_error_);
	enumerator = _tmp0_;
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
	file_info = NULL;
	while (TRUE) {
		GFileInfo* _tmp1_ = NULL;
		GFileInfo* _tmp2_;
		GFileInfo* _tmp3_;
		const gchar* _tmp4_ = NULL;
		gchar* _tmp5_;
		gchar* name;
		GFile* _tmp6_ = NULL;
		GFile* child;
		gboolean _tmp7_ = FALSE;
		gboolean _tmp8_;
		_tmp1_ = g_file_enumerator_next_file (enumerator, NULL, &_inner_error_);
		_tmp2_ = _tmp1_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (file_info);
			_g_object_unref0 (enumerator);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
		_tmp3_ = _tmp2_;
		_g_object_unref0 (file_info);
		file_info = _tmp3_;
		if (!(file_info != NULL)) {
			break;
		}
		_tmp4_ = g_file_info_get_name (file_info);
		_tmp5_ = g_strdup (_tmp4_);
		name = _tmp5_;
		_tmp6_ = g_file_get_child (directory, name);
		child = _tmp6_;
		_tmp8_ = query_is_file (child);
		if (_tmp8_) {
			gboolean _tmp9_;
			_tmp9_ = g_str_has_suffix (name, ".mp3");
			_tmp7_ = _tmp9_;
		} else {
			_tmp7_ = FALSE;
		}
		if (_tmp7_) {
			get_track_info (child);
		} else {
			gboolean _tmp10_;
			_tmp10_ = query_is_directory (child);
			if (_tmp10_) {
				enumerate (child);
			}
		}
		_g_object_unref0 (child);
		_g_free0 (name);
	}
	_g_object_unref0 (file_info);
	_g_object_unref0 (enumerator);
}


void get_track_info (GFile* file) {
	GstDiscoverer* d;
	GstDiscovererInfo* i;
	GstDiscoverer* _tmp0_ = NULL;
	GstDiscoverer* _tmp1_;
	GstDiscoverer* _tmp2_;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* path;
	gchar* _tmp6_;
	GstDiscovererInfo* _tmp7_ = NULL;
	GstDiscovererInfo* _tmp8_;
	GstDiscovererInfo* _tmp9_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (file != NULL);
	d = NULL;
	i = NULL;
	_tmp0_ = gst_discoverer_new ((GstClockTime) (10 * GST_SECOND), &_inner_error_);
	_tmp1_ = _tmp0_;
	if (_inner_error_ != NULL) {
		goto __catch0_g_error;
	}
	_tmp2_ = _tmp1_;
	_g_object_unref0 (d);
	d = _tmp2_;
	_tmp3_ = g_file_get_path (file);
	_tmp4_ = _tmp3_;
	path = (_tmp5_ = g_strconcat ("file://", _tmp4_, NULL), _g_free0 (_tmp4_), _tmp5_);
	_tmp6_ = g_strconcat (path, "\n", NULL);
	fprintf (stdout, "%s", _tmp6_);
	_g_free0 (_tmp6_);
	_tmp7_ = gst_discoverer_discover_uri (d, path, &_inner_error_);
	_tmp8_ = _tmp7_;
	if (_inner_error_ != NULL) {
		_g_free0 (path);
		goto __catch1_g_error;
	}
	_tmp9_ = _tmp8_;
	_gst_mini_object_unref0 (i);
	i = _tmp9_;
	gst_discoverer_info_get_tags (i);
	_g_free0 (path);
	goto __finally1;
	__catch1_g_error:
	{
		GError * e;
		gchar* _tmp10_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp10_ = g_strconcat (e->message, "\n", NULL);
		fprintf (stdout, "%s", _tmp10_);
		_g_free0 (_tmp10_);
		_g_error_free0 (e);
	}
	__finally1:
	if (_inner_error_ != NULL) {
		goto __catch0_g_error;
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError * e;
		gchar* _tmp11_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp11_ = g_strconcat (e->message, "\n", NULL);
		fprintf (stdout, "%s", _tmp11_);
		_g_free0 (_tmp11_);
		_g_error_free0 (e);
	}
	__finally0:
	if (_inner_error_ != NULL) {
		_gst_mini_object_unref0 (i);
		_g_object_unref0 (d);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
	_gst_mini_object_unref0 (i);
	_g_object_unref0 (d);
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	GFile* _tmp0_ = NULL;
	GFile* _tmp1_;
	gst_init (&args_length1, &args);
	_tmp0_ = g_file_new_for_path ("/home/andrew/Music");
	_tmp1_ = _tmp0_;
	enumerate (_tmp1_);
	_g_object_unref0 (_tmp1_);
	result = 0;
	return result;
}


int main (int argc, char ** argv) {
	g_type_init ();
	return _vala_main (argv, argc);
}
