shuerhaaken avatar shuerhaaken committed 72566ed

handle rating and playcount

Comments (0)

Files changed (17)

+commit 3824453c6a26c12c94f298dffbdaa93135699da9
+Author: Jörn Magens <shuerhaaken@googlemail.com>
+Date:   Thu Mar 21 14:20:14 2013 +0100
+
+    extend tests
+
 commit 4f21707e613cebc8039a2b05fe39f17936b22ed6
 Author: Jörn Magens <shuerhaaken@googlemail.com>
 Date:   Thu Mar 21 13:59:31 2013 +0100

libtaginfo/aiffinfo.cc

 }
 
 
-
-
 bool AiffInfo::write(void) {
     if(taglib_tag) {
         if(changedflag) {
 
 
 bool AiffInfo::can_handle_images(void) const {
-    return false;
+    return false; //TODO
 }
 
 bool AiffInfo::get_image(char*& data, int &data_length, ImageType &image_type) const {

libtaginfo/apeinfo.cc

                 }
             }
             if(taglib_apetag->itemListMap().contains(APE_TAG_PLAYCNT)) {
-                long PlayCount = 0;
-                PlayCount = atol(taglib_apetag->itemListMap()[APE_TAG_PLAYCNT].toStringList().front().toCString(true));
-                playcount = PlayCount;
+                playcount = 
+                    atol(taglib_apetag->itemListMap()[APE_TAG_PLAYCNT].toStringList().front().toCString(false));
+                if(playcount < 0)
+                    playcount = 0;
             }
             // Labels
             if(track_labels.size() == 0) {
             
             if(changedflag & CHANGED_DATA_RATING) {
                 taglib_apetag->addValue(APE_TAG_RATING, format("%u", rating_to_popularity(rating)));
-                taglib_apetag->addValue("PLAY_COUNTER", format("%u", playcount)); // TODO
+            }
+            if(changedflag & CHANGED_DATA_PLAYCOUNT) {
+                taglib_apetag->addValue("PLAY_COUNTER", format("%u", playcount));
             }
             if(changedflag & CHANGED_TRACK_LABELS)
                 check_ape_label_frame(taglib_apetag, "TRACK_LABELS",  track_labels_string);

libtaginfo/asfinfo.cc

             if(changedflag & CHANGED_DATA_RATING) {
                 asf_tag->removeItem("WM/SharedUserRating");
                 int WMRatings[] = { 0, 0, 1, 25, 50, 75, 99 };
-                
                 asf_tag->setAttribute("WM/SharedUserRating", format("%i", WMRatings[ rating + 1 ]));
             }
             // The Labels

libtaginfo/flacinfo.cc

                 }
             }
             if(xiphcomment->fieldListMap().contains("PLAY_COUNTER")) {
-                long playcnt = 0;
-                playcnt = atol(xiphcomment->fieldListMap()["PLAY_COUNTER"].front().toCString(false));
-                playcount = playcnt;
+                playcount = atol(xiphcomment->fieldListMap()["PLAY_COUNTER"].front().toCString(false));
+                if(playcount < 0)
+                    playcount = 0;
             }
             // Labels
             if(track_labels.size() == 0) {
             
             if(changedflag & CHANGED_DATA_RATING) {
                 xiphcomment->addField("RATING", format("%u", rating_to_popularity(rating)));
+            }
+            if(changedflag & CHANGED_DATA_PLAYCOUNT) {
                 xiphcomment->addField("PLAY_COUNTER", format("%u", playcount));
             }
             // The Labels

libtaginfo/info.cc

 
 void Info::set_disk_number(int number) {
     disk_number = number;
+    if(disk_number < 0)
+        disk_number = 0;
     changedflag |= CHANGED_DATA_DISK_NUM;
 }
 int Info::get_disk_number() const {
     return length_seconds;
 }
 
+int  Info::get_playcount() const {
+    return playcount;
+}
+void Info::set_playcount(int new_playcount) {
+    changedflag |= CHANGED_DATA_PLAYCOUNT;
+    playcount = new_playcount;
+    if(playcount < 0)
+        playcount = 0;
+}
+
+int  Info::get_rating() const {
+    return rating;
+}
+void Info::set_rating(int new_rating) {
+    changedflag |= CHANGED_DATA_RATING;
+    rating = new_rating;
+    if(rating < 0)
+        rating = 0;
+}
+
 void Info::set_track_labels_list(const StringList &new_track_labels_list) {
     track_labels = new_track_labels_list;
     track_labels_string = new_track_labels_list.toString("|");

libtaginfo/mp3info.cc

                 taglib_tagId3v2->removeFrames("TRCK");
                 taglib_tagId3v2->setTrack(tracknumber);
             }
+            TagLib::ID3v2::PopularimeterFrame * popularity_frame;
             if(changedflag & CHANGED_DATA_RATING) {
-                printf("Writing ratings and playcount...\n");
-                TagLib::ID3v2::PopularimeterFrame * popularity_frame = get_popularity_frame(taglib_tagId3v2, "LibTagInfo");
+                popularity_frame = get_popularity_frame(taglib_tagId3v2, "LibTagInfo");
                 if(!popularity_frame) {
                     popularity_frame = new TagLib::ID3v2::PopularimeterFrame();
                     taglib_tagId3v2->addFrame(popularity_frame);
                     popularity_frame->setEmail("LibTagInfo");
                 }
-                popularity_frame->setRating(rating_to_popularity(rating));
-                popularity_frame->setCounter(playcount);
+                if(popularity_frame)
+                    popularity_frame->setRating(rating_to_popularity(rating));
+            }
+            if(changedflag & CHANGED_DATA_PLAYCOUNT) {
+                if(!popularity_frame)
+                    popularity_frame = get_popularity_frame(taglib_tagId3v2, "LibTagInfo");
+                if(!popularity_frame) {
+                    popularity_frame = new TagLib::ID3v2::PopularimeterFrame();
+                    taglib_tagId3v2->addFrame(popularity_frame);
+                    popularity_frame->setEmail("LibTagInfo");
+                }
+                if(popularity_frame)
+                    popularity_frame->setCounter(playcount);
             }
             
             // The Labels

libtaginfo/mp4info.cc

                 mp4_tag->itemListMap()["----:com.apple.iTunes:RATING" ] =
                     TagLib::MP4::Item(format("%u", rating_to_popularity(rating)));
                 
+            }
+            if(changedflag & CHANGED_DATA_PLAYCOUNT) {
                 mp4_tag->itemListMap()[ "----:com.apple.iTunes:PLAY_COUNTER" ] =
                     TagLib::MP4::Item(format("%u", playcount));
             }

libtaginfo/mpcinfo.cc

             }
             // Rating
             if(taglib_apetag->itemListMap().contains("RATING")) {
-                long rat = 0;
-                rat = atol(taglib_apetag->itemListMap()["RATING"].toStringList().front().toCString(true));
+                long rat = atol(taglib_apetag->itemListMap()["RATING"].toStringList().front().toCString(true));
                 if(rat) {
                     if(rat > 5) {
                         rating = popularity_to_rating(rat);
                 }
             }
             if(taglib_apetag->itemListMap().contains("PLAY_COUNTER")) {
-                long PlayCount = 0;
-                PlayCount = atol(taglib_apetag->itemListMap()["PLAY_COUNTER"].toStringList().front().toCString(true));
-                playcount = PlayCount;
+                playcount = atol(taglib_apetag->itemListMap()["PLAY_COUNTER"].toStringList().front().toCString(true));
+                if(playcount < 0)
+                    playcount = 0;
             }
             // Labels
             if(track_labels.size() == 0) {
             
             if(changedflag & CHANGED_DATA_RATING) {
                 taglib_apetag->addValue("RATING", format("%u", rating_to_popularity(rating))); // TODO
+            }
+            if(changedflag & CHANGED_DATA_PLAYCOUNT) {
                 taglib_apetag->addValue("PLAY_COUNTER", format("%u", playcount));
             }
             // Labels

libtaginfo/ogginfo.cc

             
             if(changedflag & CHANGED_DATA_RATING) {
                 xiphcomment->addField("RATING", format("%u", rating_to_popularity(rating)));
+            }
+            if(changedflag & CHANGED_DATA_PLAYCOUNT) {
                 xiphcomment->addField("PLAY_COUNTER", format("%u", playcount));
             }
             // The Labels

libtaginfo/speexinfo.cc

             
             if(changedflag & CHANGED_DATA_RATING) {
                 xiphcomment->addField("RATING", format("%u", rating_to_popularity(rating)));
+            }
+            if(changedflag & CHANGED_DATA_PLAYCOUNT) {
                 xiphcomment->addField("PLAY_COUNTER", format("%u", playcount));
             }
             // The Labels

libtaginfo/taginfo.h

         MEDIA_FILE_TYPE_WMV
     };
     
-    
-    enum ChangedData {
-        CHANGED_DATA_NONE          = 0,
-        CHANGED_ARTIST_TAG         = (1 << 0),
-        CHANGED_ALBUM_TAG          = (1 << 1),
-        CHANGED_TITLE_TAG          = (1 << 2),
-        CHANGED_GENRE_TAG          = (1 << 3),
-        CHANGED_COMMENT_TAG        = (1 << 4),
-        CHANGED_TRACKNO_TAG        = (1 << 5),
-        CHANGED_YEAR_TAG           = (1 << 6),
-        CHANGED_DATA_ALBUMARTIST   = (1 << 7),
-        CHANGED_DATA_DISK_NUM      = (1 << 8),
-        CHANGED_DATA_IMAGES        = (1 << 9),
-        CHANGED_DATA_LYRICS        = (1 << 10),
-        CHANGED_DATA_RATING        = (1 << 11),
-        CHANGED_COMPOSER_TAG       = (1 << 12),
-        CHANGED_TRACK_LABELS       = (1 << 13),
-        CHANGED_ARTIST_LABELS      = (1 << 14),
-        CHANGED_ALBUM_LABELS       = (1 << 15),
-        CHANGED_IS_COMPILATION_TAG = (1 << 16)
-    };
-    
-    
     enum ImageType {
         IMAGE_TYPE_UNKNOWN,
         IMAGE_TYPE_JPEG,
             //Extra
             int  get_playcount() const;
             void set_playcount(int new_playcount);
+            
+            /*rating 1 - 5 ;  0 -> not set*/
             int  get_rating() const;
             void set_rating(int new_rating);
             

libtaginfo/taginfo_internal.h

 using namespace TagInfo;
 
 
+
+
+
+namespace TagInfo {
+
+    enum ChangedData {
+        CHANGED_DATA_NONE          = 0,
+        CHANGED_ARTIST_TAG         = (1 << 0),
+        CHANGED_ALBUM_TAG          = (1 << 1),
+        CHANGED_TITLE_TAG          = (1 << 2),
+        CHANGED_GENRE_TAG          = (1 << 3),
+        CHANGED_COMMENT_TAG        = (1 << 4),
+        CHANGED_TRACKNO_TAG        = (1 << 5),
+        CHANGED_YEAR_TAG           = (1 << 6),
+        CHANGED_DATA_ALBUMARTIST   = (1 << 7),
+        CHANGED_DATA_DISK_NUM      = (1 << 8),
+        CHANGED_DATA_IMAGES        = (1 << 9),
+        CHANGED_DATA_LYRICS        = (1 << 10),
+        CHANGED_DATA_RATING        = (1 << 11),
+        CHANGED_DATA_PLAYCOUNT     = (1 << 12),
+        CHANGED_COMPOSER_TAG       = (1 << 13),
+        CHANGED_TRACK_LABELS       = (1 << 14),
+        CHANGED_ARTIST_LABELS      = (1 << 15),
+        CHANGED_ALBUM_LABELS       = (1 << 16),
+        CHANGED_IS_COMPILATION_TAG = (1 << 17)
+    };
+}
+
+
 inline StringList split(const String str, const String &separator) {
     return StringList::split(str, separator);
 }

libtaginfo/trueaudioinfo.cc

                 taglib_tagId3v2->removeFrames("TRCK");
                 taglib_tagId3v2->setTrack(tracknumber);
             }
+            TagLib::ID3v2::PopularimeterFrame * popularity_frame;
             if(changedflag & CHANGED_DATA_RATING) {
-                printf("Writing ratings and playcount...\n");
-                TagLib::ID3v2::PopularimeterFrame * popularity_frame = 
+                popularity_frame = 
                     get_popularity_frame(taglib_tagId3v2, "LibTagInfo");
                 if(!popularity_frame) {
                     popularity_frame = new TagLib::ID3v2::PopularimeterFrame();
                     taglib_tagId3v2->addFrame(popularity_frame);
                     popularity_frame->setEmail("LibTagInfo");
                 }
-                popularity_frame->setRating(rating_to_popularity(rating));
-                popularity_frame->setCounter(playcount);
+                if(popularity_frame)
+                    popularity_frame->setRating(rating_to_popularity(rating));
+            }
+            if(changedflag & CHANGED_DATA_PLAYCOUNT) {
+                if(!popularity_frame)
+                    popularity_frame = get_popularity_frame(taglib_tagId3v2, "LibTagInfo");
+                if(!popularity_frame) {
+                    popularity_frame = new TagLib::ID3v2::PopularimeterFrame();
+                    taglib_tagId3v2->addFrame(popularity_frame);
+                    popularity_frame->setEmail("LibTagInfo");
+                }
+                if(popularity_frame)
+                    popularity_frame->setCounter(playcount);
             }
             
             // The Labels

libtaginfo/waveinfo.cc

                 taglib_tagId3v2->removeFrames("TRCK");
                 taglib_tagId3v2->setTrack(tracknumber);
             }
+            TagLib::ID3v2::PopularimeterFrame * popularity_frame;
             if(changedflag & CHANGED_DATA_RATING) {
-                printf("Writing ratings and playcount...\n");
-                TagLib::ID3v2::PopularimeterFrame * popularity_frame = get_popularity_frame(taglib_tagId3v2, "LibTagInfo");
+                popularity_frame = get_popularity_frame(taglib_tagId3v2, "LibTagInfo");
                 if(!popularity_frame) {
                     popularity_frame = new TagLib::ID3v2::PopularimeterFrame();
                     taglib_tagId3v2->addFrame(popularity_frame);
                     popularity_frame->setEmail("LibTagInfo");
                 }
-                popularity_frame->setRating(rating_to_popularity(rating));
-                popularity_frame->setCounter(playcount);
+                if(popularity_frame)
+                    popularity_frame->setRating(rating_to_popularity(rating));
+            }
+            if(changedflag & CHANGED_DATA_PLAYCOUNT) {
+                if(!popularity_frame)
+                    popularity_frame = get_popularity_frame(taglib_tagId3v2, "LibTagInfo");
+                if(!popularity_frame) {
+                    popularity_frame = new TagLib::ID3v2::PopularimeterFrame();
+                    taglib_tagId3v2->addFrame(popularity_frame);
+                    popularity_frame->setEmail("LibTagInfo");
+                }
+                if(popularity_frame)
+                    popularity_frame->setCounter(playcount);
             }
             
             // The Labels

libtaginfo/wavpackinfo.cc

                 taglib_apetag->addValue("ALBUM ARTIST", album_artist);
             if(changedflag & CHANGED_DATA_RATING) {
                 taglib_apetag->addValue("RATING", format("%u", rating_to_popularity(rating)));
+            }
+            if(changedflag & CHANGED_DATA_PLAYCOUNT) {
                 taglib_apetag->addValue("PLAY_COUNTER", format("%u", playcount));
             }
             // The Labels

tests/write_ogg/main.cc

     StringList labels = StringList();
     labels.append("user label1 äöüé");
     labels.append("user label1 äiiüé");
-    
     if( info ) {
         info->set_title(TESTNAME);
         info->set_album_artist("äöé");
         info->set_is_compilation(true);
         info->set_track_labels_list(labels);
         info->set_comments("Cömmmééèntß");
+        info->set_rating(2);
+        info->set_playcount(86);
         info->set_year(1978);
         info->write();
     }
             if(info->get_title() == TESTNAME &&
                info->get_album_artist() == "äöé" &&
                info->get_year() == 1978 &&
+               info->get_rating() == 2 &&
+               info->get_playcount() == 86 &&
                info->get_comments() == "Cömmmééèntß" &&
                info->get_is_compilation() == true &&
                check_list_equal(info->get_track_labels_list(), labels) ) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.