[tracker-miners/wip/carlosg/album-dates: 918/918] tracker-extract-gstreamer: Make date/time detection smarter
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/album-dates: 918/918] tracker-extract-gstreamer: Make date/time detection smarter
- Date: Sun, 21 Jun 2020 11:14:37 +0000 (UTC)
commit 5384635182ed8188c22cda15757287afefb95cac
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Aug 5 15:00:48 2018 +0200
tracker-extract-gstreamer: Make date/time detection smarter
There's files that may have both GST_TAG_DATE_TIME and GST_TAG_DATE,
in some cases both will be "the same" and the former will be just
a more exact representation.
However for other cases (notably albums ripped in m4a), it is more
likely that the album release date is contained in GST_TAG_DATE,
while the other tag is more likely to contain the ripping time, or
something equally random.
For those cases where both dates are present but different, actually
prefer GST_TAG_DATE even though it's "less exact" in terms of
resolution. This also is more in line with how totem and rhythmbox
handle these fields.
https://gitlab.gnome.org/GNOME/tracker-miners/issues/16
Closes: #16
src/tracker-extract/tracker-extract-gstreamer.c | 59 ++++++++++++++++++-------
1 file changed, 44 insertions(+), 15 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-gstreamer.c b/src/tracker-extract/tracker-extract-gstreamer.c
index 007940469..e52b983d0 100644
--- a/src/tracker-extract/tracker-extract-gstreamer.c
+++ b/src/tracker-extract/tracker-extract-gstreamer.c
@@ -226,31 +226,56 @@ extract_gst_date_time (gchar *buf,
{
GstDateTime *date_time = NULL;
GDate *date = NULL;
- gboolean ret = FALSE;
+ gboolean ret = FALSE, use_datetime = FALSE, use_date = FALSE;
buf[0] = '\0';
- if (gst_tag_list_get_date_time (tag_list, tag_date_time, &date_time)) {
- gboolean complete;
+ /* See https://gitlab.gnome.org/GNOME/tracker-miners/-/issues/16 for why
+ * this code looks at both GST_TAG_DATE_TIME and GST_TAG_DATE
+ */
+ gst_tag_list_get_date_time (tag_list, tag_date_time, &date_time);
+ gst_tag_list_get_date (tag_list, tag_date, &date);
+
+ if (date_time && date) {
+ if (!gst_date_time_has_year (date_time) ||
+ !gst_date_time_has_month (date_time) ||
+ !gst_date_time_has_day (date_time)) {
+ use_date = TRUE;
+ } else if (gst_date_time_get_year (date_time) == g_date_get_year (date) &&
+ gst_date_time_get_month (date_time) == g_date_get_month (date) &&
+ gst_date_time_get_day (date_time) == g_date_get_day (date)) {
+ /* Dates are equal, prefer datetime as it has more precission */
+ use_datetime = TRUE;
+ } else {
+ /* Dates are dissimilar, prefer date alone as it's
+ * traditionally preferred for "release" dates
+ */
+ use_date = TRUE;
+ }
+ } else if (date_time) {
+ use_datetime = TRUE;
+ } else {
+ use_date = TRUE;
+ }
- ret = gst_date_time_has_year (date_time);
- complete = get_gst_date_time_to_buf (date_time, buf, size);
- gst_date_time_unref (date_time);
+ if (date_time && use_datetime) {
+ ret = get_gst_date_time_to_buf (date_time, buf, size);
- if (!complete) {
+ if (!ret) {
g_debug ("GstDateTime was not complete, parts of the date/time were missing (e.g.
hours, minutes, seconds)");
+ use_date = TRUE;
+
+ /* Return success even if the DATE tag is empty, as we have at
+ * least some information from the DATE_TIME tag. */
+ ret = TRUE;
}
- } else if (gst_tag_list_get_date (tag_list, tag_date, &date)) {
- if (date && g_date_valid (date)) {
- if (date->julian)
- ret = g_date_valid_julian (date->julian_days);
- if (date->dmy)
- ret = g_date_valid_dmy (date->day, date->month, date->year);
- }
+ }
- if (ret) {
+ if (date && use_date) {
+ if (g_date_valid (date)) {
/* GDate does not carry time zone information, assume UTC */
g_date_strftime (buf, size, "%Y-%m-%dT%H:%M:%SZ", date);
+ ret = TRUE;
}
}
@@ -258,6 +283,10 @@ extract_gst_date_time (gchar *buf,
g_date_free (date);
}
+ if (date_time) {
+ gst_date_time_unref (date_time);
+ }
+
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]