diff options
author | Jens Georg <mail@jensge.org> | 2012-02-21 11:36:38 +0200 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2012-02-21 15:41:44 +0200 |
commit | c39162c62cd28d75cf07f88e6e7314383cc62730 (patch) | |
tree | 34fb46181868808db06d16b7cfc5cffedc4024ff | |
parent | c0d4190f393d58669e8acc61c73ad834c2784920 (diff) | |
download | rygel-c39162c62cd28d75cf07f88e6e7314383cc62730.tar.gz |
core: Use date from DIDL in CreateObject
-rw-r--r-- | src/rygel/rygel-item-creator.vala | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/rygel/rygel-item-creator.vala b/src/rygel/rygel-item-creator.vala index facd73a9..4caec904 100644 --- a/src/rygel/rygel-item-creator.vala +++ b/src/rygel/rygel-item-creator.vala @@ -391,6 +391,43 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine { } this.item.id = this.item.uris[0]; + + this.parse_and_verify_didl_date (); + } + + private void parse_and_verify_didl_date () throws Error { + if (this.didl_item.date == null) { + return; + } + + var parsed_date = new Soup.Date.from_string (this.didl_item.date); + if (parsed_date != null) { + this.item.date = parsed_date.to_string (Soup.DateFormat.ISO8601); + + return; + } + + int year = 0, month = 0, day = 0; + + if (this.didl_item.date.scanf ("%4d-%02d-%02d", + out year, + out month, + out day) != 3) { + throw new ContentDirectoryError.BAD_METADATA + ("Invalid date format: %s", + this.didl_item.date); + } + + var date = GLib.Date (); + date.set_dmy ((DateDay) day, (DateMonth) month, (DateYear) year); + + if (!date.valid ()) { + throw new ContentDirectoryError.BAD_METADATA + ("Invalid date: %s", + this.didl_item.date); + } + + this.item.date = this.didl_item.date + "T00:00:00"; } private MediaItem create_item (string id, |