Ejemplo n.º 1
0
        /// <summary>
        ///     Searches for new TVShows.
        /// </summary>
        /// <param name="directories">
        ///     The directories to search in.
        /// </param>
        /// <returns>
        ///     The ambiguous results of the search for user selection.
        /// </returns>
        public Dictionary <string, List <TvShow> > SearchNewShows(IEnumerable <IDirectoryInfo> directories)
        {
            var showDirs      = new List <string>();
            var existingShows = tvShowRepository.GetTvShows().Select(x => x.FolderName).ToList();

            // Add all of dirInfo's subdirectories where they don't already exist and
            // there isn't already a tv show with it as a folder name.
            foreach (var dirInfo in directories)
            {
                showDirs.AddRange(
                    from dir in dirInfo.GetDirectories()
                    where !showDirs.Contains(dir.Name) && !existingShows.Contains(dir.Name)
                    select dir.Name);
            }

            // Sort the directories so the show's are added alphabetically.
            showDirs.Sort();

            var searchResults = new Dictionary <string, List <TvShow> >();

            foreach (var showName in showDirs)
            {
                // Search for each of the shows using the directory name as the show name.
                var results = tvShowRepository.SearchShow(showName);

                // Any with only one result should be saved or where the first result is an exact match.
                if ((results.Count == 1) ||
                    ((results.Count > 1) &&
                     results[0].Name.Equals(showName, StringComparison.InvariantCultureIgnoreCase)))
                {
                    var show = tvShowRepository.FromSearchResult(results[0]);
                    tvShowRepository.Save(show);
                    Logger.OnLogMessage(show, "Found show {0}", LogType.Info, show.Name);
                }
                else
                {
                    // Any 0 or more than 1 result should be added to the dictionary for user selection.
                    searchResults.Add(showName, results);
                    Logger.OnLogMessage(results, "Found {0} results for {1}", LogType.Info, results.Count, showName);
                }
            }

            return(searchResults);
        }
Ejemplo n.º 2
0
        public async Task <ApiModel <IReadOnlyList <TvShowViewModel> > > Handle(GetTvShows.Query query,
                                                                                CancellationToken cancellationToken)
        {
            var tvShowSummaryViewModel = await
                                         _tvShowRepository.GetTvShows(query.Keyword, new PagingInfo(query.Page, query.PageSize),
                                                                      cancellationToken);

            return(ApiModel <IReadOnlyList <TvShowViewModel> > .Success().WithData(tvShowSummaryViewModel.TvShowViewModels)
                   .WithMeta(tvShowSummaryViewModel.PaginationInfo));
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     Initialises a new instance of the <see cref="ScanManager" /> class.
 /// </summary>
 /// <param name="storageProvider">
 ///     The storage provider to use.
 /// </param>
 /// <param name="dataProvider">
 ///     The data provider to use.
 /// </param>
 /// <param name="tvShowRepository">
 ///     The TV show repository.
 /// </param>
 public ScanManager(
     IStorageProvider storageProvider,
     IDataProvider dataProvider,
     ITvShowRepository tvShowRepository)
 {
     this.storageProvider  = storageProvider;
     this.dataProvider     = dataProvider;
     settings              = storageProvider.Settings;
     this.tvShowRepository = tvShowRepository;
     tvShows = tvShowRepository.GetTvShows().ToList();
     this.tvShowRepository.TvShowAdded   += TvShowAdded;
     this.tvShowRepository.TvShowRemoved += TvShowRemoved;
     this.tvShowRepository.TvShowChanged += TvShowChanged;
 }