Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.
My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ * * Copyright (C) 2006-2008 Robert Keevil * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/ /* Audioscrobbler spec at: http://www.audioscrobbler.net/wiki/Portable_Player_Logging */ /* increment this on any code change that effects output */ /* longest entry I've had is 323, add a safety margin */ static int scrobbler_cache; static int cache_pos; static ; static bool pending = false; static bool scrobbler_initialised = false; static time_t timestamp; static unsigned long timestamp; /* Crude work-around for Archos Sims - return a set amount */ unsigned long { return 120000; } static void { int used; const char *base_filename = ".scrobbler.log"; const char *base_filename = ".scrobbler-timeless.log"; /* Get location of USB mass storage area */ used = snprintf(path, size, "/home/user/MyDocs/%s", base_filename); used = snprintf(path, size, "/sdcard/%s", base_filename); /* SDL/unknown RaaA build */ used = snprintf(path, size, "%s/%s", ROCKBOX_DIR, base_filename); /* (CONFIG_PLATFORM & PLATFORM_MAEMO) */ used = snprintf(path, size, "/%s", base_filename); ifsize) { logf("SCROBBLER: not enough buffer space for log file"); memset(path, 0, size); } } static void write_cache(void) { int i, fd; bool error = false; size_t buflen = MAX(MAX_PATH, SCROBBLER_CACHE_LEN); char buf[buflen]; get_scrobbler_filename(buf, buflen); /* If the file doesn't exist, create it. Check at each write since file may be deleted at any time */ if(!file_exists(buf)) { fd = open(buf, O_RDWR | O_CREAT, 0666); if(fd >= 0) { fdprintf(fd, "#AUDIOSCROBBLER/" SCROBBLER_VERSION "\n" "#TZ/UNKNOWN\n" "#CLIENT/Rockbox " TARGET_NAME SCROBBLER_REVISION "\n"); "#CLIENT/Rockbox " TARGET_NAME SCROBBLER_REVISION " Timeless\n"); close(fd); } else { logf("SCROBBLER: cannot create log file"); } } /* write the cache entries */ fd = open(buf, O_WRONLY | O_APPEND); if(fd >= 0) { logf("SCROBBLER: writing %d entries", cache_pos); for { /* copy data to temporary storage in case data moves during I/O */ logf("SCROBBLER: write %d", i); char* scrobbler_buf = core_get_data(scrobbler_cache); ssize_t len = strlcpy(buf, scrobbler_buf+(SCROBBLER_CACHE_LEN*i), buflen; if != len) error = true; } close(fd); } if { logf("SCROBBLER: error writing file"); } /* clear even if unsuccessful - don't want to overflow the buffer */ cache_pos = 0; } static void { (void)data; if write_cache(); } static void { if write_cache(); int ret; char rating = 'S'; /* Skipped */ char* scrobbler_buf = core_get_data(scrobbler_cache); logf("SCROBBLER: add_to_cache[%d]", cache_pos); if ) rating = 'L'; /* Listened */ if { ret = snprintf(scrobbler_buf+(SCROBBLER_CACHE_LEN*cache_pos), SCROBBLER_CACHE_LEN, "%s\t%s\t%s\t%d\t%d\t%c\t%ld\t%s\n", scrobbler_entry.artist, scrobbler_entry.album?scrobbler_entry.album:"", scrobbler_entry.title, scrobbler_entry.tracknum, (int)scrobbler_entry.length/1000, rating, (long)timestamp, scrobbler_entry.mb_track_id?scrobbler_entry.mb_track_id:""); } else { ret = snprintf(scrobbler_buf+(SCROBBLER_CACHE_LEN*cache_pos), SCROBBLER_CACHE_LEN, "%s\t%s\t%s\t\t%d\t%c\t%ld\t%s\n", scrobbler_entry.artist, scrobbler_entry.album?scrobbler_entry.album:"", scrobbler_entry.title, (int)scrobbler_entry.length/1000, rating, (long)timestamp, scrobbler_entry.mb_track_id?scrobbler_entry.mb_track_id:""); } if { logf("SCROBBLER: entry too long:"); logf("SCROBBLER: %s", scrobbler_entry.path); } else { cache_pos++; register_storage_idle_func(scrobbler_flush_callback); } } static void { = ()data; /* add entry using the previous scrobbler_entry and timestamp */ if add_to_cache(audio_prev_elapsed()); /* check if track was resumed > %50 played check for blank artist or track name */ if ((id->elapsed > (id->length/2)) || (!id->artist ) || (!id->title ) ) { pending = false; logf("SCROBBLER: skipping file %s", id->path); } else { logf("SCROBBLER: add pending"); copy_mp3entry(&scrobbler_entry, id); timestamp = mktime(get_time()); timestamp = 0; pending = true; } } int { logf("SCROBBLER: init %d", global_settings.audioscrobbler); if(!global_settings.audioscrobbler) return -1; scrobbler_cache = core_alloc("scrobller", SCROBBLER_MAX_CACHE*SCROBBLER_CACHE_LEN); add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, scrobbler_change_event); cache_pos = 0; pending = false; scrobbler_initialised = true; return 1; } void scrobbler_flush_cache(void) { if { /* Add any pending entries to the cache */ if(pending) add_to_cache(audio_prev_elapsed()); /* Write the cache to disk if needed */ if write_cache(); pending = false; } } void { scrobbler_flush_cache(); if { remove_event(PLAYBACK_EVENT_TRACK_CHANGE, scrobbler_change_event); scrobbler_initialised = false; } } void { if { if ) add_to_cache(audio_current_track()->elapsed); else add_to_cache(audio_prev_elapsed()); /* scrobbler_shutdown is called later, the cache will be written * make sure the final track isn't added twice when that happens */ pending = false; } } bool { return scrobbler_initialised; } |