コード例 #1
0
ファイル: MP3DataMgr.cs プロジェクト: Kostarsus/MP3Manager
 /// <summary>
 /// This method inserts a new tile row
 /// </summary>
 /// <param name="mp3Info">
 /// The data to insert
 /// </param>
 /// <param name="interpretRow">
 /// The referenced interpret row
 /// </param>
 /// <param name="albumRow">
 /// The referenced album row
 /// </param>
 /// <returns>
 /// The inserted title row if the insertion was successfull, null else
 /// </returns>
 private Title InsertTitle(WMP3FileInfo mp3Info, Interpret interpretRow, Album albumRow)
 {
     if (mp3Info == null)
     {
         throw new ArgumentException("mp3Info == null");
     }
     if (interpretRow == null)
     {
         throw new ArgumentException("interpretRow == null");
     }
     if (albumRow == null)
     {
         throw new ArgumentException("albumRow == null");
     }
     if (String.IsNullOrWhiteSpace(mp3Info.Title))
     {
         throw new ArgumentException("Title null or empty");
     }
     log.DebugFormat("InsertTitle: tile={0}", mp3Info.Title);
     Title titleRow = null;
     long start = DateTime.Now.Ticks;
     using (var context = new MP3ManagerContext())
     {
         string normalizedName = CreateSearchname(mp3Info.Title);
         titleRow = context.Titles.Add(new Title()
          {
              Interpret = interpretRow,
              Album = albumRow,
              Name = mp3Info.Title,
              Length = mp3Info.Songlength,
              Bitrate = mp3Info.BitRate,
              Bytes = mp3Info.Bytes,
              Path = mp3Info.Path,
              Filename = mp3Info.Filename,
              Searchname = normalizedName,
              Track = mp3Info.Track,
              CreationDate = DateTime.Now,
              EditDate = mp3Info.EditDate,
              IsOrdered = false,
              IsCollection = false,
              DurationInSeconds = mp3Info.DurationInSeconds,
              Genre = mp3Info.Genre,
              PublicationYear = mp3Info.PublicationYear,
              SampleRate = mp3Info.SampleRate,
              Channels = mp3Info.Channels
          });
         context.SaveChanges();
         return titleRow;
     }
 }
コード例 #2
0
ファイル: MP3DataMgr.cs プロジェクト: Kostarsus/MP3Manager
        /// <summary>
        /// This method inserts a new interpret-row
        /// </summary>
        /// <param name="mp3Info">
        /// The data of  the interpeet-row
        /// </param>
        /// <returns>
        /// The new Row if the insertion was successfull, null else
        /// </returns>
        private Interpret insertInterpret(WMP3FileInfo mp3Info)
        {
            if (mp3Info == null)
            {
                throw new ArgumentException("mp3Info == null");
            }
            if (String.IsNullOrWhiteSpace(mp3Info.Interpret))
            {
                mp3Info.Interpret = WMP3FileInfo.UNKNOWN_INTERPRET;
            }

            log.DebugFormat("InsertInterpret: interpret={0}", mp3Info.Interpret);
            string normalizedName = CreateSearchname(mp3Info.Interpret);
            var interpretRow = FindArtist(normalizedName);
            if (interpretRow == null)
            {
                log.Debug("Insert new Interpret");
                using (var context= new MP3ManagerContext())
                {
                    interpretRow = context.Interprets.Add(new Interpret()
                        {
                            Name=mp3Info.Interpret,
                            Searchname = normalizedName
                        });
                    context.SaveChanges();
                }
            }
            return interpretRow;
        }
コード例 #3
0
ファイル: MP3DataMgr.cs プロジェクト: Kostarsus/MP3Manager
        /// <summary>
        /// This method inserts a new row in the album table
        /// </summary>
        /// <param name="mp3Info">
        /// The datato insert
        /// </param>
        /// <param name="interpretRow">
        /// The referenced interpretRow
        /// </param>
        /// <returns>
        /// The new albumrrow if the innsertion was successfull, null else
        /// </returns>
        private Album InsertAlbum(WMP3FileInfo mp3Info)
        {
            if (mp3Info == null)
            {
                throw new ArgumentException("mp3Info == null");
            }
            if (String.IsNullOrWhiteSpace(mp3Info.Album))
            {
                mp3Info.Album = WMP3FileInfo.UNKNOWN_ALBUM;
            }

            log.DebugFormat("InsertAlbum: albumname={0}", mp3Info.Album);
            string normalizedName = CreateSearchname(mp3Info.Album);
            var albumRow = FindAlbum(normalizedName);
            if (albumRow == null)
            {
                log.Debug("Insert new Album");
                using (var context = new MP3ManagerContext())
                {
                        albumRow = context.Albums.Add(new Album()
                        {
                            Name = mp3Info.Album, 
                            Searchname = normalizedName, 
                            InformationStatus = InformationDownloadStatus.NotStarted
                        });
                        context.SaveChanges();
                 }
            }
            return albumRow;
        }
コード例 #4
0
        /// <summary>
        /// Reads the ID3-Tag Information and merges it with the physical file info
        /// </summary>
        /// <param name="fileInfo">
        /// The physical file info
        /// </param>
        /// <returns>
        /// A wrapper which includes the physical file info and theD3-Tag informations
        /// </returns>
        public WMP3FileInfo readFile(WFileInfo fileInfo)
        {
            if (fileInfo==null)
                throw new ArgumentNullException("fileInfo");
            string fullFilename = fileInfo.Path + fileInfo.Filename;
            TagLib.File file = null;
            try
            {
                file = TagLib.File.Create(new TagLibFileAbstraction(fullFilename));
            }
            catch (TagLib.UnsupportedFormatException)
            {                
                new System.IO.IOException("UNSUPPORTED FILE: " + fullFilename);
            }

            //Fill the return value
            WMP3FileInfo retValue = new WMP3FileInfo(fileInfo);
            foreach(var codec in file.Properties.Codecs)
            {
                TagLib.IAudioCodec acodec = codec as TagLib.IAudioCodec;
                if (acodec != null && (acodec.MediaTypes & TagLib.MediaTypes.Audio) != TagLib.MediaTypes.None)
                {
                    retValue.BitRate = acodec.AudioBitrate;
                    retValue.Songlength = acodec.Duration != null ? convertTime(Convert.ToInt32(acodec.Duration.TotalSeconds)) :  convertTime(0);
                    retValue.DurationInSeconds = acodec.Duration != null ? Convert.ToInt32(acodec.Duration.TotalSeconds) : 0;
                    retValue.Channels = acodec.AudioChannels;
                    retValue.SampleRate = acodec.AudioSampleRate;
                }
            }

            retValue.Genre = (file.Tag.Genres != null && file.Tag.Genres.Length > 0) ? file.Tag.Genres[0] : string.Empty;
            retValue.PublicationYear = (int)file.Tag.Year;
            retValue.Album = NormaliseName(file.Tag.Album);
            retValue.Interpret = NormaliseName(file.Tag.FirstPerformer);
            retValue.Title = file.Tag.Title;
            retValue.Track = (int)file.Tag.Track;
            return retValue;
        }