コード例 #1
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="airdate">The airdate of the episode.</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, bool success = true)
 {
     Name          = name;
     Extension     = Path.GetExtension(Name);
     Show          = show;
     Episode       = ep;
     Title         = title;
     Quality       = quality;
     Group         = group;
     Airdate       = airdate;
     Success       = success;
 }
コード例 #2
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;
            }
        }
コード例 #3
0
        /// <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> IdentifyShow(string name, ShowEpisode ep, bool askRemote = false)
        {
            var title = string.Empty;
            var date  = DateTime.MinValue;
            var match = false;

            // try to find show in local database

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

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

                        break;
                    }
                    else if (ep.AirDate != null)
                    {
                        var episode = Database.Episodes.Where(x => x.ShowID == show.Value.ShowID && x.Airdate.ToOriginalTimeZone(x.Show.Data.Get("timezone")).Date == ep.AirDate.Value.Date).ToList();
                        if (episode.Count != 0)
                        {
                            match = true;
                            name  = show.Value.Name;
                            title = episode[0].Name;
                            date  = episode[0].Airdate;

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

                            break;
                        }
                    }
                    else
                    {
                        var episode = Database.Episodes.Where(x => x.EpisodeID == ep.Episode + (ep.Season * 1000) + (show.Value.ShowID * 100 * 1000)).ToList();
                        if (episode.Count != 0)
                        {
                            match = true;
                            name  = show.Value.Name;
                            title = episode[0].Name;
                            date  = episode[0].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 fn = Path.Combine(Path.GetTempPath(), "AllKnownTVShows.bin");

                    if (File.Exists(fn) && new FileInfo(fn).Length != 0)
                    {
                        using (var file = File.OpenRead(fn))
                        {
                            try { AllKnownTVShows = Serializer.Deserialize<List<KnownTVShow>>(file); } catch { }
                        }
                    }
                    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)
                {
                    Tables.TVShow local = null;

                    foreach (var mtch in matches)
                    {
                        foreach (var show in Database.TVShows.Values)
                        {
                            if (show.Data.Get("grabber") == mtch.Database && show.Data.Get(mtch.Database + ".id") == 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)
                            {
                                title = eps[0].Name;
                                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)
                            {
                                title = eps[0].Name;
                                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>(name, title, date)
                   : null;
        }
コード例 #4
0
        /// <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.Title, show).Match(name);
                var releaseRegex = string.Empty;
                var releaseMatch = show.Data.TryGetValue("regex", out releaseRegex) && !string.IsNullOrWhiteSpace(releaseRegex) ? Regex.Match(name, releaseRegex) : null;

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

                        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.Title;
                            lepis = episode[0];
                            title = episode[0].Title;
                            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.Title;
                            lepis = episode;
                            title = episode.Title;
                            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.Title;

                        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].Title;
                                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].Title;
                                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);
        }
コード例 #5
0
 private bool isInValidSeason(ShowEpisode relation)
 {
     return(relation.SeasonEpisodeNr == episodeNr && seasonNr == -1);
 }
コード例 #6
0
 private bool isInValidEpisode(ShowEpisode relation)
 {
     return(relation.SeasonNr == seasonNr && episodeNr == -1);
 }
コード例 #7
0
 private bool isValidRelation(ShowEpisode relation)
 {
     return(relation.SeasonNr == seasonNr && relation.SeasonEpisodeNr == episodeNr);
 }
コード例 #8
0
ファイル: MediaFile.cs プロジェクト: danowar2k/seriesrenamer
 private bool isValidRelation(ShowEpisode relation)
 {
     return relation.SeasonNr == seasonNr && relation.SeasonEpisodeNr == episodeNr;
 }
コード例 #9
0
ファイル: MediaFile.cs プロジェクト: danowar2k/seriesrenamer
 private bool isInValidSeason(ShowEpisode relation)
 {
     return relation.SeasonEpisodeNr == episodeNr && seasonNr == -1;
 }
コード例 #10
0
ファイル: MediaFile.cs プロジェクト: danowar2k/seriesrenamer
 private bool isInValidEpisode(ShowEpisode relation)
 {
     return relation.SeasonNr == seasonNr && episodeNr == -1;
 }