aboutsummaryrefslogtreecommitdiff
path: root/src/idop.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-07-12 19:55:28 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-07-12 20:02:50 +0300
commit3e010c19412a53b86f251126d427a272224795bd (patch)
tree964e09521ffc3b19fa237a771d32eb14e536caee /src/idop.c
parent725f05ca9a397f2bcbb5303e090e74c8e2b3b901 (diff)
downloadidest-3e010c19412a53b86f251126d427a272224795bd.tar.gz
idest-3e010c19412a53b86f251126d427a272224795bd.tar.bz2
Change ID3 version handling.
* src/cmdline.opt: New option --default-id-version. The --convert and --id-version take version list as their argument. * src/idest.h (IDEST_ID3V_1) (IDEST_ID3V_2): New constants. (default_version_option): New extern. * src/idop.c (set_tags): Don't alter version_option. Unless none of version_option, default_version_option or convert_version is set, preserve existing file structure. Create new tags according to the settings of default_version_option. * src/main.c (main): Set default value for default_version_option. * NEWS: Document changes. * doc/idest.texi: Update.
Diffstat (limited to 'src/idop.c')
-rw-r--r--src/idop.c64
1 files changed, 43 insertions, 21 deletions
diff --git a/src/idop.c b/src/idop.c
index f124986..a906a8c 100644
--- a/src/idop.c
+++ b/src/idop.c
@@ -132,2 +132,15 @@ update_frame(struct id3_tag *tag, const struct ed_item *item)
+static int
+build_tag_options(struct id3_tag *tag, unsigned long location,
+ id3_length_t length, void *data)
+{
+ unsigned int ver = id3_tag_version(tag);
+
+ if (ID3_TAG_VERSION_MAJOR(ver) == 1)
+ *(unsigned int*)data |= IDEST_ID3V_1;
+ else
+ *(unsigned int*)data |= IDEST_ID3V_2;
+ return 0;
+}
+
void
@@ -138,3 +151,4 @@ set_tags(const char *name)
int modified = 0;
-
+ int vopt = version_option;
+
file = id3_file_open(name, ID3_FILE_MODE_READWRITE);
@@ -161,23 +175,30 @@ set_tags(const char *name)
modified |= guile_transform(name, tag);
+
+ if (convert_version == 0) {
+ if (modified && !vopt) {
+ if (id3_file_struct_ntags(file)) {
+ id3_file_struct_iterate(file,
+ build_tag_options,
+ &vopt);
+ } else
+ vopt = default_version_option;
+ }
+ } else if (id3_file_struct_ntags(file)) {
+ id3_file_struct_iterate(file, build_tag_options, &vopt);
+ if (vopt != convert_version) {
+ vopt = convert_version;
+ modified |= 1;
+ }
+ }
- switch (convert_version) {
- case 1:
- id3_tag_options(tag,
- ID3_TAG_OPTION_NO_ID3V2,
- ID3_TAG_OPTION_NO_ID3V2);
- version_option = 1;
- modified |= 1;
- break;
+ if (modified && vopt) {
+ int opts = 0;
- case 2:
- id3_tag_options(tag, ID3_TAG_OPTION_ID3V1, 0);
- version_option = 0;
- modified |= 1;
- break;
- }
-
- if (version_option == 1) {
- id3_tag_options(tag, ID3_TAG_OPTION_ID3V1,
- ID3_TAG_OPTION_ID3V1);
- modified |= 1;
+ if (vopt & IDEST_ID3V_1)
+ opts |= ID3_TAG_OPTION_ID3V1;
+ if (!(vopt & IDEST_ID3V_2))
+ opts |= ID3_TAG_OPTION_NO_ID3V2;
+ id3_tag_options(tag,
+ ID3_TAG_OPTION_ID3V1|ID3_TAG_OPTION_NO_ID3V2,
+ opts);
}
@@ -437,4 +458,5 @@ prinfo(struct id3_tag *tag, unsigned long location,
unsigned int ver = id3_tag_version(tag);
+ unsigned int major = ID3_TAG_VERSION_MAJOR(ver);
printf("version: %u.%u\n",
- ID3_TAG_VERSION_MAJOR(ver),
+ major > 1 ? 20 + major : major,
ID3_TAG_VERSION_MINOR(ver));

Return to:

Send suggestions and report system problems to the System administrator.