Esempio n. 1
0
        private static void Main(string[] args)
        {
            var downloader = new Downloader("anime-list.xml");
            var animelist = downloader.Download().Result;

            var mapper = new Mapper(animelist);

            var fateZero = new AnidbEpisode
            {
                Series = "8160",
                Season = 1,
                Index = 7
            };

            var tvdb = mapper.ToTvdb(fateZero);
            var anidb = mapper.ToAnidb(tvdb);

            var fateZeroS2 = new AnidbEpisode
            {
                Series = "8880",
                Season = 1,
                Index = 11
            };

            tvdb = mapper.ToTvdb(fateZeroS2);
            anidb = mapper.ToAnidb(tvdb);

            var fateZeroSpecial = new AnidbEpisode
            {
                Series = "8880",
                Season = 0,
                Index = 1
            };

            tvdb = mapper.ToTvdb(fateZeroSpecial);
            anidb = mapper.ToAnidb(tvdb);

            var naruto = new AnidbEpisode
            {
                Series = "4880",
                Season = 1,
                Index = 212
            };

            tvdb = mapper.ToTvdb(naruto);
            anidb = mapper.ToAnidb(tvdb);

            var narutoMovie = new AnidbEpisode
            {
                Series = "6503",
                Season = 1,
                Index = 1
            };

            tvdb = mapper.ToTvdb(narutoMovie);
            anidb = mapper.ToAnidb(tvdb);
        }
Esempio n. 2
0
        public TvdbEpisode ToTvdb(AnidbEpisode anidb)
        {
            AnimelistAnime anime;

            if (!_anidbMappings.TryGetValue(anidb.Series, out anime))
            {
                return(null);
            }

            // look for exact mapping in mapping list
            if (anime.Mappinglist != null)
            {
                var mappings = anime.Mappinglist.Where(x => x.AnidbSeason == anidb.Season);
                foreach (var mapping in mappings)
                {
                    var episode = FindAnidbEpisodeMapping(anidb, mapping);

                    if (episode != null)
                    {
                        return(new TvdbEpisode
                        {
                            Series = anime.TvdbId,
                            Season = mapping.TvdbSeason,
                            Index = episode.Value
                        });
                    }
                }
            }

            // absolute episode numbers match
            var season = anime.DefaultTvdbSeason;

            if (season == "a")
            {
                return(new TvdbEpisode
                {
                    Series = anime.TvdbId,
                    Season = null,
                    Index = anidb.Index
                });
            }

            // fallback to offset
            var offset = anime.EpisodeOffsetSpecified ? anime.EpisodeOffset : 0;

            return(new TvdbEpisode
            {
                Series = anime.TvdbId,
                Season = int.Parse(season),
                Index = anidb.Index + offset
            });
        }
Esempio n. 3
0
        private int?FindAnidbEpisodeMapping(AnidbEpisode anidb, AnimelistMapping mapping)
        {
            var maps  = GetEpisodeMappings(mapping);
            var exact = maps.FirstOrDefault(x => x.Anidb == anidb.Index);

            if (exact != null)
            {
                return(exact.Tvdb);
            }

            if (mapping.OffsetSpecified)
            {
                var startInRange = !mapping.StartSpecified || mapping.Start <= anidb.Index;
                var endInRange   = !mapping.EndSpecified || mapping.End >= anidb.Index;

                if (startInRange && endInRange)
                {
                    return(anidb.Index + mapping.Offset);
                }
            }

            return(null);
        }
        private int? FindAnidbEpisodeMapping(AnidbEpisode anidb, AnimelistMapping mapping)
        {
            var maps = GetEpisodeMappings(mapping);
            var exact = maps.FirstOrDefault(x => x.Anidb == anidb.Index);

            if (exact != null)
                return exact.Tvdb;

            if (mapping.OffsetSpecified)
            {
                var startInRange = !mapping.StartSpecified || mapping.Start <= anidb.Index;
                var endInRange = !mapping.EndSpecified || mapping.End >= anidb.Index;

                if (startInRange && endInRange)
                    return anidb.Index + mapping.Offset;
            }

            return null;
        }
        public TvdbEpisode ToTvdb(AnidbEpisode anidb)
        {
            AnimelistAnime anime;
            if (!_anidbMappings.TryGetValue(anidb.Series, out anime))
                return null;

            // look for exact mapping in mapping list
            if (anime.Mappinglist != null)
            {
                var mappings = anime.Mappinglist.Where(x => x.AnidbSeason == anidb.Season);
                foreach (var mapping in mappings)
                {
                    var episode = FindAnidbEpisodeMapping(anidb, mapping);

                    if (episode != null)
                    {
                        return new TvdbEpisode
                        {
                            Series = anime.TvdbId,
                            Season = mapping.TvdbSeason,
                            Index = episode.Value
                        };
                    }
                }
            }

            // absolute episode numbers match
            var season = anime.DefaultTvdbSeason;
            if (season == "a")
            {
                return new TvdbEpisode
                {
                    Series = anime.TvdbId,
                    Season = null,
                    Index = anidb.Index
                };
            }

            // fallback to offset
            var offset = anime.EpisodeOffsetSpecified ? anime.EpisodeOffset : 0;

            return new TvdbEpisode
            {
                Series = anime.TvdbId,
                Season = int.Parse(season),
                Index = anidb.Index + offset
            };
        }