コード例 #1
0
        /// <summary>
        /// Extracts the episode number.
        /// </summary>
        /// <param name="m">The regex match.</param>
        /// <returns>Episode in specified format.</returns>
        public static ShowEpisode ExtractEpisode(Match m)
        {
            if (m.Success)
            {
                if (m.Groups["y"].Success)
                {
                    return(new ShowEpisode(new DateTime(m.Groups["y"].Value.ToInteger(), m.Groups["m"].Value.ToInteger(), m.Groups["d"].Value.ToInteger())));
                }

                int e;
                var se = new ShowEpisode();

                if (m.Groups["s"].Success)
                {
                    se.Season = m.Groups["s"].Value.ToInteger();
                }
                else
                {
                    se.Season = 1;
                }

                if (m.Groups["em"].Success)
                {
                    if (int.TryParse(m.Groups["em"].Value, out e))
                    {
                        se.Episode = e;
                    }
                    else
                    {
                        se.Episode = Utils.RomanToNumber(m.Groups["em"].Value);
                    }

                    if (int.TryParse(m.Groups["e"].Value, out e))
                    {
                        se.SecondEpisode = e;
                    }
                    else
                    {
                        se.SecondEpisode = Utils.RomanToNumber(m.Groups["e"].Value);
                    }
                }
                else
                {
                    if (int.TryParse(m.Groups["e"].Value, out e))
                    {
                        se.Episode = e;
                    }
                    else
                    {
                        se.Episode = Utils.RomanToNumber(m.Groups["e"].Value);
                    }
                }

                return(se);
            }

            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Generates regular expressions for matching a huge variety of episode numberings.
        /// </summary>
        /// <param name="episode">The extracted episode.</param>
        /// <returns>List of regular expressions.</returns>
        public static Regex GenerateEpisodeRegexes(ShowEpisode episode)
        {
            if (episode == null)
            {
                Log.Warn("ExtractEpisode() returned a null value to GenerateEpisodeRegexes(): This will filter everything.");
                episode = new ShowEpisode();
            }

            return(GenerateEpisodeRegexes(episode.Season.ToString(), episode.Episode.ToString(), episode.AirDate));
        }
コード例 #3
0
ファイル: Parser.cs プロジェクト: pedja1/RS-TV-Show-Tracker
        /// <summary>
        /// Identifies the name of the show.
        /// </summary>
        /// <param name="name">The name of the show.</param>
        /// <param name="ep">The episode.</param>
        /// <param name="askRemote">if set to <c>true</c> lab.rolisoft.net's API will be asked to identify a show after the local database failed.</param>
        /// <returns>
        /// A tuple containing the show's and episode's title and airdate.
        /// </returns>
        private static Tuple<string, string, DateTime, TVShow, Episode> IdentifyShow(string name, ShowEpisode ep, bool askRemote = false)
        {
            var title = string.Empty;
            var date  = DateTime.MinValue;
            var match = false;
            var ltvsh = default(TVShow);
            var lepis = default(Episode);

            // try to find show in local database

            foreach (var show in Database.TVShows.Values.ToList())
            {
                var titleMatch   = ShowNames.Parser.GenerateTitleRegex(show.Name).Match(name);
                var releaseMatch = !string.IsNullOrWhiteSpace(show.Release) ? Regex.Match(name, show.Release) : null;

                if ((titleMatch.Success && titleMatch.Value == name) || (releaseMatch != null && releaseMatch.Success && releaseMatch.Value == name))
                {
                    if (ep == null)
                    {
                        match = true;
                        ltvsh = show;
                        name  = show.Name;

                        break;
                    }
                    else if (ep.AirDate != null)
                    {
                        var episode = show.Episodes.Where(x => x.Airdate.ToOriginalTimeZone(x.Show.TimeZone).Date == ep.AirDate.Value.Date).ToList();
                        if (episode.Count != 0)
                        {
                            match = true;
                            ltvsh = show;
                            name  = show.Name;
                            lepis = episode[0];
                            title = episode[0].Name;
                            date  = episode[0].Airdate;

                            ep.Season  = episode[0].Season;
                            ep.Episode = episode[0].Number;

                            break;
                        }
                    }
                    else
                    {
                        Episode episode;
                        if (show.EpisodeByID.TryGetValue(ep.Season * 1000 + ep.Episode, out episode))
                        {
                            match = true;
                            ltvsh = show;
                            name  = show.Name;
                            lepis = episode;
                            title = episode.Name;
                            date  = episode.Airdate;

                            break;
                        }
                    }
                }
            }

            // try to find show in the local cache of the list over at lab.rolisoft.net

            if (!match)
            {
                if (AllKnownTVShows.Count == 0)
                {
                    var path = Path.Combine(Signature.InstallPath, @"misc\tvshows");

                    if (File.Exists(path) && new FileInfo(path).Length != 0)
                    {
                        using (var fs = File.OpenRead(path))
                        using (var br = new BinaryReader(fs))
                        {
                            var ver = br.ReadByte();
                            var upd = br.ReadUInt32();
                            var cnt = br.ReadUInt32();

                            AllKnownTVShows = new List<KnownTVShow>();

                            for (var i = 0; i < cnt; i++)
                            {
                                var show = new KnownTVShow();

                                show.Title      = br.ReadString();
                                show.Slug       = br.ReadString();
                                show.Database   = br.ReadString();
                                show.DatabaseID = br.ReadString();

                                AllKnownTVShows.Add(show);
                            }
                        }
                    }
                    else
                    {
                        try { GetAllKnownTVShows(); } catch { }
                    }
                }

                var slug    = Utils.CreateSlug(name);
                var matches = new List<KnownTVShow>();

                foreach (var show in AllKnownTVShows)
                {
                    if (show.Slug == slug)
                    {
                        matches.Add(show);
                    }
                }

                if (matches.Count != 0 && ep == null)
                {
                    match = true;
                    name  = matches[0].Title;
                }
                else if (matches.Count != 0 && ep != null)
                {
                    TVShow local = null;

                    foreach (var mtch in matches)
                    {
                        foreach (var show in Database.TVShows.Values)
                        {
                            if (show.Source == mtch.Database && show.SourceID == mtch.DatabaseID)
                            {
                                local = show;
                                break;
                            }
                        }
                    }

                    if (local != null)
                    {
                        match = true;
                        name  = local.Name;

                        if (ep.AirDate != null)
                        {
                            var eps = local.Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                ltvsh = eps[0].Show;
                                title = eps[0].Name;
                                lepis = eps[0];
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = local.Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                ltvsh = eps[0].Show;
                                title = eps[0].Name;
                                lepis = eps[0];
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                    else if (ShowIDCache.ContainsKey(name) && TVShowCache.ContainsKey(name))
                    {
                        match = true;
                        name  = ShowIDCache[name].Title;

                        if (ep.AirDate != null)
                        {
                            var eps = TVShowCache[name].Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = TVShowCache[name].Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                    else if (askRemote)
                    {
                        var guide = Updater.CreateGuide(matches[0].Database);
                        var data  = guide.GetData(matches[0].DatabaseID);

                        ShowIDCache[name] = new ShowID { Title = data.Title };

                        match = true;
                        name  = data.Title;

                        TVShowCache[name] = data;

                        if (ep.AirDate != null)
                        {
                            var eps = data.Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = data.Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                }
            }

            // try to find show in cache

            if (!match && ShowIDCache.ContainsKey(name))
            {
                match = true;
                name  = ShowIDCache[name].Title;

                if (ep != null)
                {
                    if (TVShowCache.ContainsKey(name))
                    {
                        if (ep.AirDate != null)
                        {
                            var eps = TVShowCache[name].Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = TVShowCache[name].Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                    else
                    {
                        match = false;
                    }
                }
            }

            // try to identify show using lab.rolisoft.net's API

            if (!match && askRemote)
            {
                var req = Remote.API.GetShowInfo(name, new[] { "Title", "Source", "SourceID" });

                if (req.Success)
                {
                    if (ep == null)
                    {
                        ShowIDCache[name] = new ShowID { Title = req.Title };

                        match = true;
                        name  = req.Title;
                    }
                    else
                    {
                        var guide = Updater.CreateGuide(req.Source);
                        var data  = guide.GetData(req.SourceID);

                        ShowIDCache[name] = new ShowID { Title = data.Title };

                        match = true;
                        name  = data.Title;

                        TVShowCache[name] = data;

                        if (ep.AirDate != null)
                        {
                            var eps = data.Episodes.Where(ch => ch.Airdate.Date == ep.AirDate.Value.Date).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;

                                ep.Season  = eps[0].Season;
                                ep.Episode = eps[0].Number;
                            }
                        }
                        else
                        {
                            var eps = data.Episodes.Where(ch => ch.Season == ep.Season && ch.Number == ep.Episode).ToList();
                            if (eps.Count() != 0)
                            {
                                title = eps[0].Title;
                                date  = eps[0].Airdate;
                            }
                        }
                    }
                }
            }

            // return

            return match
                   ? new Tuple<string, string, DateTime, TVShow, Episode>(name, title, date, ltvsh, lepis)
                   : null;
        }
コード例 #4
0
ファイル: Parser.cs プロジェクト: pedja1/RS-TV-Show-Tracker
 /// <summary>
 /// Generates regular expressions for matching a huge variety of episode numberings.
 /// </summary>
 /// <param name="episode">The extracted episode.</param>
 /// <returns>List of regular expressions.</returns>
 public static Regex GenerateEpisodeRegexes(ShowEpisode episode)
 {
     return GenerateEpisodeRegexes(episode.Season.ToString(), episode.Episode.ToString(), episode.AirDate);
 }
コード例 #5
0
ファイル: Parser.cs プロジェクト: pedja1/RS-TV-Show-Tracker
        /// <summary>
        /// Extracts the episode number.
        /// </summary>
        /// <param name="name">The show name with episode.</param>
        /// <returns>Episode in specified format.</returns>
        public static ShowEpisode ExtractEpisode(string name)
        {
            var m = Regexes.AdvNumbering.Match(name);

            if (m.Success)
            {
                if (m.Groups["y"].Success)
                {
                    return new ShowEpisode(new DateTime(m.Groups["y"].Value.ToInteger(), m.Groups["m"].Value.ToInteger(), m.Groups["d"].Value.ToInteger()));
                }

                int e;
                var se = new ShowEpisode();

                if (m.Groups["s"].Success)
                {
                    se.Season = m.Groups["s"].Value.ToInteger();
                }
                else
                {
                    se.Season = 1;
                }

                if (m.Groups["em"].Success)
                {
                    if (int.TryParse(m.Groups["em"].Value, out e))
                    {
                        se.Episode = e;
                    }
                    else
                    {
                        se.Episode = Utils.RomanToNumber(m.Groups["em"].Value);
                    }

                    if (int.TryParse(m.Groups["e"].Value, out e))
                    {
                        se.SecondEpisode = e;
                    }
                    else
                    {
                        se.SecondEpisode = Utils.RomanToNumber(m.Groups["e"].Value);
                    }
                }
                else
                {
                    if (int.TryParse(m.Groups["e"].Value, out e))
                    {
                        se.Episode = e;
                    }
                    else
                    {
                        se.Episode = Utils.RomanToNumber(m.Groups["e"].Value);
                    }
                }

                return se;
            }

            return null;
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShowFile" /> class.
        /// </summary>
        /// <param name="name">The name of the original file.</param>
        /// <param name="show">The name of the show.</param>
        /// <param name="ep">The parsed season and episode.</param>
        /// <param name="title">The title of the episode.</param>
        /// <param name="quality">The quality of the file.</param>
        /// <param name="group">The group.</param>
        /// <param name="airdate">The airdate of the episode.</param>
        /// <param name="dbtvshow">The TV show in the local database.</param>
        /// <param name="dbepisode">The episode in the local database.</param>
        /// <param name="success">if set to <c>true</c> the file was successfully parsed.</param>
        public ShowFile(string name, string show, ShowEpisode ep, string title, string quality, string group, DateTime airdate, TVShow dbtvshow = null, Episode dbepisode = null, bool success = true)
        {
            Name          = name;
            Extension     = Path.GetExtension(Name);
            Show          = show;
            Episode       = ep;
            Title         = title;
            Quality       = quality;
            Group         = group;
            Airdate       = airdate;
            Success       = success;
            DbTVShow      = dbtvshow;
            DbEpisode     = dbepisode;

            if (DbTVShow != null || DbEpisode != null)
            {
                Local = true;
            }
        }
コード例 #7
0
        /// <summary>
        /// Generates regular expressions for matching a huge variety of episode numberings.
        /// </summary>
        /// <param name="episode">The extracted episode.</param>
        /// <returns>List of regular expressions.</returns>
        public static Regex GenerateEpisodeRegexes(ShowEpisode episode)
        {
            if (episode == null)
            {
                Log.Warn("ExtractEpisode() returned a null value to GenerateEpisodeRegexes(): This will filter everything.");
                episode = new ShowEpisode();
            }

            return GenerateEpisodeRegexes(episode.Season.ToString(), episode.Episode.ToString(), episode.AirDate);
        }