2 * Copyright 2004-2005 Timo Hirvonen
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 #include <track_info.h>
29 static void track_info_free(struct track_info
*ti
)
31 comments_free(ti
->comments
);
35 struct track_info
*track_info_new(const char *filename
)
37 struct track_info
*ti
;
38 int size
= strlen(filename
) + 1;
40 ti
= xmalloc(sizeof(struct track_info
) + size
);
41 memcpy(ti
->filename
, filename
, size
);
46 void track_info_ref(struct track_info
*ti
)
52 void track_info_unref(struct track_info
*ti
)
60 int track_info_has_tag(const struct track_info
*ti
)
62 return comments_get_val(ti
->comments
, "artist") ||
63 comments_get_val(ti
->comments
, "album") ||
64 comments_get_val(ti
->comments
, "title");
67 int track_info_matches(struct track_info
*ti
, const char *text
, unsigned int flags
)
69 const char *artist
= comments_get_val(ti
->comments
, "artist");
70 const char *album
= comments_get_val(ti
->comments
, "album");
71 const char *title
= comments_get_val(ti
->comments
, "title");
75 words
= get_words(text
);
78 for (i
= 0; words
[i
]; i
++) {
79 const char *word
= words
[i
];
81 if ((flags
& TI_MATCH_ARTIST
&& artist
) ||
82 (flags
& TI_MATCH_ALBUM
&& album
) ||
83 (flags
& TI_MATCH_TITLE
&& title
)) {
84 if (flags
& TI_MATCH_ARTIST
&& artist
&& u_strcasestr(artist
, word
))
86 if (flags
& TI_MATCH_ALBUM
&& album
&& u_strcasestr(album
, word
))
88 if (flags
& TI_MATCH_TITLE
&& title
&& u_strcasestr(title
, word
))
91 /* compare with filename (without path) */
92 char *filename
= strrchr(ti
->filename
, '/');
94 if (filename
== NULL
) {
95 filename
= ti
->filename
;
99 if (u_strcasestr_filename(filename
, word
))
105 free_str_array(words
);