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

/*
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <locale.h>
#include <gst/gst.h>
#include <float.h>
#include <math.h>
#include <gio/gio.h>
#include <gst/pbutils/pbutils.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#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_tag_list_unref0(var) ((var == NULL) ? NULL : (var = (gst_tag_list_unref (var), NULL)))
#define _gst_date_time_unref0(var) ((var == NULL) ? NULL : (var = (gst_date_time_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_option_context_free0(var) ((var == NULL) ? NULL : (var = (g_option_context_free (var), NULL)))

static gint _vala_main (gchar** args,
                 gint args_length1);

static gpointer
_gst_tag_list_ref0 (gpointer self)
{
	return self ? gst_tag_list_ref (self) : NULL;
}

static gint
_vala_main (gchar** args,
            gint args_length1)
{
	GOptionContext* option_context = NULL;
	GOptionContext* _tmp0_;
	GOptionContext* _tmp1_;
	GOptionContext* _tmp2_;
	GOptionGroup* _tmp3_;
	gdouble clip_duration = 0.0;
	GDateTime* timestamp = NULL;
	GError* _inner_error0_ = NULL;
	gint result;
	setlocale (LC_NUMERIC, "C");
	_tmp0_ = g_option_context_new ("- shotwell video metadata reader helper binary");
	option_context = _tmp0_;
	_tmp1_ = option_context;
	g_option_context_set_help_enabled (_tmp1_, TRUE);
	_tmp2_ = option_context;
	_tmp3_ = gst_init_get_option_group ();
	g_option_context_add_group (_tmp2_, _tmp3_);
	timestamp = NULL;
	{
		GOptionContext* _tmp4_;
		GFile* f = NULL;
		const gchar* _tmp6_;
		GFile* _tmp7_;
		GstDiscoverer* d = NULL;
		GstDiscoverer* _tmp8_;
		GstDiscovererInfo* info = NULL;
		GstDiscoverer* _tmp9_;
		GFile* _tmp10_;
		gchar* _tmp11_;
		gchar* _tmp12_;
		GstDiscovererInfo* _tmp13_;
		GstDiscovererInfo* _tmp14_;
		GstDiscovererInfo* _tmp15_;
		GstDateTime* video_date = NULL;
		GstTagList* tags = NULL;
		GstDiscovererStreamInfo* stream_info = NULL;
		GstDiscovererInfo* _tmp16_;
		GstDiscovererStreamInfo* _tmp17_;
		GstDiscovererStreamInfo* _tmp18_;
		gboolean _tmp26_ = FALSE;
		GstTagList* _tmp27_;
		GDateTime* _tmp36_;
		_tmp4_ = option_context;
		g_option_context_parse (_tmp4_, (gint*) (&args_length1), &args, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		if (args_length1 < 2) {
			GError* _tmp5_;
			_tmp5_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Missing URI");
			_inner_error0_ = _tmp5_;
			goto __catch0_g_error;
		}
		_tmp6_ = args[1];
		_tmp7_ = g_file_new_for_commandline_arg (_tmp6_);
		f = _tmp7_;
		_tmp8_ = gst_discoverer_new ((GstClockTime) (GST_SECOND * 5), &_inner_error0_);
		d = _tmp8_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (f);
			goto __catch0_g_error;
		}
		_tmp9_ = d;
		_tmp10_ = f;
		_tmp11_ = g_file_get_uri (_tmp10_);
		_tmp12_ = _tmp11_;
		_tmp13_ = gst_discoverer_discover_uri (_tmp9_, _tmp12_, &_inner_error0_);
		_tmp14_ = _tmp13_;
		_g_free0 (_tmp12_);
		info = _tmp14_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_g_object_unref0 (d);
			_g_object_unref0 (f);
			goto __catch0_g_error;
		}
		_tmp15_ = info;
		clip_duration = ((gdouble) gst_discoverer_info_get_duration (_tmp15_)) / 1000000000.0;
		video_date = NULL;
		tags = NULL;
		_tmp16_ = info;
		_tmp17_ = gst_discoverer_info_get_stream_info (_tmp16_);
		stream_info = _tmp17_;
		_tmp18_ = stream_info;
		if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp18_, gst_discoverer_container_info_get_type ())) {
			GstDiscovererStreamInfo* _tmp19_;
			GstTagList* _tmp20_;
			GstTagList* _tmp21_;
			_tmp19_ = stream_info;
			_tmp20_ = gst_discoverer_container_info_get_tags (G_TYPE_CHECK_INSTANCE_CAST (_tmp19_, gst_discoverer_container_info_get_type (), GstDiscovererContainerInfo));
			_tmp21_ = _gst_tag_list_ref0 (_tmp20_);
			_gst_tag_list_unref0 (tags);
			tags = _tmp21_;
		} else {
			GstDiscovererStreamInfo* _tmp22_;
			_tmp22_ = stream_info;
			if (G_TYPE_CHECK_INSTANCE_TYPE (_tmp22_, gst_discoverer_stream_info_get_type ())) {
				GstDiscovererStreamInfo* _tmp23_;
				GstTagList* _tmp24_;
				GstTagList* _tmp25_;
				_tmp23_ = stream_info;
				_tmp24_ = gst_discoverer_stream_info_get_tags (G_TYPE_CHECK_INSTANCE_CAST (_tmp23_, gst_discoverer_stream_info_get_type (), GstDiscovererStreamInfo));
				_tmp25_ = _gst_tag_list_ref0 (_tmp24_);
				_gst_tag_list_unref0 (tags);
				tags = _tmp25_;
			}
		}
		_tmp27_ = tags;
		if (_tmp27_ != NULL) {
			GstTagList* _tmp28_;
			GstDateTime* _tmp29_ = NULL;
			gboolean _tmp30_;
			_tmp28_ = tags;
			_tmp30_ = gst_tag_list_get_date_time (_tmp28_, GST_TAG_DATE_TIME, &_tmp29_);
			_gst_date_time_unref0 (video_date);
			video_date = _tmp29_;
			_tmp26_ = _tmp30_;
		} else {
			_tmp26_ = FALSE;
		}
		if (_tmp26_) {
			GstDateTime* _tmp31_;
			_tmp31_ = video_date;
			if (_tmp31_ != NULL) {
				GstDateTime* _tmp32_;
				GDateTime* _tmp33_;
				GDateTime* _tmp34_;
				GDateTime* _tmp35_;
				_tmp32_ = video_date;
				_tmp33_ = gst_date_time_to_g_date_time (_tmp32_);
				_tmp34_ = _tmp33_;
				_tmp35_ = g_date_time_to_local (_tmp34_);
				_g_date_time_unref0 (timestamp);
				timestamp = _tmp35_;
				_g_date_time_unref0 (_tmp34_);
			}
		}
		g_print ("%.3f\n", clip_duration);
		_tmp36_ = timestamp;
		if (_tmp36_ != NULL) {
			GDateTime* _tmp37_;
			gchar* _tmp38_;
			gchar* _tmp39_;
			_tmp37_ = timestamp;
			_tmp38_ = g_date_time_format_iso8601 (_tmp37_);
			_tmp39_ = _tmp38_;
			g_print ("%s\n", _tmp39_);
			_g_free0 (_tmp39_);
		} else {
			g_print ("none\n");
		}
		_g_object_unref0 (stream_info);
		_gst_tag_list_unref0 (tags);
		_gst_date_time_unref0 (video_date);
		_g_object_unref0 (info);
		_g_object_unref0 (d);
		_g_object_unref0 (f);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp40_;
		const gchar* _tmp41_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp40_ = _error_;
		_tmp41_ = _tmp40_->message;
		g_critical ("VideoMetadataReaderProcess.vala:60: Failed to parse options: %s", _tmp41_);
		result = 1;
		_g_error_free0 (_error_);
		_g_date_time_unref0 (timestamp);
		_g_option_context_free0 (option_context);
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp42_ = -1;
		_g_date_time_unref0 (timestamp);
		_g_option_context_free0 (option_context);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp42_;
	}
	result = 0;
	_g_date_time_unref0 (timestamp);
	_g_option_context_free0 (option_context);
	return result;
}

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

