Esempio n. 1
0
        protected byte[] GetTrackData(CDDrive cd, Track track)
        {
            uint size = cd.TrackSize(track.Index);
            byte[] buff = new byte[size];
            int x = cd.ReadTrack(track.Index, buff, ref size, null);

            if (buff == null || buff.Length < 1)
                throw new InvalidDataException("TXT_INVALID_TRACK_DATA");

            return buff;
        }
Esempio n. 2
0
 internal void Merge(Track slave)
 {
     if (slave != null)
     {
         Artist = StringUtils.TakeValid(Artist, slave.Artist);
         Title = StringUtils.TakeValid(Title, slave.Title);
         Album = StringUtils.TakeValid(Album, slave.Album);
         Year = StringUtils.TakeValid(Year, slave.Year);
         Genre = StringUtils.TakeValid(Genre, slave.Genre);
         ExtendedData = StringUtils.TakeValid(ExtendedData, slave.ExtendedData);
     }
 }
Esempio n. 3
0
        private StepDetail ProcessTrack(Track track)
        {
            string newFileName = string.Format("{0}.{1}",
                CdRipper.GetFileName(WordCasing.KeepCase, track, OutputFilePattern),
                this.EncoderSettings.AudioMediaFormatType.ToString().ToLowerInvariant());

            StepDetail detail = new StepDetail();
            detail.Description = Translator.Translate("TXT_PROCESSING_TRACK", track, newFileName);
            RaiseTaskStepInitEvent(detail);

            detail.Results = Translator.Translate("TXT_UNHANDLED");
            detail.IsSuccess = false;

            try
            {
                _grabber = CdRipper.CreateGrabber(this.EncoderSettings.AudioMediaFormatType);
                char letter = Drive.RootDirectory.FullName.ToUpperInvariant()[0];
                using (CDDrive cd = new CDDrive())
                {
                    if (cd.Open(letter) && cd.Refresh() && cd.HasAudioTracks())
                    {
                        string destFile = Path.Combine(OutputFolder, newFileName);

                        bool generateTagsFromMetadata = false;

                        switch (this.EncoderSettings.AudioMediaFormatType)
                        {
                            case AudioMediaFormatType.WAV:
                                break;

                            case AudioMediaFormatType.MP3:
                                (_grabber as GrabberToMP3).Mp3ConversionOptions = this.EncoderSettings.Mp3EncoderSettings.Mp3ConversionOptions;
                                generateTagsFromMetadata = this.EncoderSettings.Mp3EncoderSettings.GenerateTagsFromTrackMetadata;
                                break;
                        }

                        _grabber.Grab(cd, track, destFile, generateTagsFromMetadata);
                    }
                }

                detail.IsSuccess = true;
            }
            catch (Exception ex)
            {
                detail.Results = ex.Message;
            }

            return detail;
        }
Esempio n. 4
0
        public static string GetFileName(WordCasing wordCasing, Track track, string renamePattern)
        {
            string newName = renamePattern;
            
            StringUtils.ReplaceToken(ref newName, "<A", track.Artist);
            StringUtils.ReplaceToken(ref newName, "<B", track.Album);
            StringUtils.ReplaceToken(ref newName, "<T", track.Title);
            StringUtils.ReplaceToken(ref newName, "<G", track.Genre);
            StringUtils.ReplaceToken(ref newName, "<#", track.Index.ToString("d2"));
            StringUtils.ReplaceToken(ref newName, "<Y", track.Year);

            newName = StringUtils.StripInvalidPathChars(newName);
            if (!string.IsNullOrEmpty(newName))
            {
                return newName;
            }

            return string.Format("track{0:d2}", track.Index);;
        }
Esempio n. 5
0
        public override void Grab(CDDrive cd, Track track, string destFile, bool generateTags)
        {
            if (MustCancel())
                return;

            byte[] buff = base.GetTrackData(cd, track);

            if (MustCancel())
                return;

            ID3FileInfoSlim ifiSlim = new ID3FileInfoSlim(MediaFileInfo.Empty);
            ifiSlim.Album = track.Album;
            ifiSlim.Artist = track.Artist;
            ifiSlim.Genre = track.Genre;
            ifiSlim.Title = track.Title;
            ifiSlim.Track = (short)track.Index;

            short year = 1900;
            if (short.TryParse(track.Year, out year))
                ifiSlim.Year = year;

            EncodeBuffer(buff, destFile, generateTags, ifiSlim);
        }
Esempio n. 6
0
			public override void Remove(Track value) 
			{
				this._collection.Remove(value);
			}
Esempio n. 7
0
			private void CheckUnique(Track value) 
			{
				if (IndexOf(value) >= 0)
					throw new NotSupportedException(
						"Unique collections cannot contain duplicate elements.");
			}
Esempio n. 8
0
			public override void AddRange(Track[] array) 
			{
				throw new NotSupportedException(
					"Read-only collections cannot be modified.");
			}
Esempio n. 9
0
			public override void AddRange(Track[] array) 
			{
				lock (this._root) this._collection.AddRange(array);
			}
Esempio n. 10
0
		/// <summary>
		/// Searches the entire sorted <see cref="TrackCollection"/> for an
		/// <see cref="Track"/> element using the default comparer
		/// and returns the zero-based index of the element.
		/// </summary>
		/// <param name="value">The <see cref="Track"/> object
		/// to locate in the <see cref="TrackCollection"/>.
		/// This argument can be a null reference.
		/// </param>
		/// <returns>The zero-based index of <paramref name="value"/> in the sorted
		/// <see cref="TrackCollection"/>, if <paramref name="value"/> is found;
		/// otherwise, a negative number, which is the bitwise complement of the index
		/// of the next element that is larger than <paramref name="value"/> or, if there
		/// is no larger element, the bitwise complement of <see cref="Count"/>.</returns>
		/// <exception cref="InvalidOperationException">
		/// Neither <paramref name="value"/> nor the elements of the <see cref="TrackCollection"/>
		/// implement the <see cref="IComparable"/> interface.</exception>
		/// <remarks>Please refer to <see cref="ArrayList.BinarySearch"/> for details.</remarks>

		public virtual int BinarySearch(Track value) 
		{
			return Array.BinarySearch(this._array, 0, this._count, value);
		}
Esempio n. 11
0
      private List<Track> BuildCDTracks(Kernel32.CDROM_TOC_CD_TEXT_DATA Data)
      {
          int numTracks = GetNumTracks();
          if (numTracks == -1)
              return null;

          List<Track> tracks = new List<Track>();

          List<string> titles = new List<string>();
          List<string> artists = new List<string>();
          List<string> genres = new List<string>();

          string item = string.Empty;

          try
          {
              Debug.Write("CD_TEXT info dump BEGIN:");
              for (int i = 0; i < Data.Descriptors.MaxIndex; i++)
              {
                  string line = "";
                  foreach (char c in Data.Descriptors[i].Text)
                  {
                      if (c != '\0')
                          line += c;
                      else
                          line += ".";
                  }

                  Debug.Write(line);
              }
              Debug.Write("CD_TEXT info dump END");

              for (int i = 0; i < Data.Descriptors.MaxIndex; i++)
              {
                  Kernel32.CDROM_TOC_CD_TEXT_DATA_BLOCK cdrom_toc_cd_text_data_block = Data.Descriptors[i];
                  foreach (char ch in cdrom_toc_cd_text_data_block.Text)
                  {
                      if (ch != '\0')
                      {
                          item = item + ch;
                      }
                      else if (!string.IsNullOrEmpty(item))
                      {
                          switch (cdrom_toc_cd_text_data_block.PackType)
                          {
                              case Kernel32.CDROM_CD_TEXT_PACK.ALBUM_NAME:
                                  titles.Add(item);
                                  item = string.Empty;
                                  break;

                              case Kernel32.CDROM_CD_TEXT_PACK.GENRE:
                                  genres.Add(item);
                                  item = string.Empty;
                                  break;

                              case Kernel32.CDROM_CD_TEXT_PACK.PERFORMER:
                                  artists.Add(item);
                                  item = string.Empty;
                                  break;

                              default:
                                  item = string.Empty;
                                  break;
                          }
                      }
                  }
              }

          }
          catch (IndexOutOfRangeException)
          {
          }
          finally
          {
              
          }

          //int max = titles.Count;
          //if (artists.Count != 0 && max > artists.Count)
          //    max = artists.Count;
          //if (genres.Count != 0 && max > genres.Count)
          //    max = genres.Count;

          if (numTracks > 0)
          {
              string mainTitle = (titles.Count > 0) ? titles[0] : null;
              string mainArtist = (artists.Count > 0) ? artists[0] : null;
              string mainGenre = (genres.Count > 0) ? genres[0] : null;

              for (int i = 1; i <= numTracks; i++)
              {
                  Track track = new Track();
                  track.Index = i;

                  try
                  {
                      if (titles.Count > i ||
                          titles.Count > i ||
                          titles.Count > i)
                      {
                          if (titles.Count > i)
                              track.Title = titles[i];
                          if (artists.Count > i)
                              track.Artist = artists[i];
                          if (genres.Count > i)
                              track.Genre = genres[i];

                          if (!string.IsNullOrEmpty(mainTitle))
                          {
                              track.Album = mainTitle;
                          }
                          if (string.IsNullOrEmpty(track.Artist) &&
                              !string.IsNullOrEmpty(mainArtist))
                          {
                              track.Artist = mainArtist;
                          }
                      }
                  }
                  catch { }

                  tracks.Add(track);
              }
          }

          return tracks;
      }
Esempio n. 12
0
			public override void AddRange(Track[] array) 
			{
				foreach (Track value in array)
					CheckUnique(value);
            
				this._collection.AddRange(array);
			}
Esempio n. 13
0
		/// <summary>
		/// Adds a <see cref="Track"/> to the end of the <see cref="TrackCollection"/>.
		/// </summary>
		/// <param name="value">The <see cref="Track"/> object
		/// to be added to the end of the <see cref="TrackCollection"/>.
		/// This argument can be a null reference.
		/// </param>
		/// <returns>The <see cref="TrackCollection"/> index at which the
		/// <paramref name="value"/> has been added.</returns>
		/// <exception cref="NotSupportedException">
		/// <para>The <see cref="TrackCollection"/> is read-only.</para>
		/// <para>-or-</para>
		/// <para>The <b>TrackCollection</b> has a fixed size.</para>
		/// <para>-or-</para>
		/// <para>The <b>TrackCollection</b> already contains the specified
		/// <paramref name="value"/>, and the <b>TrackCollection</b>
		/// ensures that all elements are unique.</para></exception>
		/// <remarks>Please refer to <see cref="ArrayList.Add"/> for details.</remarks>

		public virtual int Add(Track value) 
		{
			if (this._count == this._array.Length)
				EnsureCapacity(this._count + 1);

			++this._version;
			this._array[this._count] = value;
			return this._count++;
		}
Esempio n. 14
0
			public override void Remove(Track value) 
			{
				lock (this._root) this._collection.Remove(value);
			}
Esempio n. 15
0
			public override int Add(Track value) 
			{
				CheckUnique(value);
				return this._collection.Add(value);
			}
Esempio n. 16
0
			public override void Insert(int index, Track value) 
			{
				lock (this._root) this._collection.Insert(index, value);
			}
Esempio n. 17
0
			public override int IndexOf(Track value) 
			{
				lock (this._root) return this._collection.IndexOf(value);
			}
Esempio n. 18
0
			public override void CopyTo(Track[] array) 
			{
				lock (this._root) this._collection.CopyTo(array);
			}
Esempio n. 19
0
			private void CheckUnique(int index, Track value) 
			{
				int existing = IndexOf(value);
				if (existing >= 0 && existing != index)
					throw new NotSupportedException(
						"Unique collections cannot contain duplicate elements.");
			}
Esempio n. 20
0
			public override int BinarySearch(Track value) 
			{
				return this._collection.BinarySearch(value);
			}
Esempio n. 21
0
		/// <summary>
		/// Initializes a new instance of the <see cref="TrackCollection"/> class
		/// that contains elements copied from the specified <see cref="Track"/>
		/// array and that has the same initial capacity as the number of elements copied.
		/// </summary>
		/// <param name="array">An <see cref="Array"/> of <see cref="Track"/>
		/// elements that are copied to the new collection.</param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="array"/> is a null reference.</exception>
		/// <remarks>Please refer to <see cref="ArrayList(ICollection)"/> for details.</remarks>

		public TrackCollection(Track[] array) 
		{
			if (array == null)
				throw new ArgumentNullException("array");

			this._array = new Track[array.Length];
			AddRange(array);
		}
Esempio n. 22
0
			public override void CopyTo(Track[] array) 
			{
				this._collection.CopyTo(array);
			}
Esempio n. 23
0
		/// <summary>
		/// Adds the elements of a <see cref="Track"/> array
		/// to the end of the <see cref="TrackCollection"/>.
		/// </summary>
		/// <param name="array">An <see cref="Array"/> of <see cref="Track"/> elements
		/// that should be added to the end of the <see cref="TrackCollection"/>.</param>
		/// <exception cref="ArgumentNullException">
		/// <paramref name="array"/> is a null reference.</exception>
		/// <exception cref="NotSupportedException">
		/// <para>The <see cref="TrackCollection"/> is read-only.</para>
		/// <para>-or-</para>
		/// <para>The <b>TrackCollection</b> has a fixed size.</para>
		/// <para>-or-</para>
		/// <para>The <b>TrackCollection</b> already contains one or more elements
		/// in the specified <paramref name="array"/>, and the <b>TrackCollection</b>
		/// ensures that all elements are unique.</para></exception>
		/// <remarks>Please refer to <see cref="ArrayList.AddRange"/> for details.</remarks>

		public virtual void AddRange(Track[] array) 
		{
			if (array == null)
				throw new ArgumentNullException("array");

			if (array.Length == 0) return;
			if (this._count + array.Length > this._array.Length)
				EnsureCapacity(this._count + array.Length);

			++this._version;
			Array.Copy(array, 0, this._array, this._count, array.Length);
			this._count += array.Length;
		}
Esempio n. 24
0
			public override void Remove(Track value) 
			{
				throw new NotSupportedException(
					"Read-only collections cannot be modified.");
			}
Esempio n. 25
0
		/// <summary>
		/// Determines whether the <see cref="TrackCollection"/>
		/// contains the specified <see cref="Track"/> element.
		/// </summary>
		/// <param name="value">The <see cref="Track"/> object
		/// to locate in the <see cref="TrackCollection"/>.
		/// This argument can be a null reference.
		/// </param>
		/// <returns><c>true</c> if <paramref name="value"/> is found in the
		/// <see cref="TrackCollection"/>; otherwise, <c>false</c>.</returns>
		/// <remarks>Please refer to <see cref="ArrayList.Contains"/> for details.</remarks>

		public bool Contains(Track value) 
		{
			return (IndexOf(value) >= 0);
		}
Esempio n. 26
0
			public override int IndexOf(Track value) 
			{
				return this._collection.IndexOf(value);
			}
Esempio n. 27
0
			public override void Insert(int index, Track value) 
			{
				throw new NotSupportedException(
					"Read-only collections cannot be modified.");
			}
Esempio n. 28
0
			public override void Insert(int index, Track value) 
			{
				CheckUnique(value);
				this._collection.Insert(index, value);
			}
Esempio n. 29
0
			public override void CopyTo(Track[] array, int arrayIndex) 
			{
				this._collection.CopyTo(array, arrayIndex);
			}
Esempio n. 30
0
			public override int Add(Track value) 
			{
				lock (this._root) return this._collection.Add(value);
			}