Пример #1
0
        /// <summary>
        /// Handles the DoWork event of the Bgw control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param>
        private void Bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            string logCategory = "FrmImportTv > Bgw_DoWork";
            this.theTvdb = new TheTvdb();

            var toAdd = new Dictionary<string, ScanSeries>();
            var toRemove = new List<string>();

            Factories.UI.Windows7UIFactory.StartProgressState(ImportTvFactory.Scan.Count);

            var count = 0;

            InternalApps.Logs.Log.WriteToLog(LogSeverity.Debug, 0, string.Format("Starting import of tv series. {0} shows to scan.",
                    ImportTvFactory.Scan.Count), logCategory);

            foreach (var s in ImportTvFactory.Scan)
            {
                InternalApps.Logs.Log.WriteToLog(LogSeverity.Debug, 0, string.Format("Starting import of show {0}",
                    s.Key), logCategory);

                Factories.UI.Windows7UIFactory.SetProgressValue(count);

                var item = (from series in ImportTvFactory.SeriesNameList
                     where series.SeriesName == s.Key && series.WaitingForScan
                     select series).SingleOrDefault();

                this.currentIndex = gridView1.GetRowHandle(ImportTvFactory.SeriesNameList.IndexOf(item));

                if (item != null)
                {
                    if (!string.IsNullOrEmpty(s.Key))
                    {
                        this.currentStatus = "Processing " + s.Key;
                        InternalApps.Logs.Log.WriteToLog(LogSeverity.Info, 0, string.Format("Processing {0}",
                            s.Key), logCategory);

                        var searchResults = TvDBFactory.SearchDefaultShowDatabase(s.Key);

                        if (searchResults.Count == 0)
                        {
                            InternalApps.Logs.Log.WriteToLog(LogSeverity.Debug, 0, string.Format("{0} was not found in default show database. Trying TvDB",
                                s.Key), logCategory);
                            searchResults = this.theTvdb.SeriesSearch(Tools.Clean.Text.UrlEncode(s.Key)); // open initial object and do search
                        }

                        Series series;

                        if (searchResults.Count > 1 || searchResults.Count == 0)
                        {
                            InternalApps.Logs.Log.WriteToLog(LogSeverity.Debug, 0, string.Format("{0} results was found",
                                searchResults.Count), logCategory);

                           var scan =
                                (from scanSeriesPick in ImportTvFactory.ScanSeriesPicks
                                 where scanSeriesPick.SearchString == s.Key
                                 select scanSeriesPick).SingleOrDefault();

                            if (scan != null)
                            {

                                InternalApps.Logs.Log.WriteToLog(LogSeverity.Debug, 0, string.Format("Attempting to search for {0} based on scanSeriesPick.",
                                    scan.SeriesName), logCategory);

                                searchResults = this.theTvdb.SeriesSearch(Tools.Clean.Text.UrlEncode(scan.SeriesName));
                                
                                var result = (from r in searchResults where r.SeriesID == scan.SeriesID select r).Single();
                                series = this.theTvdb.OpenNewSeries(result);
                                
                                InternalApps.Logs.Log.WriteToLog(LogSeverity.Info, 0, string.Format("{0} was found to have ID {1} (IMDb: {2})",
                                    series.SeriesName, series.ID, series.ImdbId), logCategory);
                            }
                            else
                            {
                                InternalApps.Logs.Log.WriteToLog(LogSeverity.Debug, 0, string.Format("{0} was not found in scanSeriesPick",
                                    s.Key), logCategory);

                                var resultCollection = new List<object>(4)
                                    { 
                                        searchResults, 
                                        s.Key, 
                                        s.Value, 
                                        toAdd, 
                                        toRemove 
                                    };

                                e.Result = resultCollection;

                                return;
                            }
                        }
                        else
                        {
                            series = this.theTvdb.OpenNewSeries(searchResults[0]); // download series details
                            InternalApps.Logs.Log.WriteToLog(LogSeverity.Debug, 0, string.Format("{0} was found to have ID {1} (IMDb: {2})",
                                    series.SeriesName, series.ID, series.ImdbId), logCategory);

                            if ((from scan in ImportTvFactory.ScanSeriesPicks where scan.SearchString == s.Key select s).Count() == 0)
                            {
                                ImportTvFactory.ScanSeriesPicks.Add(
                                    new ScanSeriesPick
                                        {
                                            SearchString = s.Key,
                                            SeriesID = series.SeriesID.ToString(),
                                            SeriesName = series.SeriesName
                                        });
                                InternalApps.Logs.Log.WriteToLog(LogSeverity.Debug, 0, string.Format("{0} was added to scanSeriesPick",
                                    series.SeriesName), logCategory);
                            }
                        }

                        this.Set(series, toRemove, toAdd, s.Key, s.Value);
                    }
                }

                this.count++;

                this.bgw.ReportProgress(this.count);

                if (this.bgw.CancellationPending)
                {
                    return;
                }

                count++;
            }

            foreach (var s in toRemove)
            {
                ImportTvFactory.Scan.Remove(s);
                InternalApps.Logs.Log.WriteToLog(LogSeverity.Debug, 0, string.Format("Removing {0} from scan database",
                    s), logCategory);
            }

            foreach (var s in toAdd)
            {
                ImportTvFactory.Scan.Add(s.Key, s.Value);
                InternalApps.Logs.Log.WriteToLog(LogSeverity.Debug, 0, string.Format("Adding {0} to scan database",
                    s), logCategory);
            }

            this.theTvdb.ApplyScan();

            Factories.UI.Windows7UIFactory.StopProgressState();
        }
Пример #2
0
        private void BgwDoWork(object sender, DoWorkEventArgs e)
        {
            this.theTvdb = new TheTvdb();

            var toAdd = new Dictionary<string, ScanSeries>();
            var toRemove = new List<string>();

            foreach (var s in ImportTvFactory.Scan)
            {
                if (
                    (from series in ImportTvFactory.SeriesNameList
                     where series.SeriesName == s.Key && series.WaitingForScan
                     select series).SingleOrDefault() != null)
                {
                    if (!string.IsNullOrEmpty(s.Key))
                    {
                        this.currentStatus = "Processing " + s.Key;

                        var searchResults = this.theTvdb.SeriesSearch(s.Key); // open initial object and do search

                        Series series;

                        if (searchResults.Count > 1 || searchResults.Count == 0)
                        {
                           var scan =
                                (from scanSeriesPick in ImportTvFactory.ScanSeriesPicks
                                 where scanSeriesPick.SearchString == s.Key
                                 select scanSeriesPick).SingleOrDefault();

                            if (scan != null)
                            {
                                searchResults = this.theTvdb.SeriesSearch(scan.SeriesName);

                                var result = (from r in searchResults where r.SeriesID == scan.SeriesID select r).Single();
                                series = this.theTvdb.OpenNewSeries(result);
                            }
                            else
                            {
                            
                                var resultCollection = new List<object>(4)
                                    { 
                                        searchResults, 
                                        s.Key, 
                                        s.Value, 
                                        toAdd, 
                                        toRemove 
                                    };

                                e.Result = resultCollection;

                                return;
                            }
                        }
                        else
                        {
                            series = this.theTvdb.OpenNewSeries(searchResults[0]); // download series details
                        }

                        this.Set(series, toRemove, toAdd, s.Key, s.Value);
                    }
                }

                this.count++;
                this.bgw.ReportProgress(this.count);

                if (bgw.CancellationPending)
                {
                    return;
                }
            }

            foreach (var s in toRemove)
            {
                ImportTvFactory.Scan.Remove(s);
            }

            foreach (var s in toAdd)
            {
                ImportTvFactory.Scan.Add(s.Key, s.Value);
            }

            this.theTvdb.ApplyScan();
        }
Пример #3
0
        /// <summary>
        /// Handles the Click event of the ButSearchAgain control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data.
        /// </param>
        private void ButSearchAgain_Click(object sender, EventArgs e)
        {
            this.butSearchAgain.Enabled = false;
            this.butUse.Enabled = false;
            this.butCancel.Enabled = false;

            var theTvdb = new TheTvdb();

            this.searchDetails = theTvdb.SeriesSearch(this.txtSearchAgain.Text);
            this.Setup(this.searchDetails, this.txtSearchAgain.Text);

            this.butSearchAgain.Enabled = true;
            this.butUse.Enabled = true;
            this.butCancel.Enabled = true;
        }
Пример #4
0
        /// <summary>
        /// Handles the DoWork event of the bgwScan control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.
        /// </param>
        private void BgwScan_DoWork(object sender, DoWorkEventArgs e)
        {
            var tvdb = new TheTvdb();
            int count = 0;

            foreach (UpdateTvRecords series in this.updateDatabase)
            {
                this.bgwScan.ReportProgress(0, series.SeriesName);

                Series seriesObj = TvDBFactory.GetSeriesFromName(series.SeriesName);

                Series newSeries = tvdb.CheckForUpdate(seriesObj.SeriesID, seriesObj.Language, seriesObj.Lastupdated);

                if (newSeries != null)
                {
                    series.NewTime = newSeries.Lastupdated;
                    count++;
                }
            }

            e.Result = count;
        }
Пример #5
0
        /// <summary>
        /// Update series from TvDB database.
        /// </summary>
        /// <param name="seriesId">
        /// The series id.
        /// </param>
        public static void UpdateSeries(uint? seriesId)
        {
            Series seriesObj = GetSeriesFromSeriesId(seriesId);

            var tvdb = new TheTvdb();

            Series newSeries = tvdb.CheckForUpdate(seriesObj.SeriesID, seriesObj.Language, seriesObj.Lastupdated);

            if (!seriesObj.IsLocked)
            {
                seriesObj.Added = newSeries.Added;
                seriesObj.AddedBy = newSeries.AddedBy;
                seriesObj.AirsDayOfWeek = newSeries.AirsDayOfWeek;
                seriesObj.AirsTime = newSeries.AirsTime;
                seriesObj.ContentRating = newSeries.ContentRating;
                seriesObj.Country = newSeries.Country;
                seriesObj.Genre = newSeries.Genre;
                seriesObj.ImdbId = newSeries.ImdbId;
                seriesObj.Language = newSeries.ImdbId;
                seriesObj.Lastupdated = newSeries.Lastupdated;
                seriesObj.Network = newSeries.Lastupdated;
                seriesObj.NetworkID = newSeries.NetworkID;
                seriesObj.Overview = newSeries.Overview;
                seriesObj.Rating = newSeries.Rating;
                seriesObj.Runtime = newSeries.Runtime;
                seriesObj.SeriesName = newSeries.SeriesName;
                seriesObj.Status = newSeries.Status;
                seriesObj.Zap2It_Id = newSeries.Zap2It_Id;

                if (string.IsNullOrEmpty(seriesObj.SeriesBannerPath) && string.IsNullOrEmpty(seriesObj.SeriesBannerUrl))
                {
                    seriesObj.SeriesBannerUrl = newSeries.SeriesBannerUrl;
                }

                if (string.IsNullOrEmpty(seriesObj.PosterUrl) && string.IsNullOrEmpty(seriesObj.PosterPath))
                {
                    seriesObj.PosterUrl = newSeries.PosterUrl;
                }

                if (string.IsNullOrEmpty(seriesObj.FanartUrl) && string.IsNullOrEmpty(seriesObj.FanartPath))
                {
                    seriesObj.FanartUrl = newSeries.FanartUrl;
                }
            }

            foreach (var season in newSeries.Seasons)
            {
                UpdateSeason(seriesObj, season.Value);
            }
        }
Пример #6
0
        /// <summary>
        /// Handles the Click event of the btnSearch control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtSearch.Text))
            {
                XtraMessageBox.Show("Please enter a series to search for in the 'Add New Series' field.", "Empty search string");
                return;
            }

            this.btnSearch.Enabled = false;
            this.txtSearch.Enabled = false;

            var theTvdb = new TheTvdb();
            theTvdb.DoFullSearch(this.txtSearch.Text);
            this.UpdateDataBindings();
            
            this.btnSearch.Enabled = true;
            this.txtSearch.Enabled = true;
            this.txtSearch.Text = string.Empty;
        }
Пример #7
0
        /// <summary>
        /// Handles the DoWork event of the bgwScan control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.
        /// </param>
        private void BgwScan_DoWork(object sender, DoWorkEventArgs e)
        {
            var tvdb = new TheTvdb();
            int count = 0;

            foreach (UpdateTvRecords record in this.updateDatabase)
            {
                InternalApps.Logs.Log.WriteToLog(
                            LogSeverity.Debug,
                            0,
                            "UI > Dialogs > TV > FrmUpdateShows > BgwScan_DoWork",
                            string.Format(
                                "Checking {0} {1}x{2:00} for update",
                                record.SeriesName, record.SeasonNumber.GetValueOrDefault(0), record.EpisodeNumber.GetValueOrDefault(0)
                            )
                );

                this.bgwScan.ReportProgress(0, record);

                Series seriesObj = TvDBFactory.GetSeriesFromName(record.SeriesName);

                Series newSeries = tvdb.CheckForUpdate(seriesObj.SeriesID, seriesObj.Language, seriesObj.Lastupdated);

                if (newSeries != null)
                {
                    InternalApps.Logs.Log.WriteToLog(
                                LogSeverity.Debug,
                                0,
                                "UI > Dialogs > TV > FrmUpdateShows > BgwScan_DoWork",
                                string.Format(
                                    "Update found for {0} {1}x{2:00}",
                                    record.SeriesName, record.SeasonNumber.GetValueOrDefault(0), record.EpisodeNumber.GetValueOrDefault(0)
                                )
                    );

                    record.NewTime = newSeries.Lastupdated;
                    count++;
                }
            }

            e.Result = count;
        }
Пример #8
0
        /// <summary>
        /// Update series from TvDB database.
        /// </summary>
        /// <param name="seriesId">
        /// The series id.
        /// </param>
        public static void UpdateSeries(uint? seriesId, int? seasonNumber = null, int? episodeNumber = null)
        {
            Series seriesObj = GetSeriesFromSeriesId(seriesId);

            InternalApps.Logs.Log.WriteToLog(
                        LogSeverity.Debug,
                        0,
                        "Factories > TvDBFactory > UpdateSeries",
                        string.Format(
                            "Called with seriesId {0}({1}), seasonNumber {2}, episodeNumber {3}",
                            seriesId.GetValueOrDefault(0), seriesObj.SeriesName, seasonNumber.GetValueOrDefault(0), episodeNumber.GetValueOrDefault(0)
                        )
            );

            var tvdb = new TheTvdb();

            Series newSeries = tvdb.CheckForUpdate(seriesObj.SeriesID, seriesObj.Language, seriesObj.Lastupdated, true);

            if (!seriesObj.IsLocked && seasonNumber == null && episodeNumber == null)
            {
                seriesObj.Added = newSeries.Added;
                seriesObj.AddedBy = newSeries.AddedBy;
                seriesObj.AirsDayOfWeek = newSeries.AirsDayOfWeek;
                seriesObj.AirsTime = newSeries.AirsTime;
                seriesObj.ContentRating = newSeries.ContentRating;
                seriesObj.Country = newSeries.Country;
                seriesObj.Genre = newSeries.Genre;
                seriesObj.ImdbId = newSeries.ImdbId;
                seriesObj.Language = newSeries.ImdbId;
                seriesObj.Lastupdated = newSeries.Lastupdated;
                seriesObj.Network = newSeries.Lastupdated;
                seriesObj.NetworkID = newSeries.NetworkID;
                seriesObj.Overview = newSeries.Overview;
                seriesObj.Rating = newSeries.Rating;
                seriesObj.Runtime = newSeries.Runtime;
                seriesObj.SeriesName = newSeries.SeriesName;
                seriesObj.Status = newSeries.Status;
                seriesObj.Zap2It_Id = newSeries.Zap2It_Id;

                if (string.IsNullOrEmpty(seriesObj.SeriesBannerPath) && string.IsNullOrEmpty(seriesObj.SeriesBannerUrl))
                {
                    seriesObj.SeriesBannerUrl = newSeries.SeriesBannerUrl;
                }

                if (string.IsNullOrEmpty(seriesObj.PosterUrl) && string.IsNullOrEmpty(seriesObj.PosterPath))
                {
                    seriesObj.PosterUrl = newSeries.PosterUrl;
                }

                if (string.IsNullOrEmpty(seriesObj.FanartUrl) && string.IsNullOrEmpty(seriesObj.FanartPath))
                {
                    seriesObj.FanartUrl = newSeries.FanartUrl;
                }
            }

            foreach (var season in newSeries.Seasons)
            {
                if (seasonNumber == null)
                {
                    UpdateSeason(seriesObj, season.Value, episodeNumber);
                }
                else if (season.Value.SeasonNumber == seasonNumber)
                {
                    UpdateSeason(seriesObj, season.Value, episodeNumber, true);
                }
            }
        }