Skip to content

Commit f518857

Browse files
committed
1.5.14: fix #1: opuspic2tag
1 parent a32d76a commit f518857

File tree

9 files changed

+724
-6
lines changed

9 files changed

+724
-6
lines changed

doc/man/man1/opuschgain.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
44
.\" Please send any bug reports, improvements, comments, patches,
55
.\" etc. to Steve Cheng <[email protected]>.
6-
.TH "OPUSCHGAIN" "1" "2019-06-02" "1.5.8" "User Manual"
6+
.TH "OPUSCHGAIN" "1" "2022-07-24" "1.5.14" "User Manual"
77

88
.SH NAME
99
opuschgain \- Updated Ogg Opus file output gain and R128 gain tag

doc/man/man1/opuscomment.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
44
.\" Please send any bug reports, improvements, comments, patches,
55
.\" etc. to Steve Cheng <[email protected]>.
6-
.TH "OPUSCOMMENT" "1" "2019-06-02" "1.5.8" "User Manual"
6+
.TH "OPUSCOMMENT" "1" "2022-07-24" "1.5.14" "User Manual"
77

88
.SH NAME
99
opuscomment \- Ogg Edit Opus file output gain and tag

doc/man/man1/opusmbptag.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.\" <http://shell.ipoline.com/~elmert/comp/docbook2X/>
44
.\" Please send any bug reports, improvements, comments, patches,
55
.\" etc. to Steve Cheng <[email protected]>.
6-
.TH "OPUSMBPTAG" "1" "2019-06-02" "1.5.8" "User Manual"
6+
.TH "OPUSMBPTAG" "1" "2022-07-24" "1.5.14" "User Manual"
77

88
.SH NAME
99
opusmbptag \- Generate METADATA_BLOCK_PICTURE tag from image file

doc/man/man1/opuspic2tag.1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.TH "OpusPic2Tag" "1" "2022-07-24" "1.5.14" "User Manual"
2+
.SH NAME
3+
opuspic2tag \- Convert picture to opus tag
4+
.SH SYNOPSIS
5+
.B opuspic2tag
6+
.RI [ OPTIONS ]
7+
.I FILE{.jpg,.png,.gif}
8+
.SH DESCRIPTION
9+
.PP
10+
\fBopuspic2tag\fP is part \fBopustags\fP for edit the comment header of an Opus file.
11+
.SH OPTIONS
12+
.TP
13+
.B \-h, \-\-help
14+
Display a brief description of the options.
15+
.TP
16+
.B \-d, \-\-desc \fISTRING\fI
17+
description
18+
.TP
19+
.B \-t, \-\-type NUM
20+
set image type by 0-20 or keywords. Default: 3
21+
.TP
22+
.B \-o, \-\-output \fIFILE\fI
23+
Output text file.
24+
.SH EXAMPLE
25+
opuspic2tag cover.jpg > cover.opustags
26+
.PP
27+
opuspic2tag -o cover.opustags cover.png
28+
.PP
29+
opuspic2tag cover.gif >> file.opustags
30+
.SH SEE ALSO
31+
.BR opuscomment (1),
32+
.BR opusenc (1),
33+
.BR vorbiscomment (1),
34+
.BR sed (1)
35+
.SH AUTHOR
36+
Frédéric Mangano <[email protected]>

src/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ CC=c99
1010
CFLAGS=-D_POSIX_C_SOURCE=200809L -DNLS
1111
LDFLAGS=-logg -lm -lpthread
1212
SRCS=put-tags.c parse-tags.c read.c read-flac.c ocutil.c retrieve-tags.c select-codec.c
13+
SRCP=opuspic2tag.c picture.c
1314
CONFSRCS=endianness.c error.c main.c
1415
HEADERS=global.h ocutil.h limit.h error.h iconv-impl.h
1516
ERRORDEFS=errordef/opus.tab errordef/main.tab
1617
OBJS=$(SRCS:.c=.o) $(CONFSRCS:.c=.o)
18+
OBJP=$(SRCP:.c=.o)
19+
RM = rm -f
1720

18-
all: opuscomment
21+
all: opuscomment opuspic2tag
1922

2023
opuscomment: $(OBJS)
2124
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
2225

26+
opuspic2tag: $(OBJP)
27+
$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
28+
2329
.SUFFIXES:
2430
.SUFFIXES: .c .o
2531

@@ -39,4 +45,4 @@ main.c: $(HEADERS) version.h
3945
@touch $@
4046

4147
clean:
42-
rm endianness.c opuscomment $(OBJS) 2>/dev/null || :
48+
$(RM) endianness.c opuscomment opuspic2tag $(OBJS) $(OBJP) 2>/dev/null || :

src/opuspic2tag.c

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#include <errno.h>
2+
#include <getopt.h>
3+
#include <limits.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <string.h>
7+
#include <unistd.h>
8+
#include "picture.h"
9+
#include "version.h"
10+
11+
struct option options[] = {
12+
{"help", no_argument, 0, 'h'},
13+
{"desc", required_argument, 0, 'd'},
14+
{"type", required_argument, 0, 't'},
15+
{"output", required_argument, 0, 'o'},
16+
{NULL, 0, 0, 0}
17+
};
18+
19+
int main(int argc, char **argv)
20+
{
21+
if(argc == 1)
22+
{
23+
fprintf(stdout, "opuspic2tag version %s\n", OPUSCOMMENT_VERSION);
24+
fprintf(stdout, "Usage: %s [OPTIONS] FILE{.jpg,.png,.gif}\n", argv[0]);
25+
return EXIT_SUCCESS;
26+
}
27+
char *path_picture = NULL, *picture_data = NULL, *picture_desc = NULL, *path_out = NULL;
28+
const char *error_message;
29+
int print_help = 0;
30+
unsigned long picture_type = 3;
31+
int c;
32+
while((c = getopt_long(argc, argv, "hd:t:o:", options, NULL)) != -1)
33+
{
34+
switch(c){
35+
case 'h':
36+
print_help = 1;
37+
break;
38+
case 'd':
39+
picture_desc = optarg;
40+
break;
41+
case 't':
42+
picture_type = atoi(optarg);
43+
picture_type = (picture_type > 20) ? 3 : picture_type;
44+
break;
45+
case 'o':
46+
path_out = optarg;
47+
break;
48+
default:
49+
return EXIT_FAILURE;
50+
}
51+
}
52+
if(print_help)
53+
{
54+
fprintf(stdout, "opuspic2tag version %s\n", OPUSCOMMENT_VERSION);
55+
fprintf(stdout, "Usage: %s [OPTIONS] FILE{.jpg,.png,.gif}\n", argv[0]);
56+
fprintf(stdout, "Options:\n");
57+
fprintf(stdout, " -h, --help print this help\n");
58+
fprintf(stdout, " -d, --desc STRING description\n");
59+
fprintf(stdout, " -t, --type NUM set image type by 0-20 or keywords. Default: 3\n");
60+
fprintf(stdout, " -o, --output FILE write tag to a file (default=stdout)\n");
61+
fprintf(stdout, "See the man page for extensive documentation.");
62+
return EXIT_SUCCESS;
63+
}
64+
if(optind != argc - 1)
65+
{
66+
fputs("invalid arguments\n", stderr);
67+
return EXIT_FAILURE;
68+
}
69+
path_picture = argv[optind];
70+
if(path_picture != NULL)
71+
{
72+
int seen_file_icons=0;
73+
picture_data = opustags_picture_specification_parse(path_picture, &error_message, picture_desc, picture_type, &seen_file_icons);
74+
if(picture_data == NULL)
75+
{
76+
fprintf(stderr,"Not read picture: %s\n", error_message);
77+
}
78+
}
79+
FILE *out = NULL;
80+
if(path_out != NULL)
81+
{
82+
if(strcmp(path_picture, path_out) == 0)
83+
{
84+
fputs("error: the input and output files are the same\n", stderr);
85+
return EXIT_FAILURE;
86+
}
87+
out = fopen(path_out, "w");
88+
if(!out)
89+
{
90+
perror("fopen");
91+
return EXIT_FAILURE;
92+
}
93+
} else {
94+
out = stdout;
95+
}
96+
if(picture_data != NULL)
97+
{
98+
char *picture_tag = "METADATA_BLOCK_PICTURE";
99+
char *picture_meta = NULL;
100+
int picture_meta_len = strlen(picture_tag) + strlen(picture_data) + 1;
101+
picture_meta = malloc(picture_meta_len);
102+
if(picture_meta == NULL)
103+
{
104+
fprintf(stderr,"Bad picture size: %d\n", picture_meta_len);
105+
free(picture_meta);
106+
} else {
107+
strcpy(picture_meta, picture_tag);
108+
strcat(picture_meta, "=");
109+
strcat(picture_meta, picture_data);
110+
strcat(picture_meta, "\0");
111+
}
112+
fwrite(picture_meta, 1, picture_meta_len, out);
113+
free(picture_meta);
114+
}
115+
if(out)
116+
fclose(out);
117+
return EXIT_SUCCESS;
118+
}

0 commit comments

Comments
 (0)