Mercurial > audlegacy
comparison audacious/playlist.c @ 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 | 57676c0f2f33 |
comparison
equal
deleted
inserted
replaced
1587:c073fd82ded6 | 1588:15d92c51bde6 |
---|---|
98 static gint path_compare(const gchar * a, const gchar * b); | 98 static gint path_compare(const gchar * a, const gchar * b); |
99 static gint playlist_compare_path(PlaylistEntry * a, PlaylistEntry * b); | 99 static gint playlist_compare_path(PlaylistEntry * a, PlaylistEntry * b); |
100 static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b); | 100 static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b); |
101 static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b); | 101 static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b); |
102 static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b); | 102 static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b); |
103 static time_t playlist_get_mtime(const gchar *filename); | |
103 static gint playlist_compare_date(PlaylistEntry * a, PlaylistEntry * b); | 104 static gint playlist_compare_date(PlaylistEntry * a, PlaylistEntry * b); |
104 static gint playlist_compare_track(PlaylistEntry * a, PlaylistEntry * b); | 105 static gint playlist_compare_track(PlaylistEntry * a, PlaylistEntry * b); |
105 static gint playlist_compare_playlist(PlaylistEntry * a, PlaylistEntry * b); | 106 static gint playlist_compare_playlist(PlaylistEntry * a, PlaylistEntry * b); |
106 | 107 |
107 static gint playlist_dupscmp_path(PlaylistEntry * a, PlaylistEntry * b); | 108 static gint playlist_dupscmp_path(PlaylistEntry * a, PlaylistEntry * b); |
149 playlist_entry_free(PlaylistEntry * entry) | 150 playlist_entry_free(PlaylistEntry * entry) |
150 { | 151 { |
151 if (!entry) | 152 if (!entry) |
152 return; | 153 return; |
153 | 154 |
154 if (entry->tuple != NULL) | 155 if (entry->tuple != NULL) { |
155 bmp_title_input_free(entry->tuple); | 156 bmp_title_input_free(entry->tuple); |
157 entry->tuple = NULL; | |
158 } | |
156 | 159 |
157 if (entry->filename != NULL) | 160 if (entry->filename != NULL) |
158 g_free(entry->filename); | 161 g_free(entry->filename); |
159 | 162 |
160 if (entry->title != NULL) | 163 if (entry->title != NULL) |
165 | 168 |
166 static gboolean | 169 static gboolean |
167 playlist_entry_get_info(PlaylistEntry * entry) | 170 playlist_entry_get_info(PlaylistEntry * entry) |
168 { | 171 { |
169 TitleInput *tuple; | 172 TitleInput *tuple; |
173 time_t modtime = playlist_get_mtime(entry->filename); | |
170 | 174 |
171 g_return_val_if_fail(entry != NULL, FALSE); | 175 g_return_val_if_fail(entry != NULL, FALSE); |
176 | |
177 /* renew tuple if file mtime is newer than tuple mtime. */ | |
178 if(entry->tuple){ | |
179 if(entry->tuple->mtime == modtime) | |
180 return TRUE; | |
181 else { | |
182 bmp_title_input_free(entry->tuple); | |
183 entry->tuple = NULL; | |
184 } | |
185 } | |
172 | 186 |
173 if (entry->decoder == NULL) | 187 if (entry->decoder == NULL) |
174 entry->decoder = input_check_file(entry->filename, FALSE); | 188 entry->decoder = input_check_file(entry->filename, FALSE); |
175 | 189 |
176 if (entry->decoder == NULL || entry->decoder->get_song_tuple == NULL) | 190 if (entry->decoder == NULL || entry->decoder->get_song_tuple == NULL) |
178 else | 192 else |
179 tuple = entry->decoder->get_song_tuple(entry->filename); | 193 tuple = entry->decoder->get_song_tuple(entry->filename); |
180 | 194 |
181 if (tuple == NULL) | 195 if (tuple == NULL) |
182 return FALSE; | 196 return FALSE; |
197 | |
198 /* attach mtime */ | |
199 tuple->mtime = modtime; | |
183 | 200 |
184 /* entry is still around */ | 201 /* entry is still around */ |
185 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple); | 202 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple); |
186 entry->length = tuple->length; | 203 entry->length = tuple->length; |
187 entry->tuple = tuple; | 204 entry->tuple = tuple; |
483 pos = g_list_length(playlist) - 1; /* last element. */ | 500 pos = g_list_length(playlist) - 1; /* last element. */ |
484 } | 501 } |
485 | 502 |
486 node = g_list_nth(playlist, pos); | 503 node = g_list_nth(playlist, pos); |
487 entry = PLAYLIST_ENTRY(node->data); | 504 entry = PLAYLIST_ENTRY(node->data); |
488 | |
489 /* insufficient tuple */ | |
490 if(!tuple->track_name || !tuple->performer || !tuple->album_name || !tuple->genre | |
491 || !tuple->year || !tuple->track_number || !tuple->length){ | |
492 // printf("tuple discarded: %s\n", filename); | |
493 bmp_title_input_free(tuple); | |
494 | |
495 if (entry->decoder == NULL || entry->decoder->get_song_tuple == NULL) | |
496 tuple = input_get_song_tuple(entry->filename); | |
497 else | |
498 tuple = entry->decoder->get_song_tuple(entry->filename); | |
499 } | |
500 | 505 |
501 if (tuple != NULL) { | 506 if (tuple != NULL) { |
502 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple); | 507 entry->title = xmms_get_titlestring(tuple->formatter != NULL ? tuple->formatter : xmms_get_gentitle_format(), tuple); |
503 entry->length = tuple->length; | 508 entry->length = tuple->length; |
504 entry->tuple = tuple; | 509 entry->tuple = tuple; |
1536 } | 1541 } |
1537 | 1542 |
1538 entry = node->data; | 1543 entry = node->data; |
1539 | 1544 |
1540 /* FIXME: simplify this logic */ | 1545 /* FIXME: simplify this logic */ |
1541 if (!entry->title && entry->length == -1) { | 1546 // if (!entry->title && entry->length == -1) { |
1547 if ( (!entry->title && entry->length == -1) || | |
1548 (entry->tuple && (entry->tuple->mtime != playlist_get_mtime(entry->filename))) ){ | |
1542 if (playlist_entry_get_info(entry)) | 1549 if (playlist_entry_get_info(entry)) |
1543 title = entry->title; | 1550 title = entry->title; |
1544 } | 1551 } |
1545 else { | 1552 else { |
1546 title = entry->title; | 1553 title = entry->title; |
1577 | 1584 |
1578 entry = (PlaylistEntry *) node->data; | 1585 entry = (PlaylistEntry *) node->data; |
1579 | 1586 |
1580 tuple = entry->tuple; | 1587 tuple = entry->tuple; |
1581 | 1588 |
1582 if (tuple == NULL) | 1589 // if no tuple or tuple with old mtime, get new one. |
1583 { | 1590 if (!tuple || (entry->tuple->mtime != playlist_get_mtime(entry->filename))) { |
1584 playlist_entry_get_info(entry); | 1591 playlist_entry_get_info(entry); |
1585 tuple = entry->tuple; | 1592 tuple = entry->tuple; |
1586 } | 1593 } |
1587 | 1594 |
1588 PLAYLIST_UNLOCK(); | 1595 PLAYLIST_UNLOCK(); |
1609 return -1; | 1616 return -1; |
1610 } | 1617 } |
1611 | 1618 |
1612 entry = node->data; | 1619 entry = node->data; |
1613 | 1620 |
1614 if (!entry->title && entry->length == -1) { | 1621 // if (!entry->title && entry->length == -1) { |
1622 if (!entry->tuple || (entry->tuple->mtime != playlist_get_mtime(entry->filename))){ | |
1623 | |
1615 if (playlist_entry_get_info(entry)) | 1624 if (playlist_entry_get_info(entry)) |
1616 song_time = entry->length; | 1625 song_time = entry->length; |
1617 | 1626 |
1618 PLAYLIST_UNLOCK(); | 1627 PLAYLIST_UNLOCK(); |
1619 } | 1628 } |
1786 playlist_compare_path(PlaylistEntry * a, | 1795 playlist_compare_path(PlaylistEntry * a, |
1787 PlaylistEntry * b) | 1796 PlaylistEntry * b) |
1788 { | 1797 { |
1789 return path_compare(a->filename, b->filename); | 1798 return path_compare(a->filename, b->filename); |
1790 } | 1799 } |
1800 | |
1801 | |
1802 static time_t | |
1803 playlist_get_mtime(const gchar *filename) | |
1804 { | |
1805 struct stat buf; | |
1806 | |
1807 gint rv; | |
1808 | |
1809 rv = stat(filename, &buf); | |
1810 | |
1811 if (rv == 0) { | |
1812 return buf.st_mtime; | |
1813 } else { | |
1814 return 0; //error | |
1815 } | |
1816 } | |
1817 | |
1791 | 1818 |
1792 static gint | 1819 static gint |
1793 playlist_compare_date(PlaylistEntry * a, | 1820 playlist_compare_date(PlaylistEntry * a, |
1794 PlaylistEntry * b) | 1821 PlaylistEntry * b) |
1795 { | 1822 { |
2048 } | 2075 } |
2049 | 2076 |
2050 PLAYLIST_UNLOCK(); | 2077 PLAYLIST_UNLOCK(); |
2051 | 2078 |
2052 /* No tuple? Try to set this entry up properly. --nenolod */ | 2079 /* No tuple? Try to set this entry up properly. --nenolod */ |
2053 if (entry->tuple == NULL) | 2080 // if (entry->tuple == NULL) |
2081 if (!entry->tuple || (entry->tuple->mtime != playlist_get_mtime(entry->filename))) | |
2054 { | 2082 { |
2055 playlist_entry_get_info(entry); | 2083 playlist_entry_get_info(entry); |
2056 tuple = entry->tuple; | 2084 tuple = entry->tuple; |
2057 } | 2085 } |
2058 | 2086 |
2143 | 2171 |
2144 PLAYLIST_LOCK(); | 2172 PLAYLIST_LOCK(); |
2145 for (node = playlist_get(); node; node = g_list_next(node)) { | 2173 for (node = playlist_get(); node; node = g_list_next(node)) { |
2146 entry = node->data; | 2174 entry = node->data; |
2147 | 2175 |
2148 if (entry->title || entry->length != -1) | 2176 if(entry->tuple) { |
2149 continue; | 2177 // printf("tuple mtime = %ld file mtime = %ld\n", entry->tuple->mtime, playlist_get_mtime(entry->filename)); |
2178 if(entry->tuple->mtime == playlist_get_mtime(entry->filename)) | |
2179 continue; | |
2180 else | |
2181 entry->tuple->mtime = 0; /* invalidate mtime */ | |
2182 } | |
2150 | 2183 |
2151 if (!playlist_entry_get_info(entry)) { | 2184 if (!playlist_entry_get_info(entry)) { |
2152 if (g_list_index(playlist_get(), entry) == -1) | 2185 if (g_list_index(playlist_get(), entry) == -1) |
2153 /* Entry disappeared while we looked it up. | 2186 /* Entry disappeared while we looked it up. |
2154 Restart. */ | 2187 Restart. */ |
2188 && | 2221 && |
2189 playlistwin_item_visible(g_list_position | 2222 playlistwin_item_visible(g_list_position |
2190 (playlist_get(), node)); | 2223 (playlist_get(), node)); |
2191 node = g_list_next(node)) { | 2224 node = g_list_next(node)) { |
2192 entry = node->data; | 2225 entry = node->data; |
2193 if (entry->title || entry->length != -1) | 2226 // if (entry->title || entry->length != -1) |
2227 if (entry->tuple && (entry->tuple->mtime == playlist_get_mtime(entry->filename))) | |
2194 continue; | 2228 continue; |
2195 | 2229 |
2196 if (!playlist_entry_get_info(entry)) { | 2230 if (!playlist_entry_get_info(entry)) { |
2197 if (g_list_index(playlist_get(), entry) == -1) | 2231 if (g_list_index(playlist_get(), entry) == -1) |
2198 /* Entry disapeared while we | 2232 /* Entry disapeared while we |
2587 retval = TRUE; | 2621 retval = TRUE; |
2588 | 2622 |
2589 str_replace_in(&entry->title, NULL); | 2623 str_replace_in(&entry->title, NULL); |
2590 entry->length = -1; | 2624 entry->length = -1; |
2591 | 2625 |
2626 /* invalidate mtime to reread */ | |
2627 entry->tuple->mtime = 0; | |
2628 | |
2592 if (!playlist_entry_get_info(entry)) { | 2629 if (!playlist_entry_get_info(entry)) { |
2593 if (g_list_index(playlist_get(), entry) == -1) | 2630 if (g_list_index(playlist_get(), entry) == -1) |
2594 /* Entry disappeared while we looked it up. Restart. */ | 2631 /* Entry disappeared while we looked it up. Restart. */ |
2595 node = playlist_get(); | 2632 node = playlist_get(); |
2596 } | 2633 } |