Exemplo n.º 1
0
 public WatcherTests()
 {
     _form         = new Mock <IFrmEspionSpotify>().Object;
     _audioSession = new Mock <IMainAudioSession>().Object;
     _fileSystem   = new MockFileSystem(new Dictionary <string, MockFileData>());
     _userSettings = new UserSettings();
 }
Exemplo n.º 2
0
 public Recorder(IFrmEspionSpotify espionSpotifyForm, UserSettings userSettings, Track track)
 {
     _form         = espionSpotifyForm;
     _track        = track;
     _userSettings = userSettings;
     _fileManager  = new FileManager(_userSettings, _track);
 }
Exemplo n.º 3
0
        private static void LogLameMP3FileWriterArgumentException(IFrmEspionSpotify form, ArgumentException ex, string outputPath)
        {
            var resource = I18nKeys.LogUnknownException;
            var args     = ex.Message;

            if (!Directory.Exists(outputPath))
            {
                resource = I18nKeys.LogInvalidOutput;
            }
            else if (ex.Message.StartsWith("Unsupported Sample Rate"))
            {
                resource = I18nKeys.LogUnsupportedRate;
            }
            else if (ex.Message.StartsWith("Access to the path"))
            {
                resource = I18nKeys.LogNoAccessOutput;
            }
            else if (ex.Message.StartsWith("Unsupported number of channels"))
            {
                var numberOfChannels = ex.Message.Length > 32 ? ex.Message.Remove(0, 31) : "?";
                var indexOfBreakLine = numberOfChannels.IndexOf("\r\n");
                numberOfChannels = numberOfChannels.Substring(0, indexOfBreakLine != -1 ? indexOfBreakLine : 0);
                resource         = I18nKeys.LogUnsupportedNumberChannels;
                args             = numberOfChannels;
            }

            form.UpdateIconSpotify(true, false);
            form.WriteIntoConsole(resource, args);
        }
Exemplo n.º 4
0
 public Recorder(IFrmEspionSpotify form, UserSettings userSettings, Track track, IFileSystem fileSystem)
 {
     _form         = form;
     _fileSystem   = fileSystem;
     _track        = track;
     _userSettings = userSettings;
     _fileManager  = new FileManager(_userSettings, _track, fileSystem);
 }
Exemplo n.º 5
0
 internal Recorder(
     IFrmEspionSpotify form,
     IAudioThrottler audioThrottler,
     UserSettings userSettings,
     ref Track track,
     IFileSystem fileSystem) : this(form, audioThrottler, userSettings, ref track, fileSystem, init : true)
 {
 }
Exemplo n.º 6
0
        public WatcherTests()
        {
            _formMock     = new Moq.Mock <IFrmEspionSpotify>().Object;
            _userSettings = new UserSettings();

            _fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { @"C:\path\Artist_-_Dont_Overwrite_Me.mp3", new MockFileData(new byte[] { 0x12, 0x34, 0x56, 0xd2 }) }
            });
        }
Exemplo n.º 7
0
        public RecorderTests()
        {
            _formMock     = new Mock <IFrmEspionSpotify>().Object;
            _fileSystem   = new MockFileSystem(new Dictionary <string, MockFileData>());
            _userSettings = new UserSettings();

            var audioThrottlerMock = new Mock <IAudioThrottler>();

            audioThrottlerMock.Setup(x => x.WaveFormat).Returns(new WaveFormat());
            _audioThrottler = audioThrottlerMock.Object;
        }
Exemplo n.º 8
0
        public Recorder(IFrmEspionSpotify form, IMainAudioSession audioSession, UserSettings userSettings, Track track, IFileSystem fileSystem)
        {
            _userSettings = new UserSettings();
            userSettings.CopyAllTo(_userSettings);

            _form         = form;
            _audioSession = audioSession;
            _fileSystem   = fileSystem;
            _track        = track;
            _fileManager  = new FileManager(_userSettings, _track, fileSystem);
        }
Exemplo n.º 9
0
        private static void LogLameMP3FileWriterException(IFrmEspionSpotify form, Exception ex)
        {
            if (ex.Message.Contains("Unable to load DLL"))
            {
                form.WriteIntoConsole(I18nKeys.LogMissingDlls);
            }
            else
            {
                form.WriteIntoConsole(I18nKeys.LogUnknownException, ex.Message);
            }

            form.UpdateIconSpotify(true, false);
            Console.WriteLine(ex.Message);
        }
Exemplo n.º 10
0
        public static bool TestFileWriter(IFrmEspionSpotify form, IMainAudioSession audioSession, UserSettings settings)
        {
            if (audioSession.AudioMMDevicesManager.AudioEndPointDevice == null)
            {
                return(false);
            }

            var waveIn = new WasapiLoopbackCapture(audioSession.AudioMMDevicesManager.AudioEndPointDevice);

            switch (settings.MediaFormat)
            {
            case MediaFormat.Mp3:
                try
                {
                    using (new LameMP3FileWriter(new MemoryStream(), waveIn.WaveFormat, settings.Bitrate))
                    {
                        return(true);
                    }
                }
                catch (ArgumentException ex)
                {
                    return(LogLameMP3FileWriterArgumentException(form, ex, waveIn.WaveFormat));
                }
                catch (Exception ex)
                {
                    LogLameMP3FileWriterException(form, ex);
                    return(false);
                }

            case MediaFormat.Wav:
                try
                {
                    using (new WaveFileWriter(new MemoryStream(), waveIn.WaveFormat))
                    {
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    form.UpdateIconSpotify(true, false);
                    form.WriteIntoConsole(I18NKeys.LogUnknownException, ex.Message);
                    Console.WriteLine(ex.Message);
                    Program.ReportException(ex);
                    return(false);
                }

            default:
                return(false);
            }
        }
Exemplo n.º 11
0
        public Watcher(IFrmEspionSpotify form, IMainAudioSession audioSession, UserSettings userSettings, Track track,
                       IFileSystem fileSystem, List <RecorderTask> recorderTasks)
        {
            _form          = form;
            _audioSession  = audioSession;
            _userSettings  = userSettings;
            _currentTrack  = track;
            _fileSystem    = fileSystem;
            _recorderTasks = recorderTasks;

            _cancellationToken = new CancellationTokenSource();

            Settings.Default.app_console_logs = string.Empty;
            Settings.Default.Save();
        }
Exemplo n.º 12
0
        public Recorder(
            IFrmEspionSpotify form,
            IAudioThrottler audioThrottler,
            UserSettings userSettings,
            ref Track track,
            IFileSystem fileSystem,
            bool init)
        {
            _userSettings = new UserSettings();
            userSettings.CopyAllTo(_userSettings);

            _form           = form;
            _audioThrottler = audioThrottler;
            _fileSystem     = fileSystem;
            _track          = track;
            _fileManager    = new FileManager(_userSettings, _track, fileSystem);

            _initiated = init && Init();
        }
Exemplo n.º 13
0
        public static bool TestFileWriter(IFrmEspionSpotify form, UserSettings settings)
        {
            var waveIn = new WasapiLoopbackCapture(settings.SpotifyAudioSession.AudioEndPointDevice);

            switch (settings.MediaFormat)
            {
            case MediaFormat.Mp3:
                try
                {
                    // TODO: #97 NAudio Multi channel pass through
                    //return true;
                    using (var writer = new LameMP3FileWriter(new MemoryStream(), waveIn.WaveFormat, settings.Bitrate)) return(true);
                }
                catch (ArgumentException ex)
                {
                    LogLameMP3FileWriterArgumentException(form, ex, settings.OutputPath);
                    return(false);
                }
                catch (Exception ex)
                {
                    LogLameMP3FileWriterException(form, ex);
                    return(false);
                }

            case MediaFormat.Wav:
                try
                {
                    using (var writer = new WaveFileWriter(new MemoryStream(), waveIn.WaveFormat)) return(true);
                }
                catch (Exception ex)
                {
                    form.UpdateIconSpotify(true, false);
                    form.WriteIntoConsole(I18nKeys.LogUnknownException, ex.Message);
                    Console.WriteLine(ex.Message);
                    return(false);
                }

            default:
                return(false);
            }
        }
Exemplo n.º 14
0
        private static bool LogLameMP3FileWriterArgumentException(IFrmEspionSpotify form, ArgumentException ex, WaveFormat waveFormat)
        {
            var restrictions = waveFormat.GetMP3RestrictionCode();

            if (restrictions.Any())
            {
                if (restrictions.Contains(WaveFormatMP3Restriction.Channel))
                {
                    form.WriteIntoConsole(I18nKeys.LogUnsupportedNumberChannels, waveFormat.Channels);
                }
                if (restrictions.Contains(WaveFormatMP3Restriction.SampleRate))
                {
                    form.WriteIntoConsole(I18nKeys.LogUnsupportedRate, waveFormat.SampleRate);
                }
                return(true);
            }

            form.UpdateIconSpotify(true, false);
            form.WriteIntoConsole(I18nKeys.LogUnknownException, ex.Message);
            return(false);
        }
Exemplo n.º 15
0
 internal Watcher(IFrmEspionSpotify form, IMainAudioSession audioSession, UserSettings userSettings) :
     this(form, audioSession, userSettings, new Track(), new FileSystem(), new List <RecorderTask>())
 {
 }
Exemplo n.º 16
0
 public WatcherTests()
 {
     _formMock     = new Moq.Mock <IFrmEspionSpotify>().Object;
     _userSettings = new UserSettings();
 }