Пример #1
0
        /// <summary>
        ///   Add the Track to the Conversion Grid
        /// </summary>
        /// <param name = "track"></param>
        public void AddToConvert(TrackData track)
        {
            if (track == null)
            {
                return;
            }

            ConversionData convdata = new ConversionData();

            convdata.Track = track;

            bindingList.Add(convdata);
        }
        /// <summary>
        ///   Add the Track to the Conversion Grid
        /// </summary>
        /// <param name = "track"></param>
        public void AddToConvert(TrackData track)
        {
            if (track == null)
            return;

              ConversionData convdata = new ConversionData();
              convdata.Track = track;

              bindingList.Add(convdata);
        }
Пример #3
0
 public CmdConvert(object[] parameters)
 {
     _conversionData = (ConversionData)parameters[1];
 }
Пример #4
0
        private void ConversionThread()
        {
            if (_main.InvokeRequired)
            {
                ThreadSafeConvertDelegate d = ConversionThread;
                _main.Invoke(d);
                return;
            }

            log.Trace(">>>");
            string rootFolder = _main.EncoderOutputDirectory;

            if (string.IsNullOrEmpty(rootFolder))
            {
                rootFolder = Options.MainSettings.RipTargetFolder;
            }

            string encoder = null;

            if (_main.EncoderCombo.SelectedItem != null)
            {
                encoder = (string)(_main.EncoderCombo.SelectedItem as Item).Value;
            }

            if (encoder == null)
            {
                return;
            }

            try
            {
                if (!Directory.Exists(rootFolder) && !string.IsNullOrEmpty(rootFolder))
                {
                    Directory.CreateDirectory(rootFolder);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(localisation.ToString("Conversion", "ErrorDirectory"), localisation.ToString("message", "Error_Title"), MessageBoxButtons.OK);
                log.Error("Error creating Conversion output directory: {0}. {1}", rootFolder, ex.Message);
                return;
            }

            foreach (DataGridViewRow row in dataGridViewConvert.Rows)
            {
                // Reset the Status field to 0
                row.Cells[0].Value = 0;
            }

            _currentRow = -1;
            foreach (DataGridViewRow row in dataGridViewConvert.Rows)
            {
                _currentRow = row.Index;

                ConversionData track = bindingList[_currentRow];

                string inputFile = track.Track.FullFileName;
                string outFile   = Util.ReplaceParametersWithTrackValues(Options.MainSettings.RipFileNameFormat, track.Track);
                outFile = Path.Combine(rootFolder, outFile);
                string directoryName = Path.GetDirectoryName(outFile);

                // Now check the validity of the directory
                if (!Directory.Exists(directoryName))
                {
                    try
                    {
                        Directory.CreateDirectory(directoryName);
                    }
                    catch (Exception e1)
                    {
                        log.Error("Error creating folder: {0} {1]", directoryName, e1.Message);
                        row.Cells[0].Value       = localisation.ToString("message", "Error");
                        row.Cells[0].ToolTipText = String.Format("{0}: {1}", localisation.ToString("message", "Error"), e1.Message);
                        continue; // Process next row
                    }
                }

                outFile = audioEncoder.SetEncoder(encoder, outFile);
                UpdateNewFileName(outFile);

                if (inputFile == outFile)
                {
                    row.Cells[0].ToolTipText = String.Format("{0}: {1}", inputFile, localisation.ToString("Conversion", "SameFile"));
                    log.Error("No conversion for {0}. Output would overwrite input", inputFile);
                    continue;
                }

                int stream = Bass.BASS_StreamCreateFile(inputFile, 0, 0, BASSFlag.BASS_STREAM_DECODE);
                if (stream == 0)
                {
                    row.Cells[0].ToolTipText = String.Format("{0}: {1}", inputFile, localisation.ToString("Conversion", "OpenFileError"));
                    log.Error("Error creating stream for file {0}. Error: {1}", inputFile,
                              Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
                    continue;
                }

                log.Info("Convert file {0} -> {1}", inputFile, outFile);

                if (audioEncoder.StartEncoding(stream) != BASSError.BASS_OK)
                {
                    row.Cells[0].ToolTipText = String.Format("{0}: {1}", inputFile, localisation.ToString("Conversion", "EncodingFileError"));
                    log.Error("Error starting Encoder for File {0}. Error: {1}", inputFile,
                              Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
                    Bass.BASS_StreamFree(stream);
                    continue;
                }

                dataGridViewConvert.Rows[_currentRow].Cells[0].Value = 100;

                Bass.BASS_StreamFree(stream);

                try
                {
                    // Now Tag the encoded File
                    File tagInFile  = File.Create(inputFile);
                    File tagOutFile = File.Create(outFile);
                    tagOutFile.Tag.AlbumArtists = tagInFile.Tag.AlbumArtists;
                    tagOutFile.Tag.Album        = tagInFile.Tag.Album;
                    tagOutFile.Tag.Genres       = tagInFile.Tag.Genres;
                    tagOutFile.Tag.Year         = tagInFile.Tag.Year;
                    tagOutFile.Tag.Performers   = tagInFile.Tag.Performers;
                    tagOutFile.Tag.Track        = tagInFile.Tag.Track;
                    tagOutFile.Tag.TrackCount   = tagInFile.Tag.TrackCount;
                    tagOutFile.Tag.Title        = tagInFile.Tag.Title;
                    tagOutFile.Tag.Comment      = tagInFile.Tag.Comment;
                    tagOutFile.Tag.Composers    = tagInFile.Tag.Composers;
                    tagOutFile.Tag.Conductor    = tagInFile.Tag.Conductor;
                    tagOutFile.Tag.Copyright    = tagInFile.Tag.Copyright;
                    tagOutFile.Tag.Disc         = tagInFile.Tag.Disc;
                    tagOutFile.Tag.DiscCount    = tagInFile.Tag.DiscCount;
                    tagOutFile.Tag.Lyrics       = tagInFile.Tag.Lyrics;
                    tagOutFile.Tag.Pictures     = tagInFile.Tag.Pictures;
                    tagOutFile = Util.FormatID3Tag(tagOutFile);
                    tagOutFile.Save();
                }
                catch (Exception ex)
                {
                    log.Error("Error tagging encoded file {0}. Error: {1}", outFile, ex.Message);
                }
            }
            Options.MainSettings.LastConversionEncoderUsed = encoder;
            _currentRow = -1;

            log.Trace("<<<");
        }