diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/recorder/albumart.c | 156 |
1 files changed, 86 insertions, 70 deletions
diff --git a/apps/recorder/albumart.c b/apps/recorder/albumart.c index e33fcb8d08..381e61d2c9 100644 --- a/apps/recorder/albumart.c +++ b/apps/recorder/albumart.c | |||
@@ -133,7 +133,7 @@ static bool try_exts(char *path, int len) | |||
133 | * | 133 | * |
134 | * If the first symbol in size_string is a colon (e.g. ":100x100") | 134 | * If the first symbol in size_string is a colon (e.g. ":100x100") |
135 | * then the colon is skipped ("100x100" will be used) and the track | 135 | * then the colon is skipped ("100x100" will be used) and the track |
136 | * specific image (./<trackname><size>.bmp) is not tried. | 136 | * specific image (./<trackname><size>.bmp) is tried last instead of first. |
137 | */ | 137 | */ |
138 | bool search_albumart_files(const struct mp3entry *id3, const char *size_string, | 138 | bool search_albumart_files(const struct mp3entry *id3, const char *size_string, |
139 | char *buf, int buflen) | 139 | char *buf, int buflen) |
@@ -141,6 +141,8 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string, | |||
141 | char path[MAX_PATH + 1]; | 141 | char path[MAX_PATH + 1]; |
142 | char dir[MAX_PATH + 1]; | 142 | char dir[MAX_PATH + 1]; |
143 | bool found = false; | 143 | bool found = false; |
144 | int track_first = 1; | ||
145 | int pass; | ||
144 | const char *trackname; | 146 | const char *trackname; |
145 | const char *artist; | 147 | const char *artist; |
146 | int dirlen; | 148 | int dirlen; |
@@ -155,93 +157,107 @@ bool search_albumart_files(const struct mp3entry *id3, const char *size_string, | |||
155 | if (strcmp(trackname, "No file!") == 0) | 157 | if (strcmp(trackname, "No file!") == 0) |
156 | return false; | 158 | return false; |
157 | 159 | ||
158 | strip_filename(dir, sizeof(dir), trackname); | ||
159 | dirlen = strlen(dir); | ||
160 | albumlen = id3->album ? strlen(id3->album) : 0; | ||
161 | |||
162 | /* the first file we look for is one specific to the track playing */ | ||
163 | if (*size_string == ':') | 160 | if (*size_string == ':') |
164 | size_string++; | ||
165 | else { | ||
166 | strip_extension(path, sizeof(path) - strlen(size_string) - 4, trackname); | ||
167 | strcat(path, size_string); | ||
168 | strcat(path, "." EXT); | ||
169 | #ifdef USE_JPEG_COVER | ||
170 | pathlen = strlen(path); | ||
171 | #endif | ||
172 | found = try_exts(path, pathlen); | ||
173 | } | ||
174 | if (!found && albumlen > 0) | ||
175 | { | 161 | { |
176 | /* if it doesn't exist, | 162 | size_string++; |
177 | * we look for a file specific to the track's album name */ | 163 | track_first = 0; |
178 | pathlen = snprintf(path, sizeof(path), | ||
179 | "%s%s%s." EXT, dir, id3->album, size_string); | ||
180 | fix_path_part(path, dirlen, albumlen); | ||
181 | found = try_exts(path, pathlen); | ||
182 | } | 164 | } |
183 | 165 | ||
184 | if (!found) | 166 | strip_filename(dir, sizeof(dir), trackname); |
185 | { | 167 | dirlen = strlen(dir); |
186 | /* if it still doesn't exist, we look for a generic file */ | 168 | albumlen = id3->album ? strlen(id3->album) : 0; |
187 | pathlen = snprintf(path, sizeof(path), | ||
188 | "%scover%s." EXT, dir, size_string); | ||
189 | found = try_exts(path, pathlen); | ||
190 | } | ||
191 | 169 | ||
192 | #ifdef USE_JPEG_COVER | 170 | for(pass = 0; pass < 2; pass++) |
193 | if (!found && !*size_string) | ||
194 | { | 171 | { |
195 | snprintf (path, sizeof(path), "%sfolder.jpg", dir); | 172 | if (track_first || pass) |
196 | found = file_exists(path); | 173 | { |
197 | } | 174 | /* the first file we look for is one specific to the |
175 | current track */ | ||
176 | strip_extension(path, sizeof(path) - strlen(size_string) - 4, | ||
177 | trackname); | ||
178 | strcat(path, size_string); | ||
179 | strcat(path, "." EXT); | ||
180 | #ifdef USE_JPEG_COVER | ||
181 | pathlen = strlen(path); | ||
198 | #endif | 182 | #endif |
199 | 183 | found = try_exts(path, pathlen); | |
200 | artist = id3->albumartist != NULL ? id3->albumartist : id3->artist; | 184 | } |
201 | 185 | if (pass) | |
202 | if (!found && artist && id3->album) | 186 | break; |
203 | { | ||
204 | /* look in the albumart subdir of .rockbox */ | ||
205 | pathlen = snprintf(path, sizeof(path), | ||
206 | ROCKBOX_DIR "/albumart/%s-%s%s." EXT, | ||
207 | artist, | ||
208 | id3->album, | ||
209 | size_string); | ||
210 | fix_path_part(path, strlen(ROCKBOX_DIR "/albumart/"), MAX_PATH); | ||
211 | found = try_exts(path, pathlen); | ||
212 | } | ||
213 | |||
214 | if (!found) | ||
215 | { | ||
216 | /* if it still doesn't exist, | ||
217 | * we continue to search in the parent directory */ | ||
218 | strcpy(path, dir); | ||
219 | path[dirlen - 1] = 0; | ||
220 | strip_filename(dir, sizeof(dir), path); | ||
221 | dirlen = strlen(dir); | ||
222 | } | ||
223 | |||
224 | /* only try parent if there is one */ | ||
225 | if (dirlen > 0) | ||
226 | { | ||
227 | if (!found && albumlen > 0) | 187 | if (!found && albumlen > 0) |
228 | { | 188 | { |
229 | /* we look in the parent directory | 189 | /* if it doesn't exist, |
230 | * for a file specific to the track's album name */ | 190 | * we look for a file specific to the track's album name */ |
231 | pathlen = snprintf(path, sizeof(path), | 191 | pathlen = snprintf(path, sizeof(path), |
232 | "%s%s%s." EXT, dir, id3->album, size_string); | 192 | "%s%s%s." EXT, dir, id3->album, size_string); |
233 | fix_path_part(path, dirlen, albumlen); | 193 | fix_path_part(path, dirlen, albumlen); |
234 | found = try_exts(path, pathlen); | 194 | found = try_exts(path, pathlen); |
235 | } | 195 | } |
236 | 196 | ||
237 | if (!found) | 197 | if (!found) |
238 | { | 198 | { |
239 | /* if it still doesn't exist, we look in the parent directory | 199 | /* if it still doesn't exist, we look for a generic file */ |
240 | * for a generic file */ | 200 | pathlen = snprintf(path, sizeof(path), |
201 | "%scover%s." EXT, dir, size_string); | ||
202 | found = try_exts(path, pathlen); | ||
203 | } | ||
204 | |||
205 | #ifdef USE_JPEG_COVER | ||
206 | if (!found && !*size_string) | ||
207 | { | ||
208 | snprintf (path, sizeof(path), "%sfolder.jpg", dir); | ||
209 | found = file_exists(path); | ||
210 | } | ||
211 | #endif | ||
212 | |||
213 | artist = id3->albumartist != NULL ? id3->albumartist : id3->artist; | ||
214 | |||
215 | if (!found && artist && id3->album) | ||
216 | { | ||
217 | /* look in the albumart subdir of .rockbox */ | ||
241 | pathlen = snprintf(path, sizeof(path), | 218 | pathlen = snprintf(path, sizeof(path), |
242 | "%scover%s." EXT, dir, size_string); | 219 | ROCKBOX_DIR "/albumart/%s-%s%s." EXT, |
220 | artist, | ||
221 | id3->album, | ||
222 | size_string); | ||
223 | fix_path_part(path, strlen(ROCKBOX_DIR "/albumart/"), MAX_PATH); | ||
243 | found = try_exts(path, pathlen); | 224 | found = try_exts(path, pathlen); |
244 | } | 225 | } |
226 | |||
227 | if (!found) | ||
228 | { | ||
229 | /* if it still doesn't exist, | ||
230 | * we continue to search in the parent directory */ | ||
231 | strcpy(path, dir); | ||
232 | path[dirlen - 1] = 0; | ||
233 | strip_filename(dir, sizeof(dir), path); | ||
234 | dirlen = strlen(dir); | ||
235 | } | ||
236 | |||
237 | /* only try parent if there is one */ | ||
238 | if (dirlen > 0) | ||
239 | { | ||
240 | if (!found && albumlen > 0) | ||
241 | { | ||
242 | /* we look in the parent directory | ||
243 | * for a file specific to the track's album name */ | ||
244 | pathlen = snprintf(path, sizeof(path), | ||
245 | "%s%s%s." EXT, dir, id3->album, size_string); | ||
246 | fix_path_part(path, dirlen, albumlen); | ||
247 | found = try_exts(path, pathlen); | ||
248 | } | ||
249 | |||
250 | if (!found) | ||
251 | { | ||
252 | /* if it still doesn't exist, we look in the parent directory | ||
253 | * for a generic file */ | ||
254 | pathlen = snprintf(path, sizeof(path), | ||
255 | "%scover%s." EXT, dir, size_string); | ||
256 | found = try_exts(path, pathlen); | ||
257 | } | ||
258 | } | ||
259 | if (found) | ||
260 | break; | ||
245 | } | 261 | } |
246 | 262 | ||
247 | if (!found) | 263 | if (!found) |