aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miragextract.122
-rw-r--r--miragextract.c41
-rw-r--r--miragextract.rst19
3 files changed, 67 insertions, 15 deletions
diff --git a/miragextract.1 b/miragextract.1
index 7f01155..6c73e99 100644
--- a/miragextract.1
+++ b/miragextract.1
@@ -57,6 +57,12 @@ Print short usage string.
.B \-l
Lists the tracks in the image without extracting them.
.TP
+.B \-a
+Extract only audio tracks.
+.TP
+.B \-d
+Extract only data tracks.
+.TP
.B \-s
Swaps bytes in audio tracks. Use this if your audio files sound
like white noise or gibberish.
@@ -67,20 +73,30 @@ Default behaviour is to extract all tracks.
.TP
.B \-b
Sets the base filename for the output files. Default is \(aqtrack\(aq.
+See also the \-n option. Beware of using filenames with directory
+separators in them: the output files will be written in the same
+dir as the input file. Hopefully you have permission to write there.
+.TP
+.B \-n
+Set the base filename to the input filename, minus its extension.
+E.g. for foo.cue, this is the same as saying "\-b foo".
.TP
.B \-f
Sets the format and filename extension for the output files.
-Choices are \(aqwav\(aq, \(aqogg\(aq, \(aqflac\(aq, \(aqcdda\(aq (raw CD audio). Default is \(aqwav\(aq.
+Choices are \fBwav\fP, \fBogg\fP, \fBflac\fP, \fBcdda\fP (raw CD audio). Default is \fBwav\fP\&.
.TP
.B \-q
-Quality setting for .ogg and .flac output files. Integer from 0
-to 10. Default is 7.
+Quality setting for ogg and flac output files. Integer from 0
+to 10. Default is 7. Has very little effect on flac, and no effect on
+wav or cdda output.
.UNINDENT
.SH NOTES
.sp
Image\-file is e.g. a .cue, .ccd, .nrg, .mds, or anything else supported
by libmirage. See the README for your version of libmirage for details.
.sp
+Output files will be overwritten if they already exist, with no prompting.
+.sp
Output audio files are named track01.wav, track02.wav, etc by default. The
\(aqtrack\(aq part of the name can be set with \-b, and the extension will
match the encoding set with \-f. Note that mp3 is NOT a valid \-f option.
diff --git a/miragextract.c b/miragextract.c
index 9d63476..6861aef 100644
--- a/miragextract.c
+++ b/miragextract.c
@@ -22,6 +22,9 @@ char *outfmt = "wav";
int want_track = 0; /* -1 = no tracks, 0 = all, 1-99 = just that one */
double quality = 0.7l;
int swap_bytes = 0;
+int autoname = 0;
+int want_data = 1;
+int want_audio = 1;
void die(char *msg) {
fprintf(stderr, "%s: %s\n", self, msg);
@@ -65,29 +68,24 @@ void extract_track(int t, int extract) {
switch(sector_type) {
case MIRAGE_SECTOR_MODE1:
case MIRAGE_SECTOR_MODE2_FORM1:
- // printf("Track %d is data, extracting\n", output_track_number);
printf("data, ");
ext = "iso";
+ if(!want_data) extract = 0;
break;
case MIRAGE_SECTOR_AUDIO:
- // printf("Track %d is audio, extracting\n", output_track_number);
printf("audio, ");
+ if(!want_audio) extract = 0;
ext = outfmt;
break;
default:
- // printf("Track %d is unsupported type, dumping raw\n", output_track_number);
printf("<unknown>, ");
ext = "raw";
+ if(!want_data) extract = 0;
break;
}
sector = mirage_track_get_sector(track, 0, 0, NULL);
- /*
- mirage_sector_get_data(sector, &buf, &len, NULL);
- printf("got %d bytes per sector\n", len);
- */
-
sprintf(outfile, "%s%02d.%s", outfilebase, output_track_number, ext);
if(extract) {
@@ -142,10 +140,22 @@ void extract_track(int t, int extract) {
return;
}
+void set_auto_name(void) {
+ static char autoname[4096];
+ char *p;
+
+ strcpy(autoname, imagefile);
+ if((p = strrchr(autoname, '.'))) {
+ *p = '\0';
+ }
+
+ outfilebase = autoname;
+}
+
void usage(int exit_code) {
fprintf(exit_code ? stderr : stdout,
"miragextract v" VERSION " by B. Watson, WTFPL\n"
- "Usage: %s [-l] [-s] [-t track] [-b base] [-f fmt ] [-q quality ] image-file\n"
+ "Usage: %s [-l] [-s] [-n] [-a] [-d] [-t track] [-b base] [-f fmt ] [-q quality ] image-file\n"
"See man page for details\n", self);
exit(exit_code);
}
@@ -161,6 +171,14 @@ void parse_args(int argc, char **argv) {
case 'l':
want_track = -1;
break;
+ case 'a':
+ want_audio = 1;
+ want_data = 0;
+ break;
+ case 'd':
+ want_audio = 0;
+ want_data = 1;
+ break;
case 's':
swap_bytes = 1;
break;
@@ -196,6 +214,9 @@ void parse_args(int argc, char **argv) {
} else
die("-t option requires track argument");
break;
+ case 'n':
+ autoname = 1;
+ break;
default:
die("unrecognized option");
break;
@@ -208,6 +229,8 @@ void parse_args(int argc, char **argv) {
}
if(!imagefile) die("missing image file argument");
+
+ if(autoname) set_auto_name();
}
int main(int argc, char **argv) {
diff --git a/miragextract.rst b/miragextract.rst
index 5a097f8..3ae82db 100644
--- a/miragextract.rst
+++ b/miragextract.rst
@@ -41,6 +41,10 @@ OPTIONS
-l Lists the tracks in the image without extracting them.
+-a Extract only audio tracks.
+
+-d Extract only data tracks.
+
-s Swaps bytes in audio tracks. Use this if your audio files sound
like white noise or gibberish.
@@ -48,12 +52,19 @@ OPTIONS
Default behaviour is to extract all tracks.
-b Sets the base filename for the output files. Default is 'track'.
+ See also the -n option. Beware of using filenames with directory
+ separators in them: the output files will be written in the same
+ dir as the input file. Hopefully you have permission to write there.
+
+-n Set the base filename to the input filename, minus its extension.
+ E.g. for foo.cue, this is the same as saying "-b foo".
-f Sets the format and filename extension for the output files.
- Choices are 'wav', 'ogg', 'flac', 'cdda' (raw CD audio). Default is 'wav'.
+ Choices are **wav**, **ogg**, **flac**, **cdda** (raw CD audio). Default is **wav**.
--q Quality setting for .ogg and .flac output files. Integer from 0
- to 10. Default is 7.
+-q Quality setting for ogg and flac output files. Integer from 0
+ to 10. Default is 7. Has very little effect on flac, and no effect on
+ wav or cdda output.
NOTES
=====
@@ -61,6 +72,8 @@ NOTES
Image-file is e.g. a .cue, .ccd, .nrg, .mds, or anything else supported
by libmirage. See the README for your version of libmirage for details.
+Output files will be overwritten if they already exist, with no prompting.
+
Output audio files are named track01.wav, track02.wav, etc by default. The
'track' part of the name can be set with -b, and the extension will
match the encoding set with -f. Note that mp3 is NOT a valid -f option.