Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));

            var scheduler       = new TelegramScheduler(File.ReadAllText("telegram.token"));
            var pipelineBuilder = new DataPipelineBuilder();

            var fetcher   = new GeniusSongInfoFetcher(File.ReadAllText("genius.token"));
            var extractor = new SongInfoExtractor();

            pipelineBuilder.Append(new LambdaProcessor(source =>
            {
                var info = extractor.ExtractFromString(source.FileName);

                info.WriteToFile(source.FileInfo.FullName);
                info = fetcher.ExtractAsyncTask(info).GetAwaiter().GetResult();
                info.WriteToFile(source.FileInfo.FullName);

                return(source);
            }));
            scheduler.Add(pipelineBuilder);

            scheduler.Start();

            scheduler.Join();
        }
        public void TestSongInfoExtractionByName(string input, string title, string[] artists)
        {
            var extracted = new SongInfoExtractor(false).ExtractFromStringAsyncTask(input).GetAwaiter().GetResult();

            Assert.AreEqual(title, extracted.Title);

            Assert.AreEqual(artists.Length, extracted.Artists.Length);

            for (int i = 0; i < artists.Length; i++)
            {
                Assert.AreEqual(artists[i], extracted.Artists[i]);
            }
        }
        public void TestSongInfoExtractionByName(string input, string title, string[] artists)
        {
            //TODO: readd / think about other concept, once the file has to exist in order to be analyzed
            //because bitrate
            //var tmpFile = Path.GetTempFileName();
            //var testFile = Path.Combine(Path.GetDirectoryName(tmpFile), input);
            //File.Move(tmpFile, testFile);

            var extracted = new SongInfoExtractor().ExtractFromStringAsyncTask(input).GetAwaiter().GetResult();

            Assert.AreEqual(title, extracted.Title);

            Assert.AreEqual(artists.Length, extracted.Artists.Length);

            for (int i = 0; i < artists.Length; i++)
            {
                Assert.AreEqual(artists[i], extracted.Artists[i]);
            }

            //File.Delete(testFile);
        }
Exemplo n.º 4
0
        private static void Main(string[] args)
        {
            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));

            var scheduler = new TelegramScheduler(new Executor(8, new ExternalSourceComparer()),
                                                  File.ReadAllText("telegram.token"));
            var pipelineBuilder = new DataPipelineBuilder();

            var extractor = new SongInfoExtractor(false);

            GeniusSongInfoFetcher genius = null;

            try {
                string apiKey = null;
                if (File.Exists("genius.token"))
                {
                    apiKey = File.ReadAllText("genius.token");
                }

                genius = new GeniusSongInfoFetcher(apiKey);
            }
            catch (ArgumentException) {}             // will be thrown if no token could be found

            if (genius == null)
            {
                Log.Warn("Neither a genius.token file nor the corresponding environmental variable has been set. -Skipping genius");
            }

            var merger = new SongInfoMerger();             // a class that can merge multiple SongInfo instances

            pipelineBuilder.Append(new LambdaProcessor(source =>
            {
                // load already stored ID3-tags (if any) from the specified file
                var originalInfo = SongInfo.ReadFromFile(source.FileInfo.FullName);

                // try to parse the filename and extract the title, and artist(s)
                var parsedInfo = extractor.ExtractFromString(source.FileName);
                // merge the metadata but ensure that they are (probably) identical
                // greedy ensures that null values are overridden
                originalInfo = merger.Merge(originalInfo, parsedInfo, greedy: true);

                if (genius != null)                   // if a genius client is available
                // search for the info on genius
                {
                    parsedInfo = genius.ExtractAsyncTask(originalInfo).GetAwaiter().GetResult();
                    // since the fetched result could be completely different, non-greedy merging is important
                    originalInfo = merger.Merge(originalInfo, parsedInfo, greedy: false);
                }

                originalInfo.WriteToFile(source.FileInfo.FullName);                 // write new metadata back
                return(source);
            }));

            // Move the finished files into the downloads folder
            pipelineBuilder.Append(new SourceMover("/downloads", keepName: true));

            scheduler.Add(pipelineBuilder);

            scheduler.Start();

            scheduler.Join();
        }