From 8b48e81db1bd19dd1a10932d4e402f4d840e72e6 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Sun, 24 Jul 2005 17:08:19 +0000 Subject: [PATCH] Pull date added from iTunes xml file -- thanks to Mark Woehrer --- CREDITS | 2 ++ src/scan-xml.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/CREDITS b/CREDITS index b2baf60f..c14bbd95 100644 --- a/CREDITS +++ b/CREDITS @@ -86,5 +86,7 @@ North Overby Joe Holt * Fixes for web config stupidness +Mark Woehrer + * Patches for "Date Added" in iTunes xml scanner diff --git a/src/scan-xml.c b/src/scan-xml.c index 0c27fdbb..b10052c8 100644 --- a/src/scan-xml.c +++ b/src/scan-xml.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "db-generic.h" #include "err.h" @@ -76,6 +77,7 @@ static char *scan_xml_track_tags[] = { "Disc Count", "Compilation", "Location", + "Date Added", NULL }; @@ -98,6 +100,7 @@ static char *scan_xml_track_tags[] = { #define SCAN_XML_T_DISCCOUNT 14 #define SCAN_XML_T_COMPILATION 15 #define SCAN_XML_T_LOCATION 16 +#define SCAN_XML_T_DATE_ADDED 17 #ifndef TRUE @@ -110,6 +113,22 @@ typedef struct scan_xml_rb_t { int mtd_index; } SCAN_XML_RB; + +/** + * translate an ISO 8601 iTunes xml to unix epoch format + * + * @param string iSO8601 format string to translate + * @returns time in unix epoch format + */ +int scan_xml_datedecode(char *string) { + struct tm date_time; + time_t seconds; + + strptime(string,"%Y-%m-%dT%H:%M:%SZ",&date_time); + seconds = timegm(&date_time); + return seconds; +} + /** * comparison for the red-black tree. @see redblack.c * @@ -636,6 +655,7 @@ int scan_xml_tracks_section(int action, char *info) { MAYBECOPY(rating); MAYBECOPY(disc); MAYBECOPY(total_discs); + MAYBECOPY(time_added); /* must add to the red-black tree */ scan_xml_add_lookup(current_track_id,pmp3->id); @@ -686,6 +706,8 @@ int scan_xml_tracks_section(int action, char *info) { mp3.total_discs = atoi(info); } else if(current_field == SCAN_XML_T_LOCATION) { song_path = scan_xml_urldecode(info,0); + } else if(current_field == SCAN_XML_T_DATE_ADDED) { + mp3.time_added = scan_xml_datedecode(info); } } else if(action == RXML_EVT_END) { state = XML_TRACK_ST_TRACK_INFO;