Exemple #1
0
        private string GetTargetEpisodeName([NotNull] ShowConfiguration show, [NotNull] Episode ep, bool urlEncode)
        {
            //note this is for an Episode and not a ProcessedEpisode
            string name = StyleString;

            string epname = ep.Name;

            name = name.ReplaceInsensitive("{ShowName}", show.ShowName);
            name = name.ReplaceInsensitive("{ShowNameLower}", show.ShowName.ToLower().Replace(' ', '-').RemoveCharactersFrom("()[]{}&$:"));
            name = name.ReplaceInsensitive("{ShowNameInitial}", show.ShowName.Initial().ToLower());

            int seasonNumber;
            int episodeNumber;

            switch (show.Order)
            {
            case ProcessedSeason.SeasonType.dvd:
                seasonNumber  = ep.DvdSeasonNumber;
                episodeNumber = ep.DvdEpNum;
                break;

            case ProcessedSeason.SeasonType.aired:
                seasonNumber  = ep.AiredSeasonNumber;
                episodeNumber = ep.AiredEpNum;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            string seasonName = show.CachedShow?.Season(seasonNumber)?.SeasonName;

            name = name.ReplaceInsensitive("{Season}", seasonNumber.ToString());
            name = name.ReplaceInsensitive("{Season:2}", seasonNumber.ToString("00"));
            name = name.ReplaceInsensitiveLazy("{SeasonNumber}", new Lazy <string?>(() => show.GetSeasonIndex(seasonNumber).ToString()), StringComparison.CurrentCultureIgnoreCase);
            name = name.ReplaceInsensitiveLazy("{SeasonNumber:2}", new Lazy <string?>(() => show.GetSeasonIndex(seasonNumber).ToString("00")), StringComparison.CurrentCultureIgnoreCase);
            name = name.ReplaceInsensitive("{Episode}", episodeNumber.ToString("00"));
            name = name.ReplaceInsensitive("{Episode2}", episodeNumber.ToString("00"));
            name = Regex.Replace(name, "{AllEpisodes}", episodeNumber.ToString("00"));
            name = name.ReplaceInsensitive("{SeasonName}", seasonName ?? string.Empty);
            name = name.ReplaceInsensitive("{EpisodeName}", epname);
            name = name.ReplaceInsensitive("{Number}", "");
            name = name.ReplaceInsensitive("{Number:2}", "");
            name = name.ReplaceInsensitive("{Number:3}", "");
            name = name.ReplaceInsensitive("{Imdb}", ep.ImdbCode ?? string.Empty);

            CachedSeriesInfo si = show.CachedShow;

            name = name.ReplaceInsensitive("{ShowImdb}", si?.Imdb ?? string.Empty);
            name = name.ReplaceInsensitiveLazy("{Year}", new Lazy <string?>(() => si?.MinYear.ToString() ?? string.Empty), StringComparison.CurrentCultureIgnoreCase);

            ProcessedSeason selectedProcessedSeason = show.GetSeason(ep.GetSeasonNumber(show.Order));

            name = name.ReplaceInsensitive("{SeasonYear}", selectedProcessedSeason != null ? selectedProcessedSeason.MinYear().ToString() : string.Empty);

            name = ReplaceDates(urlEncode, name, ep.GetAirDateDt(show.GetTimeZone()));

            name = Regex.Replace(name, "([^\\\\])\\[.*?[^\\\\]\\]", "$1"); // remove optional parts

            name = name.Replace("\\[", "[");
            name = name.Replace("\\]", "]");

            return(name.Trim());
        }