1. shuerhaaken
  2. libtaginfo

Commits

shuerhaaken  committed 14073e1

start using is_valid()

  • Participants
  • Parent commits 15bf215
  • Branches master

Comments (0)

Files changed (2)

File libtaginfo/info.cc

View file
  • Ignore whitespace
 
 
 Info * Info::create_tag_info_with_format(const String &filename, MediaFileType format) {
+    Info * info = NULL;
     switch(format) {
         case  MEDIA_FILE_TYPE_UNKNOWN :
-            return new Info(filename, true); // try taglibs guessing as Fallback
+            info = new Info(filename, true);
+            break; // TODO
         case  MEDIA_FILE_TYPE_MP3 :
-            return new Mp3Info(filename);
+            info = new Mp3Info(filename);
+            break;
         case  MEDIA_FILE_TYPE_FLAC :
-            return new FlacInfo(filename);
+            info = new FlacInfo(filename);
+            break;
         case  MEDIA_FILE_TYPE_OGG :
         case  MEDIA_FILE_TYPE_OGA :
-            return new OggInfo(filename);
+            info = new OggInfo(filename);
+            break;
         case  MEDIA_FILE_TYPE_MP4 :
         case  MEDIA_FILE_TYPE_M4A :
         case  MEDIA_FILE_TYPE_M4B :
         case  MEDIA_FILE_TYPE_M4P :
         case  MEDIA_FILE_TYPE_AAC : 
-            return new Mp4Info(filename);
+            info = new Mp4Info(filename);
+            break;
         case  MEDIA_FILE_TYPE_WMA :
         case  MEDIA_FILE_TYPE_WMV :
         case  MEDIA_FILE_TYPE_ASF :
-            return new ASFInfo(filename);
+            info = new ASFInfo(filename);
+            break;
         case MEDIA_FILE_TYPE_APE :
-            return new ApeInfo(filename);
+            info = new ApeInfo(filename);
+            break;
         case MEDIA_FILE_TYPE_WAV :
-            return new WaveInfo(filename);
+            info = new WaveInfo(filename);
+            break;
         case MEDIA_FILE_TYPE_AIF :
-            return new AiffInfo(filename);
+            info = new AiffInfo(filename);
+            break;
         case MEDIA_FILE_TYPE_WV : 
-            return new WavPackInfo(filename);
+            info = new WavPackInfo(filename);
+            break;
         case MEDIA_FILE_TYPE_TTA :
-            return new TrueAudioInfo(filename);
+            info = new TrueAudioInfo(filename);
+            break;
         case MEDIA_FILE_TYPE_MPC :
-            return new MpcInfo(filename);
+            info = new MpcInfo(filename);
+            break;
         case MEDIA_FILE_TYPE_SPEEX :
-            return new SpeexInfo(filename);
+            info = new SpeexInfo(filename);
+            break;
         default :
             break;
     }
-    return NULL;
+    if(!info || !info->is_valid()) {
+        std::cout << "NOT valid OR unrecognized: " << filename << std::endl;
+        return NULL;
+    }
+    return info;
 }
 
 Info * Info::create_tag_info(const String &filename) {
     is_compilation = false;
     has_image = false;
     
+    valid = true; //TODO
+    
     changedflag = CHANGED_DATA_NONE;
     
     if(create_own_fileref) {
             printf("Error creating file ref! %s\n", filename.toCString(false));
         if(taglib_fileref && !taglib_fileref->isNull()) {
             taglib_file = taglib_fileref->file();
+            if(!taglib_file) {
+                printf("Cant get tag object from '%s'\n", file_name.toCString(false));
+                delete taglib_fileref;
+                taglib_fileref = NULL;
+                taglib_file    = NULL;
+                taglib_tag     = NULL;
+                valid = false;
+            }
             taglib_tag = taglib_file->tag();
-            if(!taglib_tag) {
+            valid = true;
+            if(!taglib_tag || taglib_tag) {
                 printf("Cant get tag object from '%s'\n", file_name.toCString(false));
                 delete taglib_fileref;
                 taglib_fileref = NULL;
                 taglib_file    = NULL;
                 taglib_tag     = NULL;
+                valid = false;
             }
         }
         else {
             taglib_fileref = NULL;
             taglib_file    = NULL;
             taglib_tag     = NULL;
+            valid = false;
         }
     }
 }
         delete taglib_file;
 }
 
+bool Info::is_valid() {
+    return valid;
+}
 
 void Info::set_file_name(const String &filename) {
     file_name = filename;

File libtaginfo/taginfo.h

View file
  • Ignore whitespace
             
             int changedflag;
             bool has_image;
+            bool valid;
             
             
             void set_file_name(const String &filename);
             //General stuff
             String get_file_name(void);
             
+            bool is_valid();
+            
             //Tag access functions
             String get_title(void) const;
             void   set_title(String new_title);