Exemplo n.º 1
0
        private static MusicLibrary GetLocalMusicLibrary()
        {
            var localLibraryPath  = _argRegistrar.Registry[MediaLibraryCliArgKey.INPUT];
            var localMusicLibrary = new MusicLibrary(new DirectoryInfo(localLibraryPath));

            Console.WriteLine($"Discovered {localMusicLibrary.Collection.Count} items on disk");
            return(localMusicLibrary);
        }
        public MusicLibrary Submit(MetalArchivesRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException($"{nameof(request)} may not be null");
            }

            var response = _service.Process(request);

            var musicLibrary = new MusicLibrary(_parser.Parse(response).Collection);

            return(_filterer.Filter(musicLibrary, request));
        }
Exemplo n.º 3
0
        private static MusicLibrary GetRemoteMusicLibrary(MusicLibrary musicLibrary)
        {
            var remoteMusicLibrary = new MusicLibrary(new List <MusicLibraryItem>());

            foreach (string artistName in musicLibrary.Artists.Select(ad => ad.ArtistName))
            {
                var request = BuildMetalArchivesRequest(artistName);

                remoteMusicLibrary.AddToCollection(MetalArchivesServiceClient.Submit(request));

                Console.WriteLine($"Added {artistName} to library");
                Thread.Sleep(3000);
            }

            return(remoteMusicLibrary);
        }
Exemplo n.º 4
0
        private static void WriteResults(MusicLibrary differences)
        {
            DirectoryInfo resultDirectory = new DirectoryInfo(_argRegistrar.Registry[MediaLibraryCliArgKey.OUTPUT]);

            if (!Directory.Exists(resultDirectory.Parent.FullName))
            {
                Directory.CreateDirectory(resultDirectory.Parent.FullName);
            }

            // TODO: cleanup
            string timestampedFileName =
                resultDirectory.FullName.Replace(resultDirectory.Extension, "") +
                "_" + DateTime.Now.ToLongTimeString().Replace(":", "_").Replace(" ", "_") +
                resultDirectory.Extension;

            string text = String.Join(Environment.NewLine, differences?.Collection);

            File.WriteAllText(timestampedFileName, text);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            _cliHandler = new CliHandler();
            var          _argRegistrar = _cliHandler.GetCliArgRegistrar <MediaLibraryCliArgKey>(args);
            MusicLibrary differences   = null;

            try
            {
                var localMusicLibrary  = GetLocalMusicLibrary();
                var remoteMusicLibrary = GetRemoteMusicLibrary(localMusicLibrary);
                differences = FindItemsMissingFromLocal(localMusicLibrary, remoteMusicLibrary);
            }
            catch (Exception exc)
            {
                Console.WriteLine($"Exception: {exc.Message}");
            }
            finally
            {
                WriteResults(differences);
            }
        }
Exemplo n.º 6
0
 private static MusicLibrary FindItemsMissingFromLocal(MusicLibrary local, MusicLibrary remote)
 {
     return((new MusicLibraryComparer()).Compare(local, remote).RightOutersection);
 }