/// <summary> /// Initializes a new instance of the ShowsController object. /// </summary> /// <remarks>Should only be used when a view is to be shown to display multiple show results.</remarks> /// <param name="view">The associated view for this controller.</param> /// <param name="fileToRename">The file to rename.</param> /// <param name="shows">The show results to display on the view.</param> public ShowsController(IShowsView view, TVShowFile fileToRename, IEnumerable <Show> shows) { _view = view; _view.SetController(this); _fileToRename = fileToRename; _shows = shows; }
/// <summary> /// Parses the <paramref name="inputFiles"/> parameter. /// </summary> /// <param name="inputFiles">The files to parse.</param> /// <param name="successfullyParsedFiles">When this method returns, contains the files that were successfully parsed and the values of the parsed files.</param> /// <param name="unsuccessfullyParsedFiles">When this method returns, contains the files that were unsuccessfully parsed.</param> internal void ParseTVShows(IEnumerable<string> inputFiles, out Dictionary<string, List<TVShowFile>> successfullyParsedFiles, out List<string> unsuccessfullyParsedFiles) { if (inputFiles == null) { throw new ArgumentNullException("inputFiles"); } successfullyParsedFiles = new Dictionary<string, List<TVShowFile>>(); // At first, nothing is successfully parsed. unsuccessfullyParsedFiles = new List<string>(inputFiles); // At first, everything is unsuccessful. foreach (string file in inputFiles) // parse each input file { foreach (ITVShowParser parser in _serviceFactory.GetServiceManagers<ITVShowParser>()) // use every parser available. { if (!parser.CanParse(file)) { continue; // Maybe the next parser can parse the file. } TVShowFile tvShowFile = parser.Parse(file); // Add the file to the successful list and remove it from the UNsuccessful list. if (!successfullyParsedFiles.ContainsKey(tvShowFile.ShowName)) { successfullyParsedFiles.Add(tvShowFile.ShowName, new List<TVShowFile>()); } successfullyParsedFiles[tvShowFile.ShowName].Add(tvShowFile); unsuccessfullyParsedFiles.Remove(file); break; } } }
public void Parse_valid1_Parses() { int episode = 1; int season = 1; string episodeString = episode.ToString("00"); string seasonString = season.ToString("00"); string filename = string.Format("{0}.S{1}E{2}.HDTV.mkv", _showName, seasonString, episodeString); TVShowFile file = _parser.Parse(filename); Assert.AreEqual(episode, file.Episode); Assert.AreEqual(season, file.Season); Assert.AreEqual(_showName, file.ShowName); Assert.AreEqual(filename, file.Filename); }
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); }
private void InterpretShowResults(IEnumerable<Show> results, TVShowFile fileToRename) { switch (results.Count()) { case 0: { // no results... to bad.. // Not sure if ths code would ever get reached. throw new ShowNotFoundException(String.Format("No show with the name '{0}' was found.", fileToRename.ShowName), fileToRename.ShowName); } case 1: { // one result... use the show ID to rename the file. Show show = results.First(); ShowsController controller = new ShowsController(fileToRename); try { controller.Rename(show); } catch (EpisodeNotFoundException) { // TODO: Let the user know that the episode data could not be found. } break; } default: { // TODO: create the ShowsFrom to display the results. SetStatus(String.Format("Multiple shows with the name {0} were found. Select the intended show to continue...", fileToRename.ShowName)); using (ShowsForm form = new ShowsForm()) { ShowsController controller = new ShowsController(form, fileToRename, results); if (form.ShowDialog() != DialogResult.OK) { // TODO: error case. } } break; } } }
/// <summary> /// Parses the given filename. /// </summary> /// <param name="filename">the filename to parse.</param> /// <returns>an object containing the important information parsed from the filename.</returns> public TVShowFile Parse(string filename) { if (String.IsNullOrEmpty(filename)) { throw new ArgumentException("Parameter cannot be null of empty.", "filename"); } if (!CanParse(filename)) { throw new InvalidOperationException("Cannot parse the input file"); } Match match = _showRegex.Match(filename); // parts contains the show name in an array. i.e. [game, of, thrones] string[] parts = Path.GetFileName(match.Groups[TitleGroup].Value).Split('.'); StringBuilder sb = new StringBuilder(); // Prepare the show name as one string. Capitalize the first letters and add spaces between the words for (int i = 0; i < parts.Length; ++i) { if ((parts[i].Length > 3) || (i == 0)) { sb.Append(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(parts[i])); // Capitalize the first letter of each word greater than 3 characters (or if it's the first word). } else { sb.Append(parts[i].ToLower()); } sb.Append(" "); } sb.Length--; // Trim the trailing space character; int season = int.Parse(match.Groups[SeasonGroup].Value); int episode = int.Parse(match.Groups[EpisodeGroup].Value); TVShowFile show = new TVShowFile(filename, sb.ToString(), season, episode); return(show); }
public RenameController(TVShowFile tvShowFile) { _file = tvShowFile; }
/// <summary> /// Initializes a new instance of the ShowsController object. /// </summary> /// <remarks>Should only be used when a view is to be shown to display multiple show results.</remarks> /// <param name="filetoRename">The file to rename.</param> public ShowsController(TVShowFile filetoRename) { _fileToRename = filetoRename; }