| 1 | /* |
| 2 | * Copyright (c) 2017, 2020 Moritz Grimm <[email protected]> |
| 3 | * |
| 4 | * Permission to use, copy, modify, and distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:410:9`! |
| 18 | # include "config.h"cxx . . $ `<file>/src/config.h`/ |
| 19 | #endif /* HAVE_CONFIG_H */ |
| 20 | |
| 21 | #include "compat.h"cxx . . $ `<file>/compat/compat.h`/ |
| 22 | |
| 23 | #include <sys/stat.h> |
| 24 | #include <sys/wait.h> |
| 25 | |
| 26 | #include <errno.h> |
| 27 | #if defined(HAVE_LIBGEN_Hcxx . . $ `src/config.h:23:9`!) && !defined(__linux__cxx . . $ `<built-in>:398:9`!) |
| 28 | # include <libgen.h> |
| 29 | #endif /* HAVE_LIBGEN_H && !__linux__ */ |
| 30 | #include <limits.h> |
| 31 | #include <stdio.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <string.h> |
| 34 | #include <unistd.h> |
| 35 | |
| 36 | #include <taglib/tag_c.h> |
| 37 | |
| 38 | #include "cfg.h"cxx . . $ `<file>/src/cfg.h`/ |
| 39 | #include "log.h"cxx . . $ `<file>/src/log.h`/ |
| 40 | #include "mdata.h"cxx . . $ `<file>/src/mdata.h`/ |
| 41 | #include "util.h"cxx . . $ `<file>/src/util.h`/ |
| 42 | #include "xalloc.h"cxx . . $ `<file>/src/xalloc.h`/ |
| 43 | |
| 44 | struct mdatacxx . . $ mdata# { |
| 45 | char *filenamecxx . . $ mdata#filename.; |
| 46 | char *namecxx . . $ mdata#name.; |
| 47 | char *artistcxx . . $ mdata#artist.; |
| 48 | char *albumcxx . . $ mdata#album.; |
| 49 | char *titlecxx . . $ mdata#title.; |
| 50 | char *songinfocxx . . $ mdata#songinfo.; |
| 51 | int lengthcxx . . $ mdata#length.; |
| 52 | int normalize_stringscxx . . $ mdata#normalize_strings.; |
| 53 | int run_programcxx . . $ mdata#run_program.; |
| 54 | }; |
| 55 | |
| 56 | enum mdata_requestcxx . . $ mdata_request# { |
| 57 | MDATA_ARTISTcxx . . $ MDATA_ARTIST., |
| 58 | MDATA_ALBUMcxx . . $ MDATA_ALBUM., |
| 59 | MDATA_TITLEcxx . . $ MDATA_TITLE., |
| 60 | MDATA_SONGINFOcxx . . $ MDATA_SONGINFO. |
| 61 | }; |
| 62 | |
| 63 | static void _mdata_clearcxx . . $ _mdata_clear(a5984927f6db7af3).(struct mdatacxx . . $ mdata# *); |
| 64 | static char * _mdata_get_name_from_filenamecxx . . $ _mdata_get_name_from_filename(a8b8e32347182212).(const char *); |
| 65 | static void _mdata_generate_songinfocxx . . $ _mdata_generate_songinfo(a5984927f6db7af3).(struct mdatacxx . . $ mdata# *); |
| 66 | static void _mdata_normalize_stringcxx . . $ _mdata_normalize_string(3ed91490e421178f).(char **); |
| 67 | static void _mdata_normalize_stringscxx . . $ _mdata_normalize_strings(a5984927f6db7af3).(struct mdatacxx . . $ mdata# *); |
| 68 | static char * _mdata_runcxx . . $ _mdata_run(ee2ae82df1f607b8).(const char *, enum mdata_requestcxx . . $ mdata_request#); |
| 69 | |
| 70 | static void |
| 71 | _mdata_clearcxx . . $ _mdata_clear(a5984927f6db7af3).(struct mdatacxx . . $ mdata# *md) |
| 72 | { |
| 73 | int normalize_strings; |
| 74 | |
| 75 | normalize_strings = md->normalize_stringscxx . . $ mdata#normalize_strings.; |
| 76 | xfreecxx . . $ `src/xalloc.h:26:9`!(md->filename); |
| 77 | xfreecxx . . $ `src/xalloc.h:26:9`!(md->name); |
| 78 | xfreecxx . . $ `src/xalloc.h:26:9`!(md->artist); |
| 79 | xfreecxx . . $ `src/xalloc.h:26:9`!(md->album); |
| 80 | xfreecxx . . $ `src/xalloc.h:26:9`!(md->title); |
| 81 | xfreecxx . . $ `src/xalloc.h:26:9`!(md->songinfo); |
| 82 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(md, 0, sizeof(*md)); |
| 83 | md->lengthcxx . . $ mdata#length. = -1; |
| 84 | md->normalize_stringscxx . . $ mdata#normalize_strings. = normalize_strings; |
| 85 | } |
| 86 | |
| 87 | static char * |
| 88 | _mdata_get_name_from_filenamecxx . . $ _mdata_get_name_from_filename(a8b8e32347182212).(const char *filename) |
| 89 | { |
| 90 | char *tmp; |
| 91 | char *p1, *p2, *name; |
| 92 | |
| 93 | /* |
| 94 | * Make a copy of filename in case basename() is broken and attempts |
| 95 | * to modify its argument. |
| 96 | */ |
| 97 | tmp = xstrdupcxx . . $ `src/xalloc.h:25:9`!(filename); |
| 98 | if ((p1 = basenamecxx . . $ basename(a8b8e32347182212).(tmp)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 99 | /* |
| 100 | * Some implementations limit the input to PATH_MAX; bail out |
| 101 | * if that is exceeded and an error is returned. |
| 102 | */ |
| 103 | log_alertcxx . . $ log_alert(581fddd72a8db8fc).("%s: %s", tmp, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 104 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 105 | } |
| 106 | |
| 107 | if ((p2 = strrchrcxx . . $ `<external>/13506128340496143423/string.h:295:11`!(p1, '.')) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 108 | *p2 = '\0'; |
| 109 | |
| 110 | if (strlencxx . . $ strlen(751346f8406fd082).(p1) == 0) |
| 111 | name = xstrdupcxx . . $ `src/xalloc.h:25:9`!("[unknown]"); |
| 112 | else |
| 113 | name = util_char2utf8cxx . . $ util_char2utf8(a8b8e32347182212).(p1); |
| 114 | |
| 115 | xfreecxx . . $ `src/xalloc.h:26:9`!(tmp); |
| 116 | |
| 117 | return (name); |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | _mdata_generate_songinfocxx . . $ _mdata_generate_songinfo(a5984927f6db7af3).(struct mdatacxx . . $ mdata# *md) |
| 122 | { |
| 123 | char *str; |
| 124 | size_t str_size; |
| 125 | |
| 126 | str_size = 0; |
| 127 | if (md->artistcxx . . $ mdata#artist.) |
| 128 | str_size += strlencxx . . $ strlen(751346f8406fd082).(md->artistcxx . . $ mdata#artist.); |
| 129 | if (md->titlecxx . . $ mdata#title.) { |
| 130 | if (str_size) |
| 131 | str_size += strlencxx . . $ strlen(751346f8406fd082).(" - "); |
| 132 | str_size += strlencxx . . $ strlen(751346f8406fd082).(md->titlecxx . . $ mdata#title.); |
| 133 | } |
| 134 | if (md->albumcxx . . $ mdata#album.) { |
| 135 | if (str_size) |
| 136 | str_size += strlencxx . . $ strlen(751346f8406fd082).(" - "); |
| 137 | str_size += strlencxx . . $ strlen(751346f8406fd082).(md->albumcxx . . $ mdata#album.); |
| 138 | } |
| 139 | if (!str_size) |
| 140 | return; |
| 141 | str_size++; |
| 142 | str = xcalloccxx . . $ `src/xalloc.h:23:9`!(str_size, sizeof(*str)); |
| 143 | |
| 144 | if (md->artistcxx . . $ mdata#artist.) |
| 145 | strlcpycxx . . $ strlcpy(55abe9014c6d0e39).(str, md->artistcxx . . $ mdata#artist., str_size); |
| 146 | if (md->titlecxx . . $ mdata#title.) { |
| 147 | if (strlencxx . . $ strlen(751346f8406fd082).(str)) |
| 148 | strlcatcxx . . $ strlcat(55abe9014c6d0e39).(str, " - ", str_size); |
| 149 | strlcatcxx . . $ strlcat(55abe9014c6d0e39).(str, md->titlecxx . . $ mdata#title., str_size); |
| 150 | } |
| 151 | if (md->albumcxx . . $ mdata#album.) { |
| 152 | if (strlencxx . . $ strlen(751346f8406fd082).(str)) |
| 153 | strlcatcxx . . $ strlcat(55abe9014c6d0e39).(str, " - ", str_size); |
| 154 | strlcatcxx . . $ strlcat(55abe9014c6d0e39).(str, md->albumcxx . . $ mdata#album., str_size); |
| 155 | } |
| 156 | |
| 157 | md->songinfocxx . . $ mdata#songinfo. = str; |
| 158 | } |
| 159 | |
| 160 | static void |
| 161 | _mdata_normalize_stringcxx . . $ _mdata_normalize_string(3ed91490e421178f).(char **s) |
| 162 | { |
| 163 | char *str, *cp, *tmpstr, *tp; |
| 164 | int is_space; |
| 165 | |
| 166 | str = *s; |
| 167 | if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == str) |
| 168 | return; |
| 169 | |
| 170 | tmpstr = xcalloccxx . . $ `src/xalloc.h:23:9`!(strlen(str) + 1, sizeof(char)); |
| 171 | |
| 172 | tp = tmpstr; |
| 173 | is_space = 1; |
| 174 | for (cp = str; *cp != '\0'; cp++) { |
| 175 | if (*cp == ' ') { |
| 176 | if (!is_space) |
| 177 | *tp++ = ' '; |
| 178 | is_space = 1; |
| 179 | } else { |
| 180 | *tp++ = *cp; |
| 181 | is_space = 0; |
| 182 | } |
| 183 | } |
| 184 | if (strlencxx . . $ strlen(751346f8406fd082).(tmpstr) > 0 && tmpstr[strlencxx . . $ strlen(751346f8406fd082).(tmpstr) - 1] == ' ') |
| 185 | tmpstr[strlencxx . . $ strlen(751346f8406fd082).(tmpstr) - 1] = '\0'; |
| 186 | |
| 187 | xfreecxx . . $ `src/xalloc.h:26:9`!(str); |
| 188 | *s = xreallocarraycxx . . $ `src/xalloc.h:24:9`!(tmpstr, strlen(tmpstr) + 1, sizeof(*tmpstr)); |
| 189 | } |
| 190 | |
| 191 | static void |
| 192 | _mdata_normalize_stringscxx . . $ _mdata_normalize_strings(a5984927f6db7af3).(struct mdatacxx . . $ mdata# *md) |
| 193 | { |
| 194 | _mdata_normalize_stringcxx . . $ _mdata_normalize_string(3ed91490e421178f).(&md->artistcxx . . $ mdata#artist.); |
| 195 | _mdata_normalize_stringcxx . . $ _mdata_normalize_string(3ed91490e421178f).(&md->albumcxx . . $ mdata#album.); |
| 196 | _mdata_normalize_stringcxx . . $ _mdata_normalize_string(3ed91490e421178f).(&md->titlecxx . . $ mdata#title.); |
| 197 | _mdata_normalize_stringcxx . . $ _mdata_normalize_string(3ed91490e421178f).(&md->songinfocxx . . $ mdata#songinfo.); |
| 198 | } |
| 199 | |
| 200 | static char * |
| 201 | _mdata_runcxx . . $ _mdata_run(ee2ae82df1f607b8).(const char *program, enum mdata_requestcxx . . $ mdata_request# md_req) |
| 202 | { |
| 203 | char cmd[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`! + sizeof(" artist")]; |
| 204 | char buf[BUFSIZcxx . . $ `<external>/232824719582829767/stdio.h:104:9`!]; |
| 205 | FILEcxx . . $ FILE# *fp; |
| 206 | int ret; |
| 207 | |
| 208 | switch (md_req) { |
| 209 | case MDATA_ARTISTcxx . . $ MDATA_ARTIST.: |
| 210 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(cmd, sizeof(cmd), "%s artist", program); |
| 211 | break; |
| 212 | case MDATA_ALBUMcxx . . $ MDATA_ALBUM.: |
| 213 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(cmd, sizeof(cmd), "%s album", program); |
| 214 | break; |
| 215 | case MDATA_TITLEcxx . . $ MDATA_TITLE.: |
| 216 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(cmd, sizeof(cmd), "%s title", program); |
| 217 | break; |
| 218 | case MDATA_SONGINFOcxx . . $ MDATA_SONGINFO.: |
| 219 | default: |
| 220 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(cmd, sizeof(cmd), "%s", program); |
| 221 | break; |
| 222 | } |
| 223 | |
| 224 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 225 | log_debugcxx . . $ log_debug(581fddd72a8db8fc).("running metadata command: %s", cmd); |
| 226 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 227 | if ((fp = popencxx . . $ popen(82ec0787cd37e0a3).(cmd, "r")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 228 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: execution error: %s", cmd, |
| 229 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 230 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 231 | } |
| 232 | |
| 233 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(buf, 0, sizeof(buf)); |
| 234 | if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == fgetscxx . . $ fgets(efb0aaba7ac866ae).(buf, (int)sizeof(buf), fp) && |
| 235 | ferrorcxx . . $ ferror(89bc1efcdac0ca22).(fp)) { |
| 236 | log_alertcxx . . $ log_alert(581fddd72a8db8fc).("%s: output read error: %s", program, |
| 237 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 238 | pclosecxx . . $ pclose(89bc1efcdac0ca22).(fp); |
| 239 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 240 | } |
| 241 | ret = pclosecxx . . $ pclose(89bc1efcdac0ca22).(fp); |
| 242 | if (0 > ret) { |
| 243 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: %s", program, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 244 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 245 | } else if (WIFSIGNALEDcxx . . $ `<external>/3791503621068212355/wait.h:58:10`!(ret)) { |
| 246 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: exited with signal %d", program, |
| 247 | WTERMSIGcxx . . $ `<external>/3791503621068212355/wait.h:55:10`!(ret)); |
| 248 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 249 | } else if (0 != WEXITSTATUScxx . . $ `<external>/3791503621068212355/wait.h:54:10`!(ret)) { |
| 250 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: exited with error code %d", program, |
| 251 | WEXITSTATUScxx . . $ `<external>/3791503621068212355/wait.h:54:10`!(ret)); |
| 252 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 253 | } |
| 254 | |
| 255 | if (strlencxx . . $ strlen(751346f8406fd082).(buf) == sizeof(buf) - 1) |
| 256 | log_warningcxx . . $ log_warning(581fddd72a8db8fc).("metadata output truncated: %s", cmd); |
| 257 | |
| 258 | buf[strcspncxx . . $ strcspn(335c1dc86f5c867f).(buf, "\n")] = '\0'; |
| 259 | buf[strcspncxx . . $ strcspn(335c1dc86f5c867f).(buf, "\r")] = '\0'; |
| 260 | |
| 261 | return (xstrdupcxx . . $ `src/xalloc.h:25:9`!(buf)); |
| 262 | } |
| 263 | |
| 264 | struct mdatacxx . . $ mdata# * |
| 265 | mdata_createcxx . . $ mdata_create(bf1f2813200d3c0b).(void) |
| 266 | { |
| 267 | struct mdatacxx . . $ mdata# *md; |
| 268 | |
| 269 | md = xcalloccxx . . $ `src/xalloc.h:23:9`!(1UL, sizeof(*md)); |
| 270 | md->lengthcxx . . $ mdata#length. = -1; |
| 271 | |
| 272 | return (md); |
| 273 | } |
| 274 | |
| 275 | void |
| 276 | mdata_destroycxx . . $ mdata_destroy(4e1e1e14dfbb51f3).(struct mdatacxx . . $ mdata# **md_p) |
| 277 | { |
| 278 | struct mdatacxx . . $ mdata# *md = *md_p; |
| 279 | |
| 280 | if (md) |
| 281 | _mdata_clearcxx . . $ _mdata_clear(a5984927f6db7af3).(md); |
| 282 | xfreecxx . . $ `src/xalloc.h:26:9`!(md); |
| 283 | *md_p = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 284 | } |
| 285 | |
| 286 | void |
| 287 | mdata_set_normalize_stringscxx . . $ mdata_set_normalize_strings(e60fdab16eacd424).(struct mdatacxx . . $ mdata# *md, int normalize_strings) |
| 288 | { |
| 289 | md->normalize_stringscxx . . $ mdata#normalize_strings. = normalize_strings ? 1 : 0; |
| 290 | } |
| 291 | |
| 292 | int |
| 293 | mdata_parse_filecxx . . $ mdata_parse_file(65b6d78e09a82a4).(struct mdatacxx . . $ mdata# *md, const char *filename) |
| 294 | { |
| 295 | TagLib_Filecxx . . $ TagLib_File# *tf; |
| 296 | TagLib_Tagcxx . . $ TagLib_Tag# *tt; |
| 297 | const TagLib_AudioPropertiescxx . . $ TagLib_AudioProperties# *ta; |
| 298 | char *str; |
| 299 | |
| 300 | if (0 > accesscxx . . $ access(cb7559238bb26814).(filename, R_OKcxx . . $ `<external>/12628407106812493757/unistd.h:281:9`!)) { |
| 301 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: %s", filename, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 302 | return (-1); |
| 303 | } |
| 304 | |
| 305 | //taglib_set_string_management_enabled(0); |
| 306 | #ifdef HAVE_ICONVcxx . . $ `src/config.h:17:9`! |
| 307 | taglib_set_strings_unicodecxx . . $ taglib_set_strings_unicode(d4f767463ce0a6b3).(1); |
| 308 | #else |
| 309 | taglib_set_strings_unicode(0); |
| 310 | #endif /* HAVE_ICONV */ |
| 311 | |
| 312 | _mdata_clearcxx . . $ _mdata_clear(a5984927f6db7af3).(md); |
| 313 | md->filenamecxx . . $ mdata#filename. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(filename); |
| 314 | md->namecxx . . $ mdata#name. = _mdata_get_name_from_filenamecxx . . $ _mdata_get_name_from_filename(a8b8e32347182212).(filename); |
| 315 | |
| 316 | if ((tf = taglib_file_newcxx . . $ taglib_file_new(ab07e5829365f1e9).(md->filenamecxx . . $ mdata#filename.)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 317 | log_infocxx . . $ log_info(581fddd72a8db8fc).("%s: unable to extract metadata", |
| 318 | md->filenamecxx . . $ mdata#filename.); |
| 319 | md->songinfocxx . . $ mdata#songinfo. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(md->name); |
| 320 | return (0); |
| 321 | } |
| 322 | |
| 323 | tt = taglib_file_tagcxx . . $ taglib_file_tag(52aa7cdaf7e1d912).(tf); |
| 324 | |
| 325 | str = taglib_tag_artistcxx . . $ taglib_tag_artist(d5e3add03594a6c1).(tt); |
| 326 | if (0 < strlencxx . . $ strlen(751346f8406fd082).(str)) |
| 327 | md->artistcxx . . $ mdata#artist. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(str); |
| 328 | str = taglib_tag_albumcxx . . $ taglib_tag_album(d5e3add03594a6c1).(tt); |
| 329 | if (0 < strlencxx . . $ strlen(751346f8406fd082).(str)) |
| 330 | md->albumcxx . . $ mdata#album. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(str); |
| 331 | str = taglib_tag_titlecxx . . $ taglib_tag_title(d5e3add03594a6c1).(tt); |
| 332 | if (0 < strlencxx . . $ strlen(751346f8406fd082).(str)) |
| 333 | md->titlecxx . . $ mdata#title. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(str); |
| 334 | |
| 335 | taglib_tag_free_stringscxx . . $ taglib_tag_free_strings(49f6e7a06ebc5aa8).(); |
| 336 | |
| 337 | ta = taglib_file_audiopropertiescxx . . $ taglib_file_audioproperties(823fd848a3fc573a).(tf); |
| 338 | md->lengthcxx . . $ mdata#length. = taglib_audioproperties_lengthcxx . . $ taglib_audioproperties_length(f1a4a93cf1b0e85e).(ta); |
| 339 | |
| 340 | taglib_file_freecxx . . $ taglib_file_free(40669313b02d9c01).(tf); |
| 341 | |
| 342 | if (md->normalize_stringscxx . . $ mdata#normalize_strings.) |
| 343 | _mdata_normalize_stringscxx . . $ _mdata_normalize_strings(a5984927f6db7af3).(md); |
| 344 | _mdata_generate_songinfocxx . . $ _mdata_generate_songinfo(a5984927f6db7af3).(md); |
| 345 | |
| 346 | md->run_programcxx . . $ mdata#run_program. = 0; |
| 347 | |
| 348 | return (0); |
| 349 | } |
| 350 | |
| 351 | int |
| 352 | mdata_run_programcxx . . $ mdata_run_program(65b6d78e09a82a4).(struct mdatacxx . . $ mdata# *md, const char *program) |
| 353 | { |
| 354 | struct statcxx . . $ stat# st; |
| 355 | char *artist, *album, *title, *songinfo; |
| 356 | |
| 357 | if (statcxx . . $ stat(a9cd1e23e96f423c).(program, &st) == -1) { |
| 358 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: %s", program, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 359 | return (-1); |
| 360 | } |
| 361 | if (st.st_modecxx . . $ stat#st_mode. & S_IWOTHcxx . . $ `<external>/531885356569766532/stat.h:187:9`!) { |
| 362 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: world writeable", program); |
| 363 | return (-1); |
| 364 | } |
| 365 | if (!(st.st_modecxx . . $ stat#st_mode. & (S_IEXECcxx . . $ `<external>/531885356569766532/stat.h:177:10`! | S_IXGRPcxx . . $ `<external>/531885356569766532/stat.h:182:9`! | S_IXOTHcxx . . $ `<external>/531885356569766532/stat.h:188:9`!))) { |
| 366 | log_errorcxx . . $ log_error(581fddd72a8db8fc).("%s: not an executable program", program); |
| 367 | return (-1); |
| 368 | } |
| 369 | |
| 370 | artist = album = title = songinfo = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 371 | if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == (artist = _mdata_runcxx . . $ _mdata_run(ee2ae82df1f607b8).(program, MDATA_ARTISTcxx . . $ MDATA_ARTIST.)) || |
| 372 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == (album = _mdata_runcxx . . $ _mdata_run(ee2ae82df1f607b8).(program, MDATA_ALBUMcxx . . $ MDATA_ALBUM.)) || |
| 373 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == (title = _mdata_runcxx . . $ _mdata_run(ee2ae82df1f607b8).(program, MDATA_TITLEcxx . . $ MDATA_TITLE.)) || |
| 374 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! == (songinfo = _mdata_runcxx . . $ _mdata_run(ee2ae82df1f607b8).(program, MDATA_SONGINFOcxx . . $ MDATA_SONGINFO.))) |
| 375 | goto error; |
| 376 | |
| 377 | _mdata_clearcxx . . $ _mdata_clear(a5984927f6db7af3).(md); |
| 378 | md->filenamecxx . . $ mdata#filename. = xstrdupcxx . . $ `src/xalloc.h:25:9`!(program); |
| 379 | md->namecxx . . $ mdata#name. = xstrdupcxx . . $ `src/xalloc.h:25:9`!("[unknown]"); |
| 380 | |
| 381 | if (0 == strlencxx . . $ strlen(751346f8406fd082).(artist)) |
| 382 | xfreecxx . . $ `src/xalloc.h:26:9`!(artist); |
| 383 | else |
| 384 | md->artistcxx . . $ mdata#artist. = artist; |
| 385 | |
| 386 | if (0 == strlencxx . . $ strlen(751346f8406fd082).(album)) |
| 387 | xfreecxx . . $ `src/xalloc.h:26:9`!(album); |
| 388 | else |
| 389 | md->albumcxx . . $ mdata#album. = album; |
| 390 | |
| 391 | if (0 == strlencxx . . $ strlen(751346f8406fd082).(title)) |
| 392 | xfreecxx . . $ `src/xalloc.h:26:9`!(title); |
| 393 | else |
| 394 | md->titlecxx . . $ mdata#title. = title; |
| 395 | |
| 396 | if (0 == strlencxx . . $ strlen(751346f8406fd082).(songinfo)) |
| 397 | xfreecxx . . $ `src/xalloc.h:26:9`!(songinfo); |
| 398 | else |
| 399 | md->songinfocxx . . $ mdata#songinfo. = songinfo; |
| 400 | |
| 401 | if (md->normalize_stringscxx . . $ mdata#normalize_strings.) |
| 402 | _mdata_normalize_stringscxx . . $ _mdata_normalize_strings(a5984927f6db7af3).(md); |
| 403 | |
| 404 | md->run_programcxx . . $ mdata#run_program. = 1; |
| 405 | |
| 406 | return (0); |
| 407 | |
| 408 | error: |
| 409 | xfreecxx . . $ `src/xalloc.h:26:9`!(artist); |
| 410 | xfreecxx . . $ `src/xalloc.h:26:9`!(album); |
| 411 | xfreecxx . . $ `src/xalloc.h:26:9`!(title); |
| 412 | xfreecxx . . $ `src/xalloc.h:26:9`!(songinfo); |
| 413 | |
| 414 | return (-1); |
| 415 | } |
| 416 | |
| 417 | int |
| 418 | mdata_refreshcxx . . $ mdata_refresh(cea3693af55ce6cb).(struct mdatacxx . . $ mdata# *md) |
| 419 | { |
| 420 | char *filename = xstrdupcxx . . $ `src/xalloc.h:25:9`!(md->filename); |
| 421 | int ret; |
| 422 | |
| 423 | if (md->run_programcxx . . $ mdata#run_program.) |
| 424 | ret = mdata_run_programcxx . . $ mdata_run_program(65b6d78e09a82a4).(md, filename); |
| 425 | else |
| 426 | ret = mdata_parse_filecxx . . $ mdata_parse_file(65b6d78e09a82a4).(md, filename); |
| 427 | xfreecxx . . $ `src/xalloc.h:26:9`!(filename); |
| 428 | |
| 429 | return (ret); |
| 430 | } |
| 431 | |
| 432 | const char * |
| 433 | mdata_get_filenamecxx . . $ mdata_get_filename(42a08b9e3d38b1e0).(struct mdatacxx . . $ mdata# *md) |
| 434 | { |
| 435 | return (md->filenamecxx . . $ mdata#filename.); |
| 436 | } |
| 437 | |
| 438 | const char * |
| 439 | mdata_get_namecxx . . $ mdata_get_name(42a08b9e3d38b1e0).(struct mdatacxx . . $ mdata# *md) |
| 440 | { |
| 441 | return (md->namecxx . . $ mdata#name.); |
| 442 | } |
| 443 | |
| 444 | const char * |
| 445 | mdata_get_artistcxx . . $ mdata_get_artist(42a08b9e3d38b1e0).(struct mdatacxx . . $ mdata# *md) |
| 446 | { |
| 447 | return (md->artistcxx . . $ mdata#artist.); |
| 448 | } |
| 449 | |
| 450 | const char * |
| 451 | mdata_get_albumcxx . . $ mdata_get_album(42a08b9e3d38b1e0).(struct mdatacxx . . $ mdata# *md) |
| 452 | { |
| 453 | return (md->albumcxx . . $ mdata#album.); |
| 454 | } |
| 455 | |
| 456 | const char * |
| 457 | mdata_get_titlecxx . . $ mdata_get_title(42a08b9e3d38b1e0).(struct mdatacxx . . $ mdata# *md) |
| 458 | { |
| 459 | return (md->titlecxx . . $ mdata#title.); |
| 460 | } |
| 461 | |
| 462 | const char * |
| 463 | mdata_get_songinfocxx . . $ mdata_get_songinfo(42a08b9e3d38b1e0).(struct mdatacxx . . $ mdata# *md) |
| 464 | { |
| 465 | return (md->songinfocxx . . $ mdata#songinfo.); |
| 466 | } |
| 467 | |
| 468 | int |
| 469 | mdata_get_lengthcxx . . $ mdata_get_length(cea3693af55ce6cb).(struct mdatacxx . . $ mdata# *md) |
| 470 | { |
| 471 | return (md->lengthcxx . . $ mdata#length.); |
| 472 | } |
| 473 | |
| 474 | int |
| 475 | mdata_strformatcxx . . $ mdata_strformat(2d1219fb966f86b0).(struct mdatacxx . . $ mdata# *md, char *buf, size_t bufsize, const char *format) |
| 476 | { |
| 477 | struct util_dictcxx . . $ util_dict# dicts[6]; |
| 478 | char *str; |
| 479 | int ret; |
| 480 | |
| 481 | if (format == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 482 | return (-1); |
| 483 | |
| 484 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(dicts, 0, sizeof(dicts)); |
| 485 | dicts[0].fromcxx . . $ util_dict#from. = PLACEHOLDER_ARTISTcxx . . $ `src/cfg.h:21:9`!; |
| 486 | dicts[0].tocxx . . $ util_dict#to. = mdata_get_artistcxx . . $ mdata_get_artist(42a08b9e3d38b1e0).(md) ? mdata_get_artistcxx . . $ mdata_get_artist(42a08b9e3d38b1e0).(md) : ""; |
| 487 | dicts[1].fromcxx . . $ util_dict#from. = PLACEHOLDER_ALBUMcxx . . $ `src/cfg.h:22:9`!; |
| 488 | dicts[1].tocxx . . $ util_dict#to. = mdata_get_albumcxx . . $ mdata_get_album(42a08b9e3d38b1e0).(md) ? mdata_get_albumcxx . . $ mdata_get_album(42a08b9e3d38b1e0).(md) : ""; |
| 489 | dicts[2].fromcxx . . $ util_dict#from. = PLACEHOLDER_TITLEcxx . . $ `src/cfg.h:23:9`!; |
| 490 | dicts[2].tocxx . . $ util_dict#to. = mdata_get_titlecxx . . $ mdata_get_title(42a08b9e3d38b1e0).(md) ? mdata_get_titlecxx . . $ mdata_get_title(42a08b9e3d38b1e0).(md) : ""; |
| 491 | dicts[3].fromcxx . . $ util_dict#from. = PLACEHOLDER_TRACKcxx . . $ `src/cfg.h:24:9`!; |
| 492 | dicts[3].tocxx . . $ util_dict#to. = mdata_get_filenamecxx . . $ mdata_get_filename(42a08b9e3d38b1e0).(md); |
| 493 | dicts[4].fromcxx . . $ util_dict#from. = PLACEHOLDER_STRINGcxx . . $ `src/cfg.h:25:9`!; |
| 494 | dicts[4].tocxx . . $ util_dict#to. = mdata_get_songinfocxx . . $ mdata_get_songinfo(42a08b9e3d38b1e0).(md) ? mdata_get_songinfocxx . . $ mdata_get_songinfo(42a08b9e3d38b1e0).(md) : ""; |
| 495 | |
| 496 | str = util_expand_wordscxx . . $ util_expand_words(27058f725fae1c57).(format, dicts); |
| 497 | ret = (int)strlencxx . . $ strlen(751346f8406fd082).(str); |
| 498 | |
| 499 | strlcpycxx . . $ strlcpy(55abe9014c6d0e39).(buf, str, bufsize); |
| 500 | xfreecxx . . $ `src/xalloc.h:26:9`!(str); |
| 501 | |
| 502 | return (ret); |
| 503 | } |