Пример #1
0
 /// <summary>
 /// Downloads show data from TVDB.
 /// </summary>
 /// <param name="show">the name of the show to get data for.</param>
 /// <returns>A list of shows matching the specified <paramref name="show"/>.</returns>
 private async Task<List<Show>> DownloadShowsByTitle(string show)
 {
    try
    {
       ITVDBService tvdbManager = _serviceFactory.GetServiceManager<ITVDBService>();
       Task<List<Show>> searchTask = tvdbManager.GetShowsByTitle(show);
       SetStatus(String.Format("Searching for shows with the name '{0}'", show));
       List<Show> results = await searchTask;
       return results;
    }
    catch
    {
       throw;
    }
 }
Пример #2
0
      internal async Task Rename(string file)
      {
         // TODO: set status text to parsing
         SetStatus("Parsing input file.");
         _view.VisualizeProgress(true);

         // Loop through each parser and check if it can parse the input file.
         foreach (ITVShowParser parser in _serviceFactory.GetServiceManagers<ITVShowParser>())
         {
            if (!parser.CanParse(file))
            {
               // Maybe the next parser will be able to parse the file.
               continue;
            }
            else
            {
               SetStatus("Successful parser found.");
               try
               {
                  TVShowFile tvShowFile = parser.Parse(file);
                  ITVDBService tvdbManager = _serviceFactory.GetServiceManager<ITVDBService>();

                  SetStatus(String.Format("Searching for a show with the name '{0}'", tvShowFile.ShowName));
                  Task<List<Show>> showsTaskResult = tvdbManager.GetShowsByTitle(tvShowFile.ShowName);
                  // TODO: downloading show data..
                  // TODO: update the progress bar to look like work is being done...
                  List<Show> results = await showsTaskResult;
                  // TODO: make sure the progress bar finishes

                  InterpretShowResults(results, tvShowFile);
               }
               catch (Exception ex)
               {
                  // TODO: Set status text to error
                  SetStatus(String.Format("An error occured renaming the file. {0}", ex.Message));
                  break;
               }

               // TODO: I believe here would be the successful case so display some success message.
               break;
            }
         }
         _view.VisualizeProgress(false);
      }
Пример #3
0
        /// <summary>
        /// Renames the file that given to this object on initialization.
        /// </summary>
        /// <param name="show">The show that is to be used to retrieve episode data.</param>
        /// <exception cref="EpisodeNotFoundException">Thrown when the searched for episode cannot be found for the given show.</exception>
        internal void Rename(Show show)
        {
            ITVDBService tvdbManager = _serviceFactory.GetServiceManager <ITVDBService>();
            // TODO: downloading episode data...
            List <Episode> episodes = tvdbManager.GetEpisodesByShowId(show.Id);

            Episode episode = (from e in episodes
                               where e.Season == _fileToRename.Season &&
                               e.Number == _fileToRename.Episode
                               select e).FirstOrDefault();

            if (episode == null)
            {
                // TODO: should be some way to determine if it was successfull or not.
                // Maybe just use First() and catch the exception if nothing is found.
                throw new EpisodeNotFoundException(String.Format("Show: '{0}' did not contain information for season {1}, episode {2}",
                                                                 show.Title, _fileToRename.Season, _fileToRename.Episode));
            }

            // TODO: status - building the new filename.
            // TODO: Allow multiple output filename templates
            string newFilename = String.Format("{0} S{1}E{2} - {3}.{4}", _fileToRename.ShowName, episode.SeasonAsString(), episode.NumberAsString(), episode.Title, _fileToRename.Extension);

            // Strip off any illegal filename characters.
            string invalidChars = new string(Path.GetInvalidFileNameChars());
            Regex  regex        = new Regex(String.Format("[{0}]", Regex.Escape(invalidChars)));

            newFilename = regex.Replace(newFilename, String.Empty);

            try
            {
                // TODO: status - renaming file.
                File.Move(_fileToRename.Filename, String.Format(@"{0}\{1}", Directory.GetParent(_fileToRename.Filename), newFilename));
                // TODO: I want to know if any exception occurs. Log it out or even just show a message box for testing.
                // The previous version of TVShow rename got hung up way to often without any indication of what was happening.
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }