changeset 1588:15d92c51bde6 trunk

[svn] - modified time (mtime) has been introduced into tuple - playlist makes use of mtime for scan control - xspf records and reads mtime
author yaz
date Wed, 23 Aug 2006 07:46:33 -0700
parents c073fd82ded6
children ebc170f08767
files ChangeLog Plugins/Container/xspf/xspf.c audacious/input.c audacious/playlist.c audacious/titlestring.h audacious/ui_fileinfo.c libaudacious/titlestring.h
diffstat 7 files changed, 94 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Aug 20 12:20:36 2006 -0700
+++ b/ChangeLog	Wed Aug 23 07:46:33 2006 -0700
@@ -1,3 +1,12 @@
+2006-08-20 19:20:36 +0000  George Averill <nhjm449@gmail.com>
+  revision [2097]
+  - Don't explode when loading http streams from xspf files.
+  
+
+  Changes:        Modified:
+  +5 -3           trunk/audacious/playlist.c  
+
+
 2006-08-20 03:53:12 +0000  William Pitcock <nenolod@nenolod.net>
   revision [2095]
   - use bmp_title_input_new(), as XMMS_NEW_TITLEINPUT() is a deprecated and unsafe API
--- a/Plugins/Container/xspf/xspf.c	Sun Aug 20 12:20:36 2006 -0700
+++ b/Plugins/Container/xspf/xspf.c	Wed Aug 23 07:46:33 2006 -0700
@@ -127,6 +127,14 @@
 				tuple->formatter = (gchar *)xmlNodeGetContent(nptr);
 				continue;
 			}
+			else if(!strcmp(rel, "mtime")){
+				xmlChar *str;
+				str = xmlNodeGetContent(nptr);
+				tuple->mtime = (time_t)atoll(str);
+				if(str)
+					xmlFree(str);
+				continue;
+			}
 			xmlFree(rel);
 			rel = NULL;
 		}
@@ -348,6 +356,17 @@
 				xmlAddChild(track, tmp);
 			}
 
+			if (entry->tuple->mtime) {
+				gchar *str;
+				str = g_malloc(128); // XXX fix me.
+				tmp = xmlNewNode(NULL, "meta");
+				xmlSetProp(tmp, "rel", "mtime");
+				sprintf(str, "%ld", entry->tuple->mtime);
+				xmlAddChild(tmp, xmlNewText(str));
+				xmlAddChild(track, tmp);
+				g_free(str);
+			}				
+
 		}
 		if(utf_filename) {
 			g_free(utf_filename);
--- a/audacious/input.c	Sun Aug 20 12:20:36 2006 -0700
+++ b/audacious/input.c	Wed Aug 23 07:46:33 2006 -0700
@@ -488,6 +488,7 @@
         (*length) = -1;
 
         bmp_title_input_free(input);
+        input = NULL;
     }
 
     g_free(filename_proxy);
--- a/audacious/playlist.c	Sun Aug 20 12:20:36 2006 -0700
+++ b/audacious/playlist.c	Wed Aug 23 07:46:33 2006 -0700
@@ -100,6 +100,7 @@
 static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b);
 static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b);
 static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b);
+static time_t playlist_get_mtime(const gchar *filename);
 static gint playlist_compare_date(PlaylistEntry * a, PlaylistEntry * b);
 static gint playlist_compare_track(PlaylistEntry * a, PlaylistEntry * b);
 static gint playlist_compare_playlist(PlaylistEntry * a, PlaylistEntry * b);
@@ -151,8 +152,10 @@
     if (!entry)
         return;
 
-    if (entry->tuple != NULL)
+    if (entry->tuple != NULL) {
         bmp_title_input_free(entry->tuple);
+        entry->tuple = NULL;
+    }
 
     if (entry->filename != NULL)
         g_free(entry->filename);
@@ -167,9 +170,20 @@
 playlist_entry_get_info(PlaylistEntry * entry)
 {
     TitleInput *tuple;
+    time_t modtime = playlist_get_mtime(entry->filename);
 
     g_return_val_if_fail(entry != NULL, FALSE);
 
+    /* renew tuple if file mtime is newer than tuple mtime. */
+    if(entry->tuple){
+        if(entry->tuple->mtime == modtime)
+            return TRUE;
+        else {
+            bmp_title_input_free(entry->tuple);
+            entry->tuple = NULL;
+        }
+    }
+
     if (entry->decoder == NULL)
         entry->decoder = input_check_file(entry->filename, FALSE);
 
@@ -181,6 +195,9 @@
     if (tuple == NULL)
         return FALSE;
 
+    /* attach mtime */
+    tuple->mtime = modtime;
+
     /* entry is still around */
     entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple);
     entry->length = tuple->length;
@@ -486,18 +503,6 @@
     node = g_list_nth(playlist, pos);
     entry = PLAYLIST_ENTRY(node->data);
 
-    /* insufficient tuple */
-    if(!tuple->track_name || !tuple->performer || !tuple->album_name || !tuple->genre
-       || !tuple->year || !tuple->track_number || !tuple->length){
-//	    printf("tuple discarded: %s\n", filename);
-	    bmp_title_input_free(tuple);
-
-	    if (entry->decoder == NULL || entry->decoder->get_song_tuple == NULL)
-		    tuple = input_get_song_tuple(entry->filename);
-	    else
-		    tuple = entry->decoder->get_song_tuple(entry->filename);
-    }
-
     if (tuple != NULL) {
         entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple);
         entry->length = tuple->length;
@@ -1538,7 +1543,9 @@
     entry = node->data;
 
     /* FIXME: simplify this logic */
-    if (!entry->title && entry->length == -1) {
+//    if (!entry->title && entry->length == -1) {
+    if ( (!entry->title && entry->length == -1) || 
+	 (entry->tuple && (entry->tuple->mtime != playlist_get_mtime(entry->filename))) ){
         if (playlist_entry_get_info(entry))
             title = entry->title;
     }
@@ -1579,8 +1586,8 @@
 
     tuple = entry->tuple;
 
-    if (tuple == NULL)
-    {
+    // if no tuple or tuple with old mtime, get new one.
+    if (!tuple || (entry->tuple->mtime != playlist_get_mtime(entry->filename))) {
         playlist_entry_get_info(entry);
         tuple = entry->tuple;
     }
@@ -1611,7 +1618,9 @@
 
     entry = node->data;
 
-    if (!entry->title && entry->length == -1) {
+//    if (!entry->title && entry->length == -1) {
+    if (!entry->tuple || (entry->tuple->mtime != playlist_get_mtime(entry->filename))){
+
         if (playlist_entry_get_info(entry))
             song_time = entry->length;
 
@@ -1789,6 +1798,24 @@
     return path_compare(a->filename, b->filename);
 }
 
+
+static time_t
+playlist_get_mtime(const gchar *filename)
+{
+	struct stat buf;
+
+    gint rv;
+
+    rv = stat(filename, &buf);
+
+    if (rv == 0) {
+        return buf.st_mtime;
+    } else {
+        return 0; //error
+    }
+}
+
+
 static gint
 playlist_compare_date(PlaylistEntry * a,
                       PlaylistEntry * b)
@@ -2050,7 +2077,8 @@
     PLAYLIST_UNLOCK();
 
     /* No tuple? Try to set this entry up properly. --nenolod */
-    if (entry->tuple == NULL)
+//    if (entry->tuple == NULL)
+    if (!entry->tuple || (entry->tuple->mtime != playlist_get_mtime(entry->filename)))
     {
         playlist_entry_get_info(entry);
         tuple = entry->tuple;
@@ -2145,8 +2173,13 @@
             for (node = playlist_get(); node; node = g_list_next(node)) {
                 entry = node->data;
 
-                if (entry->title || entry->length != -1)
-                    continue;
+                if(entry->tuple) {
+//                    printf("tuple mtime = %ld file mtime = %ld\n", entry->tuple->mtime, playlist_get_mtime(entry->filename));
+                    if(entry->tuple->mtime == playlist_get_mtime(entry->filename)) 
+                        continue;
+                    else
+                        entry->tuple->mtime = 0; /* invalidate mtime */
+                }
 
                 if (!playlist_entry_get_info(entry)) {
                     if (g_list_index(playlist_get(), entry) == -1)
@@ -2190,7 +2223,8 @@
                                           (playlist_get(), node));
                  node = g_list_next(node)) {
                 entry = node->data;
-                if (entry->title || entry->length != -1)
+//                if (entry->title || entry->length != -1)
+                if (entry->tuple && (entry->tuple->mtime == playlist_get_mtime(entry->filename)))
                     continue;
 
                 if (!playlist_entry_get_info(entry)) {
@@ -2589,6 +2623,9 @@
         str_replace_in(&entry->title, NULL);
         entry->length = -1;
 
+	/* invalidate mtime to reread */
+	entry->tuple->mtime = 0;
+
         if (!playlist_entry_get_info(entry)) {
             if (g_list_index(playlist_get(), entry) == -1)
                 /* Entry disappeared while we looked it up. Restart. */
--- a/audacious/titlestring.h	Sun Aug 20 12:20:36 2006 -0700
+++ b/audacious/titlestring.h	Wed Aug 23 07:46:33 2006 -0700
@@ -32,7 +32,7 @@
  */
 
 typedef struct {
-    gint __size;                /* Set by XMMS_NEW_TITLEINPUT() */
+    gint __size;                /* Set by bmp_title_input_new() */
     gint __version;             /* Ditto */
 
     gchar *performer;           /* %p */
@@ -46,8 +46,9 @@
     gchar *file_name;           /* %f */
     const gchar *file_ext;      /* %e *//* is not always strdup'ed, see xmms_input_get_song_info and plugins! */
     gchar *file_path;           /* %F */
-    gint length;		/* not displayable */
-    gchar *formatter;		/* not displayable */
+    gint length;                /* not displayable */
+    gchar *formatter;           /* not displayable */
+    time_t mtime;               /* time of modified */
 } TitleInput;
 
 typedef TitleInput BmpTitleInput;
--- a/audacious/ui_fileinfo.c	Sun Aug 20 12:20:36 2006 -0700
+++ b/audacious/ui_fileinfo.c	Wed Aug 23 07:46:33 2006 -0700
@@ -500,4 +500,5 @@
 	fileinfo_show_for_tuple(tuple);
 
 	bmp_title_input_free(tuple);
+	tuple = NULL;
 }
--- a/libaudacious/titlestring.h	Sun Aug 20 12:20:36 2006 -0700
+++ b/libaudacious/titlestring.h	Wed Aug 23 07:46:33 2006 -0700
@@ -32,7 +32,7 @@
  */
 
 typedef struct {
-    gint __size;                /* Set by XMMS_NEW_TITLEINPUT() */
+    gint __size;                /* Set by bmp_title_input_new() */
     gint __version;             /* Ditto */
 
     gchar *performer;           /* %p */
@@ -48,6 +48,7 @@
     gchar *file_path;           /* %F */
     gint length;		/* not displayable */
     gchar *formatter;		/* not displayable */
+    time_t mtime;
 } TitleInput;
 
 typedef TitleInput BmpTitleInput;