]> diplodocus.org Git - flac-archive/blob - stupid
Add stupid diff to metaflac to extract PICTURE.
[flac-archive] / stupid
1 diff -Naur -x '*~' flac-1.1.3-beta2/src/metaflac/.gdb_history mine/src/metaflac/.gdb_history
2 --- flac-1.1.3-beta2/src/metaflac/.gdb_history 1970-01-01 00:00:00.000000000 +0000
3 +++ mine/src/metaflac/.gdb_history 2006-10-28 08:24:22.000000000 +0000
4 @@ -0,0 +1,2 @@
5 +set height 0
6 +set width 0
7 diff -Naur -x '*~' flac-1.1.3-beta2/src/metaflac/operations.c mine/src/metaflac/operations.c
8 --- flac-1.1.3-beta2/src/metaflac/operations.c 2006-09-28 18:18:45.000000000 +0000
9 +++ mine/src/metaflac/operations.c 2006-10-28 08:39:01.000000000 +0000
10 @@ -359,6 +359,7 @@
11 case OP__EXPORT_CUESHEET_TO:
12 ok = do_shorthand_operation__cuesheet(filename, chain, operation, needs_write);
13 break;
14 + case OP__EXPORT_PICTURE:
15 case OP__IMPORT_PICTURE:
16 ok = do_shorthand_operation__picture(filename, chain, operation, needs_write);
17 break;
18 diff -Naur -x '*~' flac-1.1.3-beta2/src/metaflac/operations_shorthand_picture.c mine/src/metaflac/operations_shorthand_picture.c
19 --- flac-1.1.3-beta2/src/metaflac/operations_shorthand_picture.c 2006-10-10 00:09:39.000000000 +0000
20 +++ mine/src/metaflac/operations_shorthand_picture.c 2006-10-29 08:15:36.000000000 +0000
21 @@ -16,6 +16,9 @@
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 */
24
25 +#include <fcntl.h>
26 +#include <unistd.h>
27 +
28 #if HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 @@ -29,11 +32,35 @@
32
33 static FLAC__bool import_pic_from(const char *filename, FLAC__StreamMetadata **picture, const char *specification, FLAC__bool *needs_write);
34
35 +/* Write all of buf, even if write(2) is interrupted. */
36 +static ssize_t
37 +full_write(int fd, const char *buf, size_t nbytes)
38 +{
39 + ssize_t r, w = 0;
40 +
41 + /* Loop until nbytes of buf have been written. */
42 + while (w < nbytes) {
43 + /* Keep trying until write succeeds without interruption. */
44 + do {
45 + r = write(fd, buf + w, nbytes - w);
46 + } while (r < 0 && errno == EINTR);
47 +
48 + if (r < 0) {
49 + return r;
50 + }
51 +
52 + w += r;
53 + }
54 +
55 + return w;
56 +}
57 +
58 FLAC__bool do_shorthand_operation__picture(const char *filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write)
59 {
60 FLAC__bool ok = true, has_type1 = false, has_type2 = false;
61 FLAC__StreamMetadata *picture = 0;
62 FLAC__Metadata_Iterator *iterator = FLAC__metadata_iterator_new();
63 + FLAC__StreamMetadata *block;
64
65 if(0 == iterator)
66 die("out of memory allocating iterator");
67 @@ -54,6 +81,43 @@
68 }
69 }
70 break;
71 + case OP__EXPORT_PICTURE:
72 + do {
73 + block = FLAC__metadata_iterator_get_block(iterator);
74 + ok &= (0 != block);
75 + if(!ok) {
76 + fprintf(stderr, "%s: ERROR: couldn't get block from chain\n", filename);
77 + continue;
78 + }
79 + if (block->type != FLAC__METADATA_TYPE_PICTURE)
80 + continue;
81 + if (block->data.picture.type != FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER)
82 + continue;
83 + int fd = open(operation->argument.specification.value, O_WRONLY | O_EXCL | O_CREAT, 0644);
84 + if (fd < 0) {
85 + perror("open");
86 + ok = 0;
87 + break;
88 + }
89 +
90 + if(0 != block->data.picture.data)
91 + if (full_write(fd, block->data.picture.data, block->data.picture.data_length) != block->data.picture.data_length) {
92 + perror("write");
93 + ok = 0;
94 + break;
95 + }
96 + if (fsync(fd) < 0) {
97 + perror("fsync");
98 + ok = 0;
99 + break;
100 + }
101 + if (close(fd) < 0) {
102 + perror("close");
103 + ok = 0;
104 + break;
105 + }
106 + } while(ok && FLAC__metadata_iterator_next(iterator));
107 + break;
108 default:
109 ok = false;
110 FLAC__ASSERT(0);
111 diff -Naur -x '*~' flac-1.1.3-beta2/src/metaflac/options.c mine/src/metaflac/options.c
112 --- flac-1.1.3-beta2/src/metaflac/options.c 2006-09-26 00:52:23.000000000 +0000
113 +++ mine/src/metaflac/options.c 2006-10-28 10:47:20.000000000 +0000
114 @@ -72,6 +72,7 @@
115 { "export-tags-to", 1, 0, 0 },
116 { "import-cuesheet-from", 1, 0, 0 },
117 { "export-cuesheet-to", 1, 0, 0 },
118 + { "stupid-export-picture", 1, 0, 0 },
119 { "import-picture", 1, 0, 0 },
120 { "add-seekpoint", 1, 0, 0 },
121 { "add-replay-gain", 0, 0, 0 },
122 @@ -547,6 +548,14 @@
123 ok = false;
124 }
125 }
126 + else if(0 == strcmp(opt, "stupid-export-picture")) {
127 + op = append_shorthand_operation(options, OP__EXPORT_PICTURE);
128 + FLAC__ASSERT(0 != option_argument);
129 + if(!parse_string(option_argument, &(op->argument.specification.value))) {
130 + fprintf(stderr, "ERROR (--%s): missing specification\n", opt);
131 + ok = false;
132 + }
133 + }
134 else if(0 == strcmp(opt, "import-picture")) {
135 op = append_shorthand_operation(options, OP__IMPORT_PICTURE);
136 FLAC__ASSERT(0 != option_argument);
137 diff -Naur -x '*~' flac-1.1.3-beta2/src/metaflac/options.h mine/src/metaflac/options.h
138 --- flac-1.1.3-beta2/src/metaflac/options.h 2006-09-25 15:21:49.000000000 +0000
139 +++ mine/src/metaflac/options.h 2006-10-28 07:50:44.000000000 +0000
140 @@ -60,6 +60,7 @@
141 OP__EXPORT_VC_TO,
142 OP__IMPORT_CUESHEET_FROM,
143 OP__EXPORT_CUESHEET_TO,
144 + OP__EXPORT_PICTURE,
145 OP__IMPORT_PICTURE,
146 OP__ADD_SEEKPOINT,
147 OP__ADD_REPLAY_GAIN,