This patch checks the artist, source and title tags of a file to
detect tune duplications in addition to the rid field.

It has the same effect as the patch put forward by Andrew Reinartz
back in May but I had a look at that and it seemed unnecessarily
complicated.

This should apply cleanly on top of offset-bugfix-libkarma-hg100.patch

Keith.
# HG changeset patch
# User Keith Bennett <[EMAIL PROTECTED]>
# Node ID 56cb49cf38445700d25e650cb0af38f162432bd4
# Parent  974350f4455da1d41197a1abbb2e2874fe738737
Added a check for duplicate files based on artist, source and title

diff -r 974350f4455d -r 56cb49cf3844 src/rio_rw.c
--- a/src/rio_rw.c      Thu Aug 17 10:11:59 2006 +0100
+++ b/src/rio_rw.c      Thu Aug 17 10:12:59 2006 +0100
@@ -46,7 +46,7 @@
 static int get_taxi_props(HASH *p);
 static int get_wave_props(HASH *p, const char *filename);
 static void add_tag(HASH *p, char *key, char *value);
-static void set_tag_props(HASH *p, const char *filename, int type);
+static int set_tag_props(HASH *p, const char *filename, int type);
 static int get_file_type(mp3info *mp3);
 
 int lk_synchronize_necessary(int rio)
@@ -300,8 +300,7 @@
     lk_properties_set_property_hash(p, "artist", NOT_TAGGED);
     lk_properties_set_property_hash(p, "source", NOT_TAGGED);
     
-    set_tag_props(p, filename, TagLib_File_OggVorbis);
-    return 0;
+    return set_tag_props(p, filename, TagLib_File_OggVorbis);
 }
 
 static int get_flac_props(HASH *p, const char *filename)
@@ -317,12 +316,13 @@
 #ifndef TagLib_File_FLAC  /* older tag_c libs don't have TagLib_File_FLAC */
 #define TagLib_File_FLAC -1
 #endif
-    set_tag_props(p, filename, TagLib_File_FLAC);
-    return 0;
+
+    return set_tag_props(p, filename, TagLib_File_FLAC);
 }
 
 static int get_mp3_props(HASH *p, mp3info *mp3)
 {
+    int ret = 0;
     char bitrate[5];
     
     lk_properties_set_property_hash(p, "type", "tune");
@@ -334,7 +334,7 @@
     lk_properties_set_property_hash(p, "artist", NOT_TAGGED);
     lk_properties_set_property_hash(p, "source", NOT_TAGGED);
     
-    set_tag_props(p, mp3->filename, TagLib_File_MPEG);
+    ret = set_tag_props(p, mp3->filename, TagLib_File_MPEG);
     
     if(!mp3->vbr){
         strcpy(bitrate, "fs");
@@ -342,7 +342,7 @@
         lk_properties_set_property_hash(p, "bitrate", bitrate);
     }
     
-    return 0;
+    return ret;
 }
 
 static int get_taxi_props(HASH *p)
@@ -398,13 +398,15 @@
 
 /*** You can use this with all tag-formats, which taglib supports.
   */
-static void set_tag_props(HASH *p, const char *filename, int type)
+static int set_tag_props(HASH *p, const char *filename, int type)
 {
     TagLib_File *tl_file;
     TagLib_Tag *tl_tag;
     const TagLib_AudioProperties * tl_audio;
     int i;
     char bitrate[6];
+    uint32_t *ids;
+    char *title, *source, *artist;
 
     if (type != -1) 
         tl_file = taglib_file_new_type(filename, type);
@@ -412,15 +414,36 @@
         tl_file = taglib_file_new(filename);
     if (! tl_file) {
         lk_errors_set(E_UNSUPTAG);
-        return;
+        return 0;
     }
 
     tl_tag = taglib_file_tag(tl_file);
     tl_audio = taglib_file_audioproperties(tl_file);
 
-    add_tag(p, "title", taglib_tag_title(tl_tag));
-    add_tag(p, "artist", taglib_tag_artist(tl_tag));
-    add_tag(p, "source", taglib_tag_album(tl_tag));
+    title  = taglib_tag_title (tl_tag);
+    source = taglib_tag_album (tl_tag);
+    artist = taglib_tag_artist(tl_tag);
+
+    if (write_dupes == 0) {
+        ids = lk_properties_andOrSearch(EXACT|ORS, NULL, "title", title);
+        if (ids) {
+            ids = lk_properties_andOrSearch(EXACT|ANDS, ids, "source", source);
+            if (ids) {
+                ids = lk_properties_andOrSearch(EXACT|ANDS, ids, "artist",
+                                                artist);
+                if (ids) {
+                    free(ids);
+                    lk_errors_set(E_DUPE);
+                    return -1;
+                }
+            }
+            free(ids);
+        }
+    }
+
+    add_tag(p, "title", title);
+    add_tag(p, "source", source);
+    add_tag(p, "artist", artist);
     add_tag(p, "comment", taglib_tag_comment(tl_tag));
     add_tag(p, "genre", taglib_tag_genre(tl_tag));
 
@@ -448,6 +471,7 @@
 
     taglib_file_free(tl_file);
     /*taglib_tag_free_strings();*/
+    return 0;
 }
 
 static int get_file_type(mp3info *mp3)
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
linux-karma-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-karma-devel

Reply via email to