Ejemplo n.º 1
0
        public static int Main(string[] args)
        {
            try
            {
                Stream sysin = new MemoryStream();
                Console.OpenStandardInput().CopyTo(sysin);

                Console.Error.WriteLine($"Copied STDIN, length {sysin.Length}");

                string id3Title     = Environment.GetEnvironmentVariable("FFM_ID3_TITLE");
                string id3Author    = Environment.GetEnvironmentVariable("FFM_ID3_AUTHOR");
                string mimeHint     = Environment.GetEnvironmentVariable("FFM_MIME");
                int?   limitSeconds = Environment.GetEnvironmentVariable("FFM_MAX_SECONDS") == null ?
                                      new int?() :
                                      Convert.ToInt32(Environment.GetEnvironmentVariable("FFM_MAX_SECONDS"));

                string typeString = InferInformationString(sysin, mimeHint);
                Console.Error.WriteLine($"TypeString is {typeString}");

                AudioFormat audioFormat = AudioFormatFromString(typeString);
                Console.Error.WriteLine($"AudioFormat is {audioFormat}");

                sysin.Position = 0;
                WaveStream readerStream = ReaderForAudioFormat(sysin, audioFormat, limitSeconds, out int seconds);
                Console.Error.WriteLine($"ReaderStream is {readerStream}");

                Stream sysout = Console.OpenStandardOutput();

                var fileWriter = new LameMP3FileWriter
                                 (
                    sysout,
                    readerStream.WaveFormat,
                    320,
                    new ID3TagData
                {
                    Title  = id3Title,
                    Artist = id3Author,
                }
                                 );

                Console.Error.WriteLine($"Setting Debug,Error,Message functions on fileWriter");

                fileWriter.SetDebugFunction(txt => Console.Error.WriteLine(txt));
                fileWriter.SetErrorFunction(txt => Console.Error.WriteLine(txt));
                fileWriter.SetMessageFunction(txt => Console.Error.WriteLine(txt));

                Console.Error.WriteLine($"Streaming operations now!");

                readerStream.CopyTo(fileWriter);
                fileWriter.Flush();
                fileWriter.Close();

                sysout.Close();

                return(seconds);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                Console.Error.Flush();
                return(-1);
            }
        }