コード例 #1
0
        public string BuildFileName(string path, bool includePath = true)
        {
            string songName;
            var    track = _userSettings.OrderNumber?.ToString("000 ") ?? null;

            if (_userSettings.GroupByFoldersEnabled)
            {
                songName = Normalize.RemoveDiacritics(_track.Title);
                songName = Regex.Replace(songName, _windowsExlcudedChars, string.Empty);
            }
            else
            {
                songName = Normalize.RemoveDiacritics(_track.ToString());
                songName = Regex.Replace(songName, _windowsExlcudedChars, string.Empty);
            }

            var songNameTrackNumber = Regex.Replace($"{track}{songName}", "\\s", _userSettings.TrackTitleSeparator);
            var filename            = GetFileName(songNameTrackNumber, FirstSongNameCount, includePath ? path : null);
            var count = FirstSongNameCount;

            while (_userSettings.DuplicateAlreadyRecordedTrack && File.Exists(GetFileName(songNameTrackNumber, count, path)))
            {
                if (includePath)
                {
                    count++;
                }
                filename = GetFileName(songNameTrackNumber, count, includePath ? path : null);
                if (!includePath)
                {
                    count++;
                }
            }

            return(filename);
        }
コード例 #2
0
        private string BuildFileName(string path, bool includePath = true)
        {
            string songName;
            var    track = _compteur != -1 && _bNumFile ? $"{_compteur :000} " : null;

            if (_strucDossiers)
            {
                songName = Normalize.RemoveDiacritics(_song.Title);
                songName = Regex.Replace(songName, _windowsExlcudedChars, string.Empty);
            }
            else
            {
                songName = Normalize.RemoveDiacritics(_song.ToString());
                songName = Regex.Replace(songName, _windowsExlcudedChars, string.Empty);
            }

            var songNameTrackNumber = Regex.Replace($"{track}{songName}", "\\s", _charSeparator);
            var filename            = GetFileName(songNameTrackNumber, FirstSongNameCount, includePath ? path : null);
            var count = FirstSongNameCount;

            while (File.Exists(GetFileName(songNameTrackNumber, count, path)))
            {
                if (includePath)
                {
                    count++;
                }
                filename = GetFileName(songNameTrackNumber, count, includePath ? path : null);
                if (!includePath)
                {
                    count++;
                }
            }

            return(filename);
        }
コード例 #3
0
        private static string GetAlbumFolderPath(Track track, string trackTitleSeparator)
        {
            var albumInfos = new List <string>()
            {
                string.IsNullOrEmpty(track.Album) ? Track.UNTITLED_ALBUM : Normalize.RemoveDiacritics(track.Album)
            };

            if (track.Year.HasValue)
            {
                albumInfos.Add($"({track.Year.Value})");
            }
            return(Regex.Replace(string.Join(" ", albumInfos), _windowsExlcudedChars, string.Empty).Replace(" ", trackTitleSeparator));
        }
コード例 #4
0
        public string CreateDirectory()
        {
            string insertArtistDir = null;
            var    artistDir       = Normalize.RemoveDiacritics(_track.Artist);

            artistDir = Regex.Replace(artistDir, _windowsExlcudedChars, string.Empty);

            if (_userSettings.GroupByFoldersEnabled)
            {
                insertArtistDir = $"//{artistDir}";
                Directory.CreateDirectory($"{_userSettings.OutputPath}//{artistDir}");
            }

            return(insertArtistDir);
        }
コード例 #5
0
ファイル: FileManager.cs プロジェクト: fquijano29/spy-spotify
        public static string GetFolderPath(Track track, UserSettings userSettings)
        {
            string insertArtistDir = null;
            var    artistDir       = Normalize.RemoveDiacritics(track.Artist);

            artistDir = Regex.Replace(artistDir, _windowsExlcudedChars, string.Empty);

            if (userSettings.GroupByFoldersEnabled)
            {
                insertArtistDir = $"\\{artistDir}";
                Directory.CreateDirectory($"{userSettings.OutputPath}\\{artistDir}");
            }

            return(insertArtistDir);
        }
コード例 #6
0
        public Stream GetFileWriter(WasapiLoopbackCapture waveIn)
        {
            Stream writer;
            string insertArtistDir = null;
            var    artistDir       = Normalize.RemoveDiacritics(_song.Artist);

            artistDir = Regex.Replace(artistDir, _windowsExlcudedChars, string.Empty);

            if (_strucDossiers)
            {
                insertArtistDir = "//" + artistDir;
                Directory.CreateDirectory(_path + "//" + artistDir);
            }

            if (_format == Format.Mp3)
            {
                try
                {
                    _currentFile = BuildFileName(_path + insertArtistDir);
                    writer       = new LameMP3FileWriter(
                        _currentFile,
                        waveIn.WaveFormat,
                        _bitrate);

                    return(writer);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(null);
                }
            }

            try
            {
                _currentFile = BuildFileName(_path + insertArtistDir);
                writer       = new WaveFileWriter(
                    _currentFile,
                    waveIn.WaveFormat
                    );
                return(writer);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }
コード例 #7
0
ファイル: FileManager.cs プロジェクト: tuanla07/spy-spotify
        private static string GenerateFileName(Track track, UserSettings userSettings)
        {
            string fileName;

            if (userSettings.GroupByFoldersEnabled)
            {
                fileName = Normalize.RemoveDiacritics(track.ToTitleString());
                fileName = Regex.Replace(fileName, _windowsExlcudedChars, string.Empty);
            }
            else
            {
                fileName = Normalize.RemoveDiacritics(track.ToString());
                fileName = Regex.Replace(fileName, _windowsExlcudedChars, string.Empty);
            }

            var trackNumber = userSettings.OrderNumberInfrontOfFileEnabled ? (userSettings.OrderNumberAsFile ?? 0).ToString($"{userSettings.OrderNumberMask} ") : null;

            return(Regex.Replace($"{trackNumber}{fileName}", @"\s", userSettings.TrackTitleSeparator));;
        }
コード例 #8
0
ファイル: FileManager.cs プロジェクト: fquijano29/spy-spotify
        private static string GetFileName(Track track, UserSettings userSettings)
        {
            string fileName;

            if (userSettings.GroupByFoldersEnabled)
            {
                fileName = Normalize.RemoveDiacritics(track.ToTitleString());
                fileName = Regex.Replace(fileName, _windowsExlcudedChars, string.Empty);
            }
            else
            {
                fileName = Normalize.RemoveDiacritics(track.ToString());
                fileName = Regex.Replace(fileName, _windowsExlcudedChars, string.Empty);
            }

            var trackNumber = userSettings.OrderNumber?.ToString("000 ") ?? null;

            return(Regex.Replace($"{trackNumber}{fileName}", "\\s", userSettings.TrackTitleSeparator));;
        }
コード例 #9
0
ファイル: FileManager.cs プロジェクト: tuanla07/spy-spotify
        private static string GetAlbumFolderPath(string trackAlbum)
        {
            var albumDir = string.IsNullOrEmpty(trackAlbum) ? Track.UNTITLED_ALBUM : Normalize.RemoveDiacritics(trackAlbum);

            return(Regex.Replace(albumDir, _windowsExlcudedChars, string.Empty));
        }
コード例 #10
0
ファイル: FileManager.cs プロジェクト: tuanla07/spy-spotify
        private static string GetArtistFolderPath(string trackArtist)
        {
            var artistDir = Normalize.RemoveDiacritics(trackArtist);

            return(Regex.Replace(artistDir, _windowsExlcudedChars, string.Empty));
        }
コード例 #11
0
        private static string GetArtistFolderPath(Track track, string trackTitleSeparator)
        {
            var artistDir = Normalize.RemoveDiacritics(track.Artist);

            return(Regex.Replace(artistDir, _windowsExlcudedChars, string.Empty).Replace(" ", trackTitleSeparator));
        }
コード例 #12
0
ファイル: Recorder.cs プロジェクト: hobbit19/spy-spotify
        private Stream GetFileWriter(WasapiLoopbackCapture waveIn)
        {
            Stream writer;
            string insertArtistDir = null;
            var    artistDir       = Normalize.RemoveDiacritics(_track.Artist);

            artistDir = Regex.Replace(artistDir, _windowsExlcudedChars, string.Empty);

            if (_userSettings.GroupByFoldersEnabled)
            {
                insertArtistDir = $"//{artistDir}";
                Directory.CreateDirectory($"{_userSettings.OutputPath}//{artistDir}");
            }

            if (_userSettings.MediaFormat.Equals(MediaFormat.Mp3))
            {
                try
                {
                    _currentFile = BuildFileName(_userSettings.OutputPath + insertArtistDir);
                    writer       = new LameMP3FileWriter(
                        _currentFile,
                        waveIn.WaveFormat,
                        _userSettings.Bitrate);

                    return(writer);
                }
                catch (Exception ex)
                {
                    var message = $"{FrmEspionSpotify.Rm.GetString($"logUnknownException")}: ${ex.Message}";

                    if (!Directory.Exists(_userSettings.OutputPath))
                    {
                        message = FrmEspionSpotify.Rm.GetString($"logInvalidOutput");
                    }
                    else if (ex.Message.StartsWith("Unsupported Sample Rate"))
                    {
                        message = FrmEspionSpotify.Rm.GetString($"logWriterIsNull");
                    }
                    else if (ex.Message.StartsWith("Access to the path"))
                    {
                        message = FrmEspionSpotify.Rm.GetString($"logNoAccessOutput");
                    }

                    _form.WriteIntoConsole(message);
                    Console.WriteLine(ex.Message);
                    return(null);
                }
            }

            try
            {
                _currentFile = BuildFileName($"{_userSettings.OutputPath}{insertArtistDir}");
                writer       = new WaveFileWriter(
                    _currentFile,
                    waveIn.WaveFormat
                    );
                return(writer);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(null);
            }
        }