Ejemplo n.º 1
0
        void StartRecording()
        {
            // Stop least recent streamed audio
            if (recorders.Count > 0)
            {
                var lastRecorder = recorders[recorders.Count - 1];

                if (File.Exists(lastRecorder.FileName + ".INCOMPLETE"))
                {
                    File.Delete(lastRecorder.FileName + ".INCOMPLETE");
                }

                if (lastRecorder.IsRecording)
                {
                    lastRecorder.Stop();
                }
            }

            // ADS!!! Just ignore :3
            if (IsSongAnAd(currentSong))
            {
                return;
            }

            var parentPath = @"" + downloadPath + "//" + GetValidFileName(currentSong.Artist);

            if (!Directory.Exists(parentPath))
            {
                Directory.CreateDirectory(parentPath);
            }

            var spotifyTitleWEx = currentSong.Location;

            if (File.Exists(spotifyTitleWEx) && !File.Exists(spotifyTitleWEx + ".INCOMPLETE"))
            {
                return;
            }

            File.WriteAllText(spotifyTitleWEx + ".INCOMPLETE", "Delete if MP3 file is already done streaming.");

            #region Recorder Initializers
            var recorder = new AudioRecorder
            {
                FileName             = spotifyTitleWEx,
                Format               = Format.MP3,
                Bitrate              = Bitrate.bits320,
                Samplerate           = Samplerate.esamples44100,
                Bits                 = Bits.bits16,
                Channels             = Channels.channels2,
                Mode                 = Mode.WasapiLoopbackCapture,
                ACMTag               = "PCM",
                DeviceIndex          = 0,
                Latency              = 1000,
                StopOnSilence        = true,
                StopOnSilenceSeconds = 2,
                StopOnSilenceVal     = 0,
                TagTitle             = currentSong.SongTitle,
                TagArtists           = new List <string>()
                {
                    currentSong.Artist
                },
                TagComment = "Ripped from Spotify by Meowth"
            };

            var defDeviceIndex = recorder.GetDeviceDefaultIndex(Mode.WasapiLoopbackCapture);

            if (defDeviceIndex != -1)
            {
                recorder.DeviceIndex = defDeviceIndex;
            }

            recorder.RecordError    += LogError;
            recorder.RecordDone     += AddMP3Tags;
            recorder.RecordProgress += FixIndicatorText;

            recorders.Add(recorder);

            recorder.Start();
            lblIndicator.Text = "Streaming";
            #endregion
        }