static void get_output_path (DB_playItem_t *it, const char *outfolder, const char *outfile, ddb_encoder_preset_t *encoder_preset, char *out, int sz) { int l; char fname[PATH_MAX]; char *path = outfolder[0] ? strdupa (outfolder) : strdupa (getenv("HOME")); char *pattern = strdupa (outfile); // replace invalid chars char invalid[] = "?%*:|\"<>"; char *p = path; while (*p) { if (strchr (invalid, *p)) { *p = '_'; } p++; } snprintf (out, sz, "%s/", path); // split path and create directories char *field = pattern; char *s = pattern; while (*s) { if ((*s == '/') || (*s == '\\')) { *s = '\0'; get_output_field (it, field, fname, sizeof(fname)); l = strlen (out); snprintf (out+l, sz-l, "%s/", fname); mkdir (out, 0755); field = s+1; } s++; } // last part of outfile is the filename get_output_field (it, field, fname, sizeof(fname)); l = strlen (out); snprintf (out+l, sz-l, "%s.%s", fname, encoder_preset->ext); trace ("converter output file is '%s'\n", out); }
void get_output_path (DB_playItem_t *it, const char *outfolder_user, const char *outfile, ddb_encoder_preset_t *encoder_preset, int preserve_folder_structure, const char *root_folder, int write_to_source_folder, char *out, int sz) { trace ("get_output_path: %s %s %s\n", outfolder_user, outfile, root_folder); deadbeef->pl_lock (); const char *uri = strdupa (deadbeef->pl_find_meta (it, ":URI")); deadbeef->pl_unlock (); char outfolder_preserve[2000]; if (preserve_folder_structure) { // generate new outfolder int rootlen = strlen (root_folder); const char *e = strrchr (uri, '/'); if (e) { const char *s = uri + rootlen; char subpath[e-s+1]; memcpy (subpath, s, e-s); subpath[e-s] = 0; snprintf (outfolder_preserve, sizeof (outfolder_preserve), "%s%s", outfolder_user[0] ? outfolder_user : getenv("HOME"), subpath); } } const char *outfolder; if (write_to_source_folder) { char *path = strdupa (uri); char *sep = strrchr (path, '/'); if (sep) { *sep = 0; } outfolder = path; } else { outfolder = preserve_folder_structure ? outfolder_preserve : outfolder_user; } int l; char fname[PATH_MAX]; int pathl = strlen(outfolder)*2+1; char path[pathl]; char *pattern = strdupa (outfile); snprintf (out, sz, "%s/", outfolder); // split path, and expand each path component using get_output_field char *field = pattern; char *s = pattern; while (*s) { if ((*s == '/') || (*s == '\\')) { *s = '\0'; get_output_field (it, field, fname, sizeof(fname)); l = strlen (out); snprintf (out+l, sz-l, "%s/", fname); field = s+1; } s++; } // last part of outfile is the filename get_output_field (it, field, fname, sizeof(fname)); l = strlen (out); snprintf (out+l, sz-l, "%s.%s", fname, encoder_preset->ext); trace ("converter output file is '%s'\n", out); }