Skip to content

Commit

Permalink
Merge pull request #107 from yairp03/dev
Browse files Browse the repository at this point in the history
Added a proper way to quit the app
  • Loading branch information
yairp03 authored Oct 2, 2022
2 parents 20e3ac8 + 8b7eeb6 commit 3a2c502
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions HoradotTV.Console/IOHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static string ChooseOption(IEnumerable<string> options, string type = "op
do
{
Print($"\nAvailable {type}s: " + string.Join(", ", options));
option = Input($"{title}: ");
if (options.Contains(option))
option = Input($"{title} (c - cancel): ");
if (option == "c" || options.Contains(option))
return option;
Print($"Please enter an valid {type}.");
} while (true);
Expand Down
22 changes: 17 additions & 5 deletions HoradotTV.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,26 @@ static async Task Main()
}

var season = await GetSeason(driver, series);
if (season is null)
continue;
if (mode == Modes.Season)
{
await DownloadSeason(driver, season, downloadLocation);
continue;
}

var episode = await GetEpisode(driver, season);
if (episode is null)
continue;
if (mode == Modes.Episode)
{
await DownloadEpisode(driver, episode, downloadLocation);
continue;
}

var episodesAmount = GetEpisodesAmount();
if (episodesAmount == 0)
continue;
await DownloadEpisodes(driver, episode, episodesAmount, downloadLocation);
}
}
Expand All @@ -70,7 +76,9 @@ static async Task Main()
var searchResult = new List<SeriesInformation>();
do
{
var query = IOHelpers.Input("\nEnter series name or part of it: ");
var query = IOHelpers.Input("\nEnter series name or part of it (q - quit): ");
if (query == "q")
Environment.Exit(0);
if (query.Length < Constants.QUERY_MIN_LENGTH)
{
IOHelpers.Print($"Please enter at least {Constants.QUERY_MIN_LENGTH} characters.");
Expand Down Expand Up @@ -132,25 +140,29 @@ static Modes GetMode()
return (Modes)IOHelpers.ChooseOptionRange(Enum.GetNames(typeof(Modes)).Length - 1, "Choose a mode");
}

static async Task<SeasonInformation> GetSeason(SdarotDriver driver, SeriesInformation series)
static async Task<SeasonInformation?> GetSeason(SdarotDriver driver, SeriesInformation series)
{
var seasons = await driver.GetSeasonsAsync(series);
var seasonName = IOHelpers.ChooseOption(seasons.Select(s => s.SeasonName), "season", "Choose a season");
if (seasonName == "c")
return null;
var season = seasons.Where(s => s.SeasonName == seasonName).First();
return season;
}
static async Task<EpisodeInformation> GetEpisode(SdarotDriver driver, SeasonInformation season)
static async Task<EpisodeInformation?> GetEpisode(SdarotDriver driver, SeasonInformation season)
{
var episodes = await driver.GetEpisodesAsync(season);
var episodeName = IOHelpers.ChooseOption(episodes.Select(e => e.EpisodeName), "episode", "Choose an episode");
if (episodeName == "c")
return null;
var episode = episodes.Where(e => e.EpisodeName == episodeName).First();
return episode;
}

static int GetEpisodesAmount()
{
var amount = IOHelpers.InputInt("\nEnter episodes amount: ");
while (amount <= 0)
var amount = IOHelpers.InputInt("\nEnter episodes amount (0 - cancel): ");
while (amount < 0)
{
IOHelpers.Print("Please enter a positive amount.");
amount = IOHelpers.InputInt("Enter episodes amount: ");
Expand Down

0 comments on commit 3a2c502

Please sign in to comment.