Esempio n. 1
0
 public ProcessedEpisode(SeriesInfo ser, Season seas, ShowItem si)
     : base(ser, seas)
 {
     this.NextToAir = false;
     this.OverallNumber = -1;
     this.Ignore = false;
     this.EpNum2 = this.EpNum;
     this.SI = si;
 }
Esempio n. 2
0
        public Episode(Episode O)
        {
            this.EpisodeID = O.EpisodeID;
            this.SeriesID = O.SeriesID;
            this.EpNum = O.EpNum;
            this.FirstAired = O.FirstAired;
            this.Srv_LastUpdated = O.Srv_LastUpdated;
            this.Overview = O.Overview;
            this.EpisodeRating = O.EpisodeRating;
            this.EpisodeGuestStars = O.EpisodeGuestStars;
            this.EpisodeDirector = O.EpisodeDirector;
            this.Writer = O.Writer;
            this.Name = O.Name;
            this.TheSeason = O.TheSeason;
            this.TheSeries = O.TheSeries;
            this.SeasonID = O.SeasonID;
            this.Dirty = O.Dirty;

            this.Items = new System.Collections.Generic.Dictionary<string, string>();
            foreach (System.Collections.Generic.KeyValuePair<string, string> i in O.Items)
                this.Items.Add(i.Key, i.Value);
        }
Esempio n. 3
0
        public Banner(Banner O)
        {

            this.BannerId = O.BannerId;
            this.BannerPath = O.BannerPath;
            this.BannerType = O.BannerType;
            this.BannerType2 = O.BannerType2;
            this.Language = O.Language;
            this.Rating = O.Rating;
            this.RatingCount = O.RatingCount;
            this.SeasonID = O.SeasonID;
            this.SeriesID = O.SeriesID;

            this.Colors = O.Colors;
            this.ThumbnailPath = O.ThumbnailPath;
            this.VignettePath = O.VignettePath;
            this.SeriesName = O.SeriesName;
            
            this.Name = O.Name;
            this.TheSeason = O.TheSeason;
            this.TheSeries = O.TheSeries;

        }
Esempio n. 4
0
        private string GetShowImagesHTMLOverview(ShowItem si, SeriesInfo ser)
        {
            string body = "";

            body += "<h1><A HREF=\"" + TheTVDB.Instance.WebsiteURL(si.TVDBCode, -1, true) + "\">" + si.ShowName + "</A> " + "</h1>";

            body += ImageSection("Show Banner", 758, 140, ser.GetItem("banner"));
            body += ImageSection("Show Poster", 350, 500, ser.GetItem("poster"));
            body += ImageSection("Show Fanart", 960, 540, ser.GetItem("fanart"));
            
            return body;
        }
Esempio n. 5
0
        public Episode(SeriesInfo ser, Season seas, XmlReader r, CommandLineArgs args)
        {
            // <Episode>
            //  <id>...</id>
            //  blah blah
            // </Episode>

            try
            {
                this.SetDefaults(ser, seas);

                r.Read();
                if (r.Name != "Episode")
                    return;

                r.Read();
                while (!r.EOF)
                {
                    if ((r.Name == "Episode") && (!r.IsStartElement()))
                        break;
                    if (r.Name == "id")
                        this.EpisodeID = r.ReadElementContentAsInt();
                    else if (r.Name == "seriesid")
                        this.SeriesID = r.ReadElementContentAsInt(); // thetvdb series id
                    else if (r.Name == "seasonid")
                        this.SeasonID = r.ReadElementContentAsInt();
                    else if (r.Name == "EpisodeNumber")
                        this.EpNum = r.ReadElementContentAsInt();
                    else if (r.Name == "SeasonNumber")
                    {
                        String sn = r.ReadElementContentAsString();
                        int.TryParse(sn, out this.ReadSeasonNum);
                    }
                    else if (r.Name == "lastupdated")
                        this.Srv_LastUpdated = r.ReadElementContentAsInt();
                    else if (r.Name == "Overview")
                        this.Overview = Helpers.ReadStringFixQuotesAndSpaces(r);
                    else if (r.Name == "Rating")        
                        this.EpisodeRating = Helpers.ReadStringFixQuotesAndSpaces(r);  
                    else if (r.Name == "GuestStars")
                        this.EpisodeGuestStars = Helpers.ReadStringFixQuotesAndSpaces(r);      
                    else if (r.Name == "Director")
                        this.EpisodeDirector = Helpers.ReadStringFixQuotesAndSpaces(r);      
                    else if (r.Name == "Writer")
                        this.Writer = Helpers.ReadStringFixQuotesAndSpaces(r);      
                    else if (r.Name == "EpisodeName")
                        this.Name = Helpers.ReadStringFixQuotesAndSpaces(r);
                    else if (r.Name == "FirstAired")
                    {
                        try
                        {
                            this.FirstAired = DateTime.ParseExact(r.ReadElementContentAsString(), "yyyy-MM-dd", new System.Globalization.CultureInfo(""));
                        }
                        catch
                        {
                            this.FirstAired = null;
                        }
                    }
                    else
                    {
                        if ((r.IsEmptyElement) || !r.IsStartElement())
                            r.ReadOuterXml();
                        else
                        {
                            XmlReader r2 = r.ReadSubtree();
                            r2.Read();
                            string name = r2.Name;
                            this.Items[name] = r2.ReadElementContentAsString();
                            r.Read();
                        }
                    }
                }
            }
            catch (XmlException e)
            {
                string message = "Error processing data from TheTVDB for an episode.";
                if (this.SeriesID != -1)
                    message += "\r\nSeries ID: " + this.SeriesID;
                if (this.EpisodeID != -1)
                    message += "\r\nEpisode ID: " + this.EpisodeID;
                if (this.EpNum != -1)
                    message += "\r\nEpisode Number: " + this.EpNum;
                if (!string.IsNullOrEmpty(this.Name))
                    message += "\r\nName: " + this.Name;

                message += "\r\n" + e.Message;

                if (!args.Unattended) 
                    MessageBox.Show(message, "TVRename", MessageBoxButtons.OK, MessageBoxIcon.Error);

                throw new TVDBException(e.Message);
            }
        }
Esempio n. 6
0
        public void Merge(SeriesInfo o, String preferredLanguage)
        {
            if (o.TVDBCode != this.TVDBCode)
                return; // that's not us!
            if (o.Srv_LastUpdated != 0 && o.Srv_LastUpdated < this.Srv_LastUpdated)
                return; // older!?

            bool betterLanguage = (o.Language == preferredLanguage) && (this.Language != preferredLanguage);

            this.Srv_LastUpdated = o.Srv_LastUpdated;

            // take the best bits of "o"
            // "o" is always newer/better than us, if there is a choice
            if ((!string.IsNullOrEmpty(o.Name)) && betterLanguage)
                this.Name = o.Name;
           // this.Items.Clear();
            foreach (System.Collections.Generic.KeyValuePair<string, string> kvp in o.Items)
            {
                // on offer is non-empty text, in a better language
                // or text for something we don't have
                if ((!string.IsNullOrEmpty(kvp.Value) && betterLanguage) || 
                     (!this.Items.ContainsKey(kvp.Key) || string.IsNullOrEmpty(this.Items[kvp.Key])))
                    this.Items[kvp.Key] = kvp.Value;
            }
            if (o.AirsTime != null)
                this.AirsTime = o.AirsTime;

            if ((o.Seasons != null) && (o.Seasons.Count != 0))
                this.Seasons = o.Seasons;

            if ((o.Banners != null) && (o.Banners.Count != 0))
                this.Banners = o.Banners;

            if ((o.LangBanners != null) && (o.LangBanners.Count != 0))
                this.LangBanners = o.LangBanners;

            if ((o.LangWideBanners != null) && (o.LangWideBanners.Count != 0))
                this.LangWideBanners = o.LangWideBanners;

            if ((o.WideBanners != null) && (o.WideBanners.Count != 0))
                this.WideBanners = o.WideBanners;
            
            if ((o.AllBanners != null) && (o.AllBanners.Count != 0))
                this.AllBanners = o.AllBanners;

            if (betterLanguage)
                this.Language = o.Language;

            this.Dirty = o.Dirty;
        }
Esempio n. 7
0
 protected Episode(SeriesInfo ser)
 {
     SetDefaults(ser);
 }
Esempio n. 8
0
 public Episode(SeriesInfo ser, Season seas)
 {
     this.SetDefaults(ser, seas);
 }
Esempio n. 9
0
        // ReSharper disable once FunctionComplexityOverflow
        public void Merge([NotNull] SeriesInfo o, int preferredLanguageId)
        {
            if (o.TvdbCode != TvdbCode)
            {
                return; // that's not us!
            }

            if (o.SrvLastUpdated != 0 && o.SrvLastUpdated < SrvLastUpdated)
            {
                return; // older!?
            }

            bool currentLanguageNotSet = o.LanguageId == -1;
            bool newLanguageBetter     = o.LanguageId == preferredLanguageId && LanguageId != preferredLanguageId;
            bool betterLanguage        = currentLanguageNotSet || newLanguageBetter;

            SrvLastUpdated = o.SrvLastUpdated;

            // take the best bits of "o"
            // "o" is always newer/better than us, if there is a choice
            if ((!string.IsNullOrEmpty(o.Name)) && betterLanguage)
            {
                Name = o.Name;
            }

            AirsDay       = ChooseBetter(AirsDay, betterLanguage, o.AirsDay);
            Imdb          = ChooseBetter(Imdb, betterLanguage, o.Imdb);
            Overview      = ChooseBetter(Overview, betterLanguage, o.Overview);
            BannerString  = ChooseBetter(BannerString, betterLanguage, o.BannerString);
            Network       = ChooseBetter(Network, betterLanguage, o.Network);
            Runtime       = ChooseBetter(Runtime, betterLanguage, o.Runtime);
            SeriesId      = ChooseBetter(SeriesId, betterLanguage, o.SeriesId);
            Status        = ChooseBetter(Status, betterLanguage, o.Status);
            ContentRating = ChooseBetter(ContentRating, betterLanguage, o.ContentRating);

            if (betterLanguage && o.FirstAired.HasValue)
            {
                FirstAired = o.FirstAired;
            }

            if (!FirstAired.HasValue && o.FirstAired.HasValue)
            {
                FirstAired = o.FirstAired;
            }

            if (betterLanguage && o.SiteRating > 0)
            {
                SiteRating = o.SiteRating;
            }

            if (betterLanguage && o.SiteRatingVotes > 0)
            {
                SiteRatingVotes = o.SiteRatingVotes;
            }

            if (!aliases.Any() || (o.aliases.Any() && betterLanguage))
            {
                aliases = o.aliases;
            }

            if (!genres.Any() || (o.genres.Any() && betterLanguage))
            {
                genres = o.genres;
            }

            if (o.AirsTime != null)
            {
                AirsTime = o.AirsTime;
            }

            if ((o.AiredSeasons != null) && (o.AiredSeasons.Count != 0))
            {
                AiredSeasons = o.AiredSeasons;
            }

            if ((o.DvdSeasons != null) && (o.DvdSeasons.Count != 0))
            {
                DvdSeasons = o.DvdSeasons;
            }

            banners.MergeBanners(o.banners);

            if (betterLanguage)
            {
                LanguageId = o.LanguageId;
            }

            Dirty = o.Dirty;
        }
Esempio n. 10
0
        public void SetDefaults(SeriesInfo ser, Season seas)
        {
            this.Items = new System.Collections.Generic.Dictionary<string, string>();
            this.TheSeason = seas;
            this.TheSeries = ser;

            this.Overview = "";
            this.EpisodeRating = "";  
            this.EpisodeGuestStars = "";   
            this.EpisodeDirector = ""; 
            this.Writer = ""; 
            this.Name = "";
            this.EpisodeID = -1;
            this.SeriesID = -1;
            this.EpNum = -1;
            this.FirstAired = null;
            this.Srv_LastUpdated = -1;
            this.Dirty = false;
        }
Esempio n. 11
0
 public void SetSeriesSeason(SeriesInfo ser, Season seas)
 {
     this.TheSeason = seas;
     this.TheSeries = ser;
 }
Esempio n. 12
0
 public Banner(SeriesInfo ser, Season seas)
 {
     this.SetDefaults(ser, seas);
 }
Esempio n. 13
0
        private string GetSeasonImagesHTMLOverview(ShowItem si, SeriesInfo ser, int snum)
        {
            string body = "";

            Season s = ser.Seasons[snum];

            List<ProcessedEpisode> eis = null;
            // int snum = s.SeasonNumber;
            if (si.SeasonEpisodes.ContainsKey(snum))
                eis = si.SeasonEpisodes[snum]; // use processed episodes if they are available
            else
                eis = ShowItem.ProcessedListFromEpisodes(s.Episodes, si);

            string seasText = snum == 0 ? "Specials" : ("Season " + snum);
            if ((eis.Count > 0) && (eis[0].SeasonID > 0))
                seasText = " - <A HREF=\"" + TheTVDB.Instance.WebsiteURL(si.TVDBCode, eis[0].SeasonID, false) + "\">" + seasText + "</a>";
            else
                seasText = " - " + seasText;

            body += "<h1><A HREF=\"" + TheTVDB.Instance.WebsiteURL(si.TVDBCode, -1, true) + "\">" + si.ShowName + "</A>" + seasText + "</h1>";

            body += ImageSection("Series Banner", 758, 140, ser.GetSeasonWideBannerPath(snum));
            body += ImageSection("Series Poster", 350, 500, ser.GetSeasonBannerPath(snum));

            return body;
        }
Esempio n. 14
0
        public static List<ProcessedEpisode> GenerateEpisodes(ShowItem si, SeriesInfo ser, int snum, bool applyRules)
        {
            List<ProcessedEpisode> eis = new List<ProcessedEpisode>();

            if ((ser == null) || !ser.Seasons.ContainsKey(snum))
                return null; // todo.. something?

            Season seas = ser.Seasons[snum];

            if (seas == null)
                return null; // TODO: warn user

            foreach (Episode e in seas.Episodes)
                eis.Add(new ProcessedEpisode(e, si)); // add a copy

            if (si.DVDOrder)
            {
                eis.Sort(new System.Comparison<ProcessedEpisode>(ProcessedEpisode.DVDOrderSorter));
                Renumber(eis);
            }
            else
                eis.Sort(new System.Comparison<ProcessedEpisode>(ProcessedEpisode.EPNumberSorter));

            if (si.CountSpecials && ser.Seasons.ContainsKey(0))
            {
                // merge specials in
                foreach (Episode ep in ser.Seasons[0].Episodes)
                {
                    if (ep.Items.ContainsKey("airsbefore_season") && ep.Items.ContainsKey("airsbefore_episode"))
                    {
                        string seasstr = ep.Items["airsbefore_season"];
                        string epstr = ep.Items["airsbefore_episode"];
                        if ((string.IsNullOrEmpty(seasstr)) || (string.IsNullOrEmpty(epstr)))
                            continue;
                        int sease = int.Parse(seasstr);
                        if (sease != snum)
                            continue;
                        int epnum = int.Parse(epstr);
                        for (int i = 0; i < eis.Count; i++)
                        {
                            if ((eis[i].SeasonNumber == sease) && (eis[i].EpNum == epnum))
                            {
                                ProcessedEpisode pe = new ProcessedEpisode(ep, si)
                                                          {
                                                              TheSeason = eis[i].TheSeason,
                                                              SeasonID = eis[i].SeasonID
                                                          };
                                eis.Insert(i, pe);
                                break;
                            }
                        }
                    }
                }
                // renumber to allow for specials
                int epnumr = 1;
                for (int j = 0; j < eis.Count; j++)
                {
                    eis[j].EpNum2 = epnumr + (eis[j].EpNum2 - eis[j].EpNum);
                    eis[j].EpNum = epnumr;
                    epnumr++;
                }
            }

            if (applyRules)
            {
                List<ShowRule> rules = si.RulesForSeason(snum);
                if (rules != null)
                    ApplyRules(eis, rules, si);
            }

            return eis;
        }
Esempio n. 15
0
 public SeriesBanners(SeriesInfo s)
 {
     series = s;
 }
Esempio n. 16
0
        public static List <ProcessedEpisode> GenerateEpisodes(ShowItem si, SeriesInfo ser, int snum, bool applyRules)
        {
            List <ProcessedEpisode> eis = new List <ProcessedEpisode>();

            if (ser == null)
            {
                return(null);
            }

            Dictionary <int, Season> seasonsToUse = si.DVDOrder ? ser.DVDSeasons : ser.AiredSeasons;

            if (!seasonsToUse.ContainsKey(snum))
            {
                return(null); // todo.. something?
            }
            Season seas = seasonsToUse[snum];

            if (seas == null)
            {
                return(null); // TODO: warn user
            }
            foreach (Episode e in seas.Episodes)
            {
                eis.Add(new ProcessedEpisode(e, si)); // add a copy
            }
            if (si.DVDOrder)
            {
                eis.Sort(new System.Comparison <ProcessedEpisode>(ProcessedEpisode.DVDOrderSorter));
                Renumber(eis);
            }
            else
            {
                eis.Sort(new System.Comparison <ProcessedEpisode>(ProcessedEpisode.EPNumberSorter));
            }

            if (si.CountSpecials && seasonsToUse.ContainsKey(0))
            {
                // merge specials in
                foreach (Episode ep in seasonsToUse[0].Episodes)
                {
                    string seasstr = ep.AirsBeforeSeason;
                    string epstr   = ep.AirsBeforeEpisode;
                    if ((string.IsNullOrEmpty(seasstr)) || (string.IsNullOrEmpty(epstr)))
                    {
                        continue;
                    }
                    int sease = int.Parse(seasstr);
                    if (sease != snum)
                    {
                        continue;
                    }
                    int epnum = int.Parse(epstr);
                    for (int i = 0; i < eis.Count; i++)
                    {
                        if ((eis[i].AppropriateSeasonNumber == sease) && (eis[i].AppropriateEpNum == epnum))
                        {
                            ProcessedEpisode pe = new ProcessedEpisode(ep, si)
                            {
                                TheAiredSeason = eis[i].TheAiredSeason,
                                TheDVDSeason   = eis[i].TheDVDSeason,
                                SeasonID       = eis[i].SeasonID
                            };
                            eis.Insert(i, pe);
                            break;
                        }
                    }
                }
                // renumber to allow for specials
                int epnumr = 1;
                foreach (ProcessedEpisode t in eis)
                {
                    t.EpNum2           = epnumr + (t.EpNum2 - t.AppropriateEpNum);
                    t.AppropriateEpNum = epnumr;
                    epnumr++;
                }
            }

            if (applyRules)
            {
                List <ShowRule> rules = si.RulesForSeason(snum);
                if (rules != null)
                {
                    ApplyRules(eis, rules, si);
                }
            }

            return(eis);
        }
Esempio n. 17
0
        public bool GenerateEpisodeDict(ShowItem si)
        {
            si.SeasonEpisodes.Clear();

            // copy data from tvdb
            // process as per rules
            // done!

            TheTVDB.Instance.GetLock("GenerateEpisodeDict");

            SeriesInfo ser = TheTVDB.Instance.GetSeries(si.TVDBCode);

            if (ser == null)
            {
                TheTVDB.Instance.Unlock("GenerateEpisodeDict");
                return(false); // TODO: warn user
            }

            bool r = true;
            Dictionary <int, Season> seasonsToUse = si.DVDOrder ?
                                                    ser.DVDSeasons
                : ser.AiredSeasons;

            foreach (KeyValuePair <int, Season> kvp in seasonsToUse)
            {
                List <ProcessedEpisode> pel = GenerateEpisodes(si, ser, kvp.Key, true);
                si.SeasonEpisodes[kvp.Key] = pel;
                if (pel == null)
                {
                    r = false;
                }
            }

            List <int> theKeys = new List <int>();

            // now, go through and number them all sequentially
            foreach (int snum in seasonsToUse.Keys)
            {
                theKeys.Add(snum);
            }

            theKeys.Sort();

            int overallCount = 1;

            foreach (int snum in theKeys)
            {
                if (snum == 0)
                {
                    continue;
                }

                foreach (ProcessedEpisode pe in si.SeasonEpisodes[snum])
                {
                    pe.OverallNumber = overallCount;
                    if (si.DVDOrder)
                    {
                        overallCount += 1 + pe.EpNum2 - pe.DVDEpNum;
                    }
                    else
                    {
                        overallCount += 1 + pe.EpNum2 - pe.AiredEpNum;
                    }
                }
            }

            TheTVDB.Instance.Unlock("GenerateEpisodeDict");

            return(r);
        }
Esempio n. 18
0
        public static bool FindSeasEpDateCheck([CanBeNull] FileInfo fi, out int seas, out int ep, out int maxEp, [CanBeNull] ShowItem si)
        {
            ep    = -1;
            seas  = -1;
            maxEp = -1;

            if (fi is null || si is null)
            {
                return(false);
            }

            // look for a valid airdate in the filename
            // check for YMD, DMY, and MDY
            // only check against airdates we expect for the given show
            SeriesInfo ser = TheTVDB.Instance.GetSeries(si.TvdbCode);

            if (ser is null)
            {
                return(false);
            }

            string[] dateFormats = { "yyyy-MM-dd", "dd-MM-yyyy", "MM-dd-yyyy", "yy-MM-dd", "dd-MM-yy", "MM-dd-yy" };
            string   filename    = fi.Name;

            if (filename is null)
            {
                return(false);
            }
            // force possible date separators to a dash
            filename = filename.Replace("/", "-");
            filename = filename.Replace(".", "-");
            filename = filename.Replace(",", "-");
            filename = filename.Replace(" ", "-");

            Dictionary <int, Season> seasonsToUse = si.DvdOrder ? ser.DvdSeasons : ser.AiredSeasons;

            if (seasonsToUse is null)
            {
                return(false);
            }

            foreach (KeyValuePair <int, Season> kvp in seasonsToUse)
            {
                if (kvp.Value?.Episodes?.Values is null)
                {
                    continue;
                }

                if (!(si.IgnoreSeasons is null) && (si.IgnoreSeasons.Contains(kvp.Value.SeasonNumber)))
                {
                    continue;
                }

                if ((kvp.Value.SeasonNumber == 0) && TVSettings.Instance.IgnoreAllSpecials)
                {
                    continue;
                }

                foreach (Episode epi in kvp.Value.Episodes.Values)
                {
                    DateTime?dt = epi.GetAirDateDt();  // file will have local timezone date, not ours
                    if (dt is null)
                    {
                        continue;
                    }

                    TimeSpan closestDate = TimeSpan.MaxValue;

                    foreach (string dateFormat in dateFormats)
                    {
                        string datestr = dt.Value.ToString(dateFormat);

                        if (filename.Contains(datestr) && DateTime.TryParseExact(datestr, dateFormat,
                                                                                 new CultureInfo("en-GB"), DateTimeStyles.None, out DateTime dtInFilename))
                        {
                            TimeSpan timeAgo = DateTime.Now.Subtract(dtInFilename);

                            if (timeAgo < closestDate)
                            {
                                seas        = (si.DvdOrder ? epi.DvdSeasonNumber : epi.AiredSeasonNumber);
                                ep          = si.DvdOrder ? epi.DvdEpNum : epi.AiredEpNum;
                                closestDate = timeAgo;
                            }
                        }
                    }
                }
            }

            return((ep != -1) && (seas != -1));
        }
Esempio n. 19
0
        private static (ProcessedEpisode firstMatchingPep, bool fileCanBeDeleted) FirstMatchingPep(bool unattended,
                                                                                                   DirFilesCache dfc, FileInfo fi, List <ShowItem> matchingShows, SeriesInfo s, int seasF, int epF, ShowItem si,
                                                                                                   ProcessedEpisode firstMatchingPep, List <Item> returnActions, [CanBeNull] TVSettings.FilenameProcessorRE re, bool fileCanBeDeleted)
        {
            try
            {
                Episode          ep  = s.GetEpisode(seasF, epF, si.DvdOrder);
                ProcessedEpisode pep = new ProcessedEpisode(ep, si);
                firstMatchingPep = pep;
                List <FileInfo> encumbants = dfc.FindEpOnDisk(pep, false);

                if (encumbants.Count == 0)
                {
                    //File is needed as there are no files for that series/episode
                    fileCanBeDeleted = false;

                    returnActions.AddRange(CopyFutureDatedFile(fi, pep));
                }
                else
                {
                    foreach (FileInfo existingFile in encumbants)
                    {
                        if (existingFile.FullName.Equals(fi.FullName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            //the user has put the search folder and the download folder in the same place - DO NOT DELETE
                            fileCanBeDeleted = false;
                            continue;
                        }

                        fileCanBeDeleted = ReviewFile(unattended, fi, matchingShows, existingFile, fileCanBeDeleted,
                                                      returnActions, pep);
                    }
                }
            }
            catch (SeriesInfo.EpisodeNotFoundException)
            {
                LOGGER.Info(
                    $"Can't find the right episode for {fi.FullName} coming out as S{seasF}E{epF} using rule '{re?.Notes}'");

                fileCanBeDeleted = false;
            }

            return(firstMatchingPep, fileCanBeDeleted);
        }
Esempio n. 20
0
        public void SetDefaults(SeriesInfo ser, Season seas)
        {
            this.TheSeason = seas;
            this.TheSeries = ser;


            this.BannerId = -1;
            this.BannerPath = "";
            this.BannerType = "";
            this.BannerType2 = "";
            this.Language = "";
            this.Rating = -1;
            this.RatingCount = 0;
            this.SeasonID = -1;
            this.SeriesID = -1;

            this.Colors = "";
            this.ThumbnailPath = "";
            this.VignettePath = "";
            this.SeriesName = "";

        }
Esempio n. 21
0
        private string GetShowHTMLOverview(ShowItem si, SeriesInfo ser)
        {
            string body =""; 

            List<string> skip = new List<String>
                                  {
                                      "Actors",
                                      "banner",
                                      "Overview",
                                      "Airs_Time",
                                      "Airs_DayOfWeek",
                                      "fanart",
                                      "poster",
                                      "zap2it_id"
                                  };

            
            if ((!string.IsNullOrEmpty(ser.GetItem("banner"))) && (!string.IsNullOrEmpty(TheTVDB.Instance.BannerMirror)))
                body += "<img width=758 height=140 src=\"" + TheTVDB.Instance.BannerMirror + "/banners/" + ser.GetItem("banner") + "\"><br/>";

            body += "<h1><A HREF=\"" + TheTVDB.Instance.WebsiteURL(si.TVDBCode, -1, true) + "\">" + si.ShowName + "</A> " + "</h1>";

            body += "<h2>Overview</h2>" + ser.GetItem("Overview");

            string actors = ser.GetItem("Actors");
            if (!string.IsNullOrEmpty(actors))
            {
                bool first = true;
                foreach (string aa in actors.Split('|'))
                {
                    if (!string.IsNullOrEmpty(aa))
                    {
                        if (!first)
                            body += ", ";
                        else
                            body += "<h2>Actors</h2>";
                        body += "<A HREF=\"http://www.imdb.com/find?s=nm&q=" + aa + "\">" + aa + "</a>";
                        first = false;
                    }
                }
            }

            string airsTime = ser.GetItem("Airs_Time");
            string airsDay = ser.GetItem("Airs_DayOfWeek");
            if ((!string.IsNullOrEmpty(airsTime)) && (!string.IsNullOrEmpty(airsDay)))
            {
                body += "<h2>Airs</h2> " + airsTime + " " + airsDay;
                string net = ser.GetItem("Network");
                if (!string.IsNullOrEmpty(net))
                {
                    skip.Add("Network");
                    body += ", " + net;
                }
            }

            bool firstInfo = true;
            foreach (System.Collections.Generic.KeyValuePair<string, string> kvp in ser.Items)
            {
                if (firstInfo)
                {
                    body += "<h2>Information<table border=0>";
                    firstInfo = false;
                }
                if (!skip.Contains(kvp.Key))
                {
                    if (kvp.Key == "SeriesID")
                        body += "<tr><td width=120px>tv.com</td><td><A HREF=\"http://www.tv.com/show/" + kvp.Value + "/summary.html\">Visit</a></td></tr>";
                    else if (kvp.Key == "IMDB_ID")
                        body += "<tr><td width=120px>imdb.com</td><td><A HREF=\"http://www.imdb.com/title/" + kvp.Value + "\">Visit</a></td></tr>";
                    else
                        body += "<tr><td width=120px>" + kvp.Key + "</td><td>" + kvp.Value + "</td></tr>";
                }
            }
            if (!firstInfo)
                body += "</table>";

            return body;

        }
Esempio n. 22
0
        private string GetSeasonHTMLOverview(ShowItem si,SeriesInfo ser, int snum ) {
            string body = "";

            if (!string.IsNullOrEmpty(ser.GetItem("banner")) && !string.IsNullOrEmpty(TheTVDB.Instance.BannerMirror))
                body += "<img width=758 height=140 src=\"" + TheTVDB.Instance.BannerMirror + "/banners/" + ser.GetItem("banner") + "\"><br/>";

            Season s = ser.Seasons[snum];

            List<ProcessedEpisode> eis = null;
            // int snum = s.SeasonNumber;
            if (si.SeasonEpisodes.ContainsKey(snum))
                eis = si.SeasonEpisodes[snum]; // use processed episodes if they are available
            else
                eis = ShowItem.ProcessedListFromEpisodes(s.Episodes, si);

            string seasText = snum == 0 ? "Specials" : ("Season " + snum);
            if ((eis.Count > 0) && (eis[0].SeasonID > 0))
                seasText = " - <A HREF=\"" + TheTVDB.Instance.WebsiteURL(si.TVDBCode, eis[0].SeasonID, false) + "\">" + seasText + "</a>";
            else
                seasText = " - " + seasText;

            body += "<h1><A HREF=\"" + TheTVDB.Instance.WebsiteURL(si.TVDBCode, -1, true) + "\">" + si.ShowName + "</A>" + seasText + "</h1>";

            DirFilesCache dfc = new DirFilesCache();
            foreach (ProcessedEpisode ei in eis)
            {
                string epl = ei.NumsAsString();

                // http://www.thetvdb.com/?tab=episode&seriesid=73141&seasonid=5356&id=108303&lid=7
                string episodeURL = "http://www.thetvdb.com/?tab=episode&seriesid=" + ei.SeriesID + "&seasonid=" + ei.SeasonID + "&id=" + ei.EpisodeID;

                body += "<A href=\"" + episodeURL + "\" name=\"ep" + epl + "\">"; // anchor
                body += "<b>" + CustomName.NameForNoExt(ei, CustomName.OldNStyle(6)) + "</b>";
                body += "</A>"; // anchor
                if (si.UseSequentialMatch && (ei.OverallNumber != -1))
                    body += " (#" + ei.OverallNumber + ")";

                body += " <A HREF=\"" + TVSettings.Instance.BTSearchURL(ei) + "\" class=\"search\">Search</A>";

                List<FileInfo> fl = this.mDoc.FindEpOnDisk(dfc, ei);
                if (fl != null)
                {
                    foreach (FileInfo fi in fl)
                        body += " <A HREF=\"file://" + fi.FullName + "\" class=\"search\">Watch</A>";
                }

                DateTime? dt = ei.GetAirDateDT(true);
                if ((dt != null) && (dt.Value.CompareTo(DateTime.MaxValue) != 0))
                    body += "<p>" + dt.Value.ToShortDateString() + " (" + ei.HowLong() + ")";

                body += "<p><p>";

                if (TVSettings.Instance.ShowEpisodePictures)
                {
                    body += "<table><tr>";
                    body += "<td width=100% valign=top>" + ei.Overview + "</td><td width=300 height=225>";
                    // 300x168 / 300x225
                    if (!string.IsNullOrEmpty(ei.GetItem("filename")))
                        body += "<img src=" + TheTVDB.Instance.BannerMirror + "/banners/_cache/" + ei.GetItem("filename") + ">";
                    body += "</td></tr></table>";
                }
                else
                    body += ei.Overview;

                body += "<p><hr><p>";
            } // for each episode in this season

            return body;
        }
Esempio n. 23
0
        public bool ProcessTVDBResponse(Stream str, int? codeHint)
        {
            // Will have one or more series, and episodes
            // all wrapped in <Data> </Data>

            // e.g.: 
            //<Data>
            // <Series>
            //  <id>...</id>
            //  etc.
            // </Series>
            // <Episode>
            //  <id>...</id>
            //  blah blah
            // </Episode>
            // <Episode>
            //  <id>...</id>
            //  blah blah
            // </Episode>
            // ...
            //</Data>

            if (!this.GetLock("ProcessTVDBResponse"))
                return false;

            try
            {
                XmlReaderSettings settings = new XmlReaderSettings
                {
                    IgnoreComments = true,
                    IgnoreWhitespace = true
                };
                XmlReader r = XmlReader.Create(str, settings);

                r.Read();

                while (!r.EOF)
                {
                    if ((r.Name == "Data") && !r.IsStartElement())
                        break; // that's it.
                    if (r.Name == "Series")
                    {
                        // The <series> returned by GetSeries have
                        // less info than other results from
                        // thetvdb.com, so we need to smartly merge
                        // in a <Series> if we already have some/all
                        // info on it (depending on which one came
                        // first).

                        SeriesInfo si = new SeriesInfo(r.ReadSubtree());
                        if (this.Series.ContainsKey(si.TVDBCode))
                            this.Series[si.TVDBCode].Merge(si, this.RequestLanguage);
                        else
                            this.Series[si.TVDBCode] = si;
                        r.Read();
                    }
                    else if (r.Name == "Episode")
                    {
                        Episode e = new Episode(null, null, r.ReadSubtree(), Args);
                        if (e.OK())
                        {
                            if (!this.Series.ContainsKey(e.SeriesID))
                                throw new TVDBException("Can't find the series to add the episode to (TheTVDB).");
                            SeriesInfo ser = this.Series[e.SeriesID];
                            Season seas = ser.GetOrAddSeason(e.ReadSeasonNum, e.SeasonID);

                            bool added = false;
                            for (int i = 0; i < seas.Episodes.Count; i++)
                            {
                                Episode ep = seas.Episodes[i];
                                if (ep.EpisodeID == e.EpisodeID)
                                {
                                    seas.Episodes[i] = e;
                                    added = true;
                                    break;
                                }
                            }
                            if (!added)
                                seas.Episodes.Add(e);
                            e.SetSeriesSeason(ser, seas);
                        }
                        r.Read();
                    }
                    else if (r.Name == "xml")
                        r.Read();
                    else if (r.Name == "BannersCache")
                    {
                        //this wil not be found in a standard response from the TVDB website
                        //will only be in the response when we are reading from the cache
                        ProcessTVDBBannerCacheResponse(r);
                        r.Read();
                    }
                    else if (r.Name == "Data")
                    {
                        string time = r.GetAttribute("time");
                        if (time != null)
                            this.New_Srv_Time = int.Parse(time);
                        r.Read();
                    }
                    else
                        r.ReadOuterXml();
                }
            }
            catch (XmlException e)
            {
                if (!this.Args.Unattended)
                {
                    string message = "Error processing data from TheTVDB (top level).";
                    message += "\r\n" + e.Message;
                    String name = "";
                    if (codeHint.HasValue && Series.ContainsKey(codeHint.Value))
                    {
                        name += "Show \"" + Series[codeHint.Value].Name + "\" ";
                    }
                    if (codeHint.HasValue)
                    {
                        name += "ID #" + codeHint.Value + " ";
                    }
                    MessageBox.Show(name + message, "TVRename", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    // throw new TVDBException(e.Message);
                }
                return false;
            }
            finally
            {
                this.Unlock("ProcessTVDBResponse");
            }
            return true;
        }
Esempio n. 24
0
        public Banner(SeriesInfo ser, Season seas, int? codeHint, XmlReader r, CommandLineArgs args)
        {
            // <Banner>
            //        <id>708811</id>
            //        <BannerPath>seasonswide/79488-5.jpg</BannerPath>
            //        <BannerType>season</BannerType>
            //        <BannerType2>seasonwide</BannerType2>
            //        <Language>en</Language>
            //        <Rating/>
            //        <RatingCount>0</RatingCount>
            //        <Season>5</Season>
            //  blah blah
            // </Banner>



            try
            {
                this.SetDefaults(ser, seas);

                this.SeriesID = (int) codeHint;

                r.Read();
                if (r.Name != "Banner")
                    return;

                r.Read();
                while (!r.EOF)
                {
                    if ((r.Name == "Banner") && (!r.IsStartElement()))
                        break;

                    if (r.Name == "id")
                        this.BannerId = r.ReadElementContentAsInt();
                    else if (r.Name == "seriesid")
                        this.SeriesID = r.ReadElementContentAsInt(); // thetvdb series id
                    else if (r.Name == "seasonid")
                        this.SeasonID = r.ReadElementContentAsInt();
                    else if (r.Name == "BannerPath")
                        this.BannerPath = XMLHelper.ReadStringFixQuotesAndSpaces(r);
                    else if (r.Name == "BannerType")
                        this.BannerType = r.ReadElementContentAsString();
                    else if (r.Name == "BannerType2")
                        this.BannerType2 = r.ReadElementContentAsString();
                    else if (r.Name == "Language")
                        this.Language = r.ReadElementContentAsString();
                    else if (r.Name == "Rating")
                        {
                        String sn = r.ReadElementContentAsString();
                        double.TryParse(sn, out this.Rating);
                        }
                    else if (r.Name == "RatingCount")
                        this.RatingCount  = r.ReadElementContentAsInt();
                    else if (r.Name == "Season")
                        this.SeasonID = r.ReadElementContentAsInt();
                    else if (r.Name == "Colors") this.Colors = r.ReadElementContentAsString();
                    else if (r.Name == "ThumbnailPath") this.ThumbnailPath = r.ReadElementContentAsString();
                    else if (r.Name == "VignettePath") this.VignettePath = r.ReadElementContentAsString();
                    else if (r.Name == "SeriesName") this.SeriesName = r.ReadElementContentAsString();
                    else
                    {
                        if ((r.IsEmptyElement) || !r.IsStartElement())
                            r.ReadOuterXml();
                        else
                            r.Read();
                    }
                }
            }
            catch (XmlException e)
            {
                string message = "Error processing data from TheTVDB for a banner.";
                if (this.SeriesID != -1)
                    message += "\r\nSeries ID: " + this.SeriesID;
                if (this.BannerId != -1)
                    message += "\r\nBanner ID: " + this.BannerId;
                if (!string.IsNullOrEmpty(this.BannerPath))
                    message += "\r\nBanner Path: " + this.BannerPath;
                if (!string.IsNullOrEmpty(this.Name))
                    message += "\r\nName: " + this.Name;

                message += "\r\n" + e.Message;

                if (!args.Unattended) 
                    MessageBox.Show(message, "TVRename", MessageBoxButtons.OK, MessageBoxIcon.Error);

                throw new TVDBException(e.Message);
            }
        }
Esempio n. 25
0
        public void Merge(SeriesInfo o, int preferredLanguageId)
        {
            if (o.TvdbCode != TvdbCode)
            {
                return; // that's not us!
            }
            if (o.SrvLastUpdated != 0 && o.SrvLastUpdated < SrvLastUpdated)
            {
                return; // older!?
            }
            bool currentLanguageNotSet = o.languageId == -1;
            bool newLanguageBetter     = o.languageId == preferredLanguageId && languageId != preferredLanguageId;
            bool betterLanguage        = currentLanguageNotSet || newLanguageBetter;

            SrvLastUpdated = o.SrvLastUpdated;

            // take the best bits of "o"
            // "o" is always newer/better than us, if there is a choice
            if ((!string.IsNullOrEmpty(o.Name)) && betterLanguage)
            {
                Name = o.Name;
            }
            // this.Items.Clear();
            foreach (KeyValuePair <string, string> kvp in o.items)
            {
                // on offer is non-empty text, in a better language
                // or text for something we don't have
                if ((!string.IsNullOrEmpty(kvp.Value) && betterLanguage) ||
                    (!items.ContainsKey(kvp.Key) || string.IsNullOrEmpty(items[kvp.Key])))
                {
                    items[kvp.Key] = kvp.Value;
                }
            }
            if (o.AirsTime != null)
            {
                AirsTime = o.AirsTime;
            }

            if ((o.AiredSeasons != null) && (o.AiredSeasons.Count != 0))
            {
                AiredSeasons = o.AiredSeasons;
            }
            if ((o.DvdSeasons != null) && (o.DvdSeasons.Count != 0))
            {
                DvdSeasons = o.DvdSeasons;
            }

            if ((o.seasonBanners != null) && (o.seasonBanners.Count != 0))
            {
                seasonBanners = o.seasonBanners;
            }

            if ((o.seasonLangBanners != null) && (o.seasonLangBanners.Count != 0))
            {
                seasonLangBanners = o.seasonLangBanners;
            }

            if ((o.seasonLangWideBanners != null) && (o.seasonLangWideBanners.Count != 0))
            {
                seasonLangWideBanners = o.seasonLangWideBanners;
            }

            if ((o.seasonWideBanners != null) && (o.seasonWideBanners.Count != 0))
            {
                seasonWideBanners = o.seasonWideBanners;
            }

            if ((o.AllBanners != null) && (o.AllBanners.Count != 0))
            {
                AllBanners = o.AllBanners;
            }

            if ((o.bestSeriesPosterId != -1))
            {
                bestSeriesPosterId = o.bestSeriesPosterId;
            }
            if ((o.bestSeriesBannerId != -1))
            {
                bestSeriesBannerId = o.bestSeriesBannerId;
            }
            if ((o.bestSeriesFanartId != -1))
            {
                bestSeriesFanartId = o.bestSeriesFanartId;
            }
            if ((o.bestSeriesLangPosterId != -1))
            {
                bestSeriesLangPosterId = o.bestSeriesLangPosterId;
            }
            if ((o.bestSeriesLangBannerId != -1))
            {
                bestSeriesLangBannerId = o.bestSeriesLangBannerId;
            }
            if ((o.bestSeriesLangFanartId != -1))
            {
                bestSeriesLangFanartId = o.bestSeriesLangFanartId;
            }

            if (betterLanguage)
            {
                languageId = o.languageId;
            }

            Dirty = o.Dirty;
        }