public static int Main( string [] args ) { int verbosity = 0; bool noMoreOptions = false; bool doListAction = false; ArrayList fileList = new ArrayList(); foreach (string arg in args) { if (noMoreOptions) { fileList.Add( arg ); } else { switch (arg) { case "-v": case "--verbose": ++ verbosity; break; case "-l": case "--list": doListAction = true; break; default: fileList.Add( arg ); break; } } } // Dump trace output if verbose if (verbosity > 0) { Trace.Listeners.Add( new TextWriterTraceListener(Console.Out) ); Trace.AutoFlush = true; } foreach (string file in fileList) { ID3v2 tag = null; try { bool dumpDebugInfo = false; if (verbosity > 2) dumpDebugInfo = true; tag = new ID3v2( file, dumpDebugInfo ); ID3v2Header header = tag.header; if (header == null) { Console.WriteLine( "File: {0}", file ); Console.WriteLine( "No ID3v2 header found" ); continue; // ** Next File Please ** } } catch (Exception e) { Console.WriteLine( "File: {0}", file ); Console.WriteLine( e.ToString() ); return 1; } if (verbosity > 0) { Console.WriteLine( "File: {0}", file ); Console.WriteLine( "Found Tag: ID3v2.{0}", tag.header.version ); } if (verbosity > 1) { Console.WriteLine( "Size: {0}", tag.header.size ); Console.WriteLine( "IsUnsynchronized: {0}", tag.header.isUnsynchronized ); Console.WriteLine( "HasExtHeader: {0}", tag.header.hasExtendedHeader ); Console.WriteLine( "IsExperimental: {0}", tag.header.isExperimental ); Console.WriteLine( "HasFooter: {0}", tag.header.hasFooter ); } if (verbosity > 0) { if (tag.tit2 != null) Console.WriteLine( "TIT2: {0}", tag.tit2 ); if (tag.tpe1 != null) Console.WriteLine( "TPE1: {0}", tag.tpe1 ); if (tag.trck != null) Console.WriteLine( "TRCK: {0}", tag.trck ); if (tag.comm != null) Console.WriteLine( "TCON: {0}", tag.comm ); if (tag.comm != null) Console.WriteLine( "TYER: {0}", tag.tyer ); if (tag.tcon != null) Console.WriteLine( "TCON: {0}", tag.tcon ); if (tag.mcdi != null) Console.WriteLine( "MCDI found (what do I do with it?)" ); if (tag.trackIndex > 0) Console.WriteLine( "Index: {0}", tag.trackIndex ); if (tag.trackCount > 0) Console.WriteLine( "TrackCount: {0}", tag.trackCount ); } } return 0; }
/// /// Updates the database info for a file. Assumes the file is an /// MP3 file. /// /// \todo Create a pluggable interface to extract the file info /// from various file types, not just mp3 /// void _UpdateMP3FileInfo( string path, IBackend engine ) { // Get ID3 tags from the file ID3v2 tag = new ID3v2( path, false ); if (!tag.isValid) { _Trace( "Note: No id3v2 tag found in file: '" + path + "'" ); return; } if ((null == tag.tit2) || (tag.tit2.Length == 0)) { // Match anything after the last forward/backslash string basename = Path.GetFileName( path ); Debug.Assert( null != basename, "All files have names!" ); Debug.Assert( basename.Length > 0, "All files have names!" ); _Trace( "Song title is empty, using file name: '" + basename + "'" ); tag.tit2 = basename; } string genre = tag.DefaultGenre; if (null == genre) genre = "unknown"; if (engine.EntryExists( path )) { engine.FileIsNotMissing( path ); } else { // Oh god, the noise, the noise! Just comment when something interesting // heppens, OK? // _Trace( "adding '" + path + "'" ); PlayableData data = new PlayableData(); data.filePath = path; if (tag.tpe1 == null) data.artist = ""; else data.artist = tag.tpe1; if (tag.talb == null) data.album = ""; else data.album = tag.talb; if (tag.tit2 == null) // no title, maybe check tit1 and tit3? data.title = ""; else data.title = tag.tit2; data.track = tag.trackIndex; data.genre = genre; data.lengthInSeconds = 0; // unknown, ID3 tag doesn't know engine.Add( data ); } }