public void TestSongInfoMerging(string title1, string artist1, string title2, string artist2, bool greedy,
                                        string newTitle, string newArtists)
        {
            const char splitChar = '~';
            var        songInfo1 = new SongInfo {
                Title = title1, Artists = artist1.Split(splitChar)
            };
            var songInfo2 = new SongInfo {
                Title = title2, Artists = artist2.Split(splitChar)
            };

            var merged = new SongInfoMerger().Merge(songInfo1, songInfo2, greedy);

            Assert.AreEqual(newTitle, merged.Title);
            CollectionAssert.AreEqual(newArtists.Split(splitChar), merged.Artists);
        }
Esempio n. 2
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();
        }