Esempio n. 1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            //Save to DB then close

            if (txtName.Text.Equals("") || txtUrl.Text.Equals(""))
                return;

            using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
            {
                providers feed = new providers
                                     {
                                         name = txtName.Text,
                                         url = txtUrl.Text
                                     };

                sabSyncEntities.AddToproviders(feed);
                sabSyncEntities.SaveChanges();
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Esempio n. 2
0
        private void AddNewShowWithEpisodes(string showName)
        {
            //TODO: Find a way to migrate aliases to Database... or not, not a big deal IMO
            //Update the shows table, get TVDB ID and Name, possible get TVRage ID and Name

            Logger.Log("Checking if {0} is in Database: ", showName);

            try
            {
                using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
                {
                    if (sabSyncEntities.shows.Any(s => s.show_name == showName)) //If show was already added...skip it (Use local disk name)
                        return;

                    //Get TVDB ID & Name
                    TvDbShowInfo info = new TvDbShowInfo();
                    info = TvDb.GetShowData(showName);

                    if (info == null)
                        return;

                    //string aliases = GetAliasForDb(showName, info.SeriesName);
                    int downloadQuality = GetQualityForDb();

                    //Add to shows Database
                    shows newItem = new shows
                                        {
                                            id = new int(),
                                            show_name = showName,
                                            tvdb_id = Convert.ToInt32(info.SeriesId),
                                            tvdb_name = info.SeriesName,
                                            ignore_season = 0,
                                            air_day = info.AirDay,
                                            air_time = info.AirTime,
                                            run_time = Convert.ToInt32(info.RunTime),
                                            status = info.Status,
                                            poster_url = info.PosterUrl,
                                            banner_url = info.BannerUrl,
                                            imdb_id = info.ImdbId,
                                            genre = info.Genre.Trim('|'),
                                            overview = info.Overview,
                                            quality = downloadQuality,
                                            aliases = GetAliasForDb(showName)
                    };
                    Logger.Log("Adding {0} to database.", showName);

                    sabSyncEntities.AddToshows(newItem);
                    sabSyncEntities.SaveChanges(); //Save show to Database after each show
                    var newShow = (from s in sabSyncEntities.shows where s.tvdb_id == info.SeriesId select s).FirstOrDefault(); //Get the PK for the show just added (so we can get the banner)
                    TvDb.GetBanner(info.BannerUrl, newShow.id); //Get the banner and save to disk
                    AddEpisodes(info.Episodes, Convert.ToInt32(info.SeriesId)); //Add all episodes for this show
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString());
            }
        }
Esempio n. 3
0
        public void GetBanner(long showId)
        {
            try
            {
                using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
                {
                    var show = (from s in sabSyncEntities.shows
                                where s.id == showId
                                select s).FirstOrDefault();
                    
                    //Get Banner URL for DB then download Banner
                    show.banner_url = TvDb.GetBannerUrl((long)show.tvdb_id);
                    sabSyncEntities.shows.ApplyCurrentValues(show);

                    Logger.Log("Attempting to get banner for: {0}", show.show_name);

                    //If banner comes back null or empty return
                    if (String.IsNullOrEmpty(show.banner_url))
                        return;

                    TvDb.GetBanner(show.banner_url, show.id);
                    sabSyncEntities.SaveChanges(); //Save the Banner URLs
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString());
            }
        }
Esempio n. 4
0
        public void GetBanners()
        {
            try
            {
                using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
                {
                    var shows = from s in sabSyncEntities.shows
                                where String.IsNullOrEmpty(s.banner_url)
                                select s;

                    foreach (var show in shows)
                    {
                        //Get Banner URL for DB then download Banner
                        show.banner_url = TvDb.GetBannerUrl((long)show.tvdb_id);
                        sabSyncEntities.shows.ApplyCurrentValues(show);

                        Logger.Log("Attempting to get banner for: {0}", show.show_name);

                        //If banner comes back null or empty go onto the next
                        if (String.IsNullOrEmpty(show.banner_url))
                            continue;

                        TvDb.GetBanner(show.banner_url, show.id);
                    }
                    sabSyncEntities.SaveChanges(); //Save the Banner URLs
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString());
            }
        }
Esempio n. 5
0
        private void AddEpisodes(List<TvDbEpisodeInfo> episodeList, long? seriesId)
        {
            //Check if Episode is in table, if not, add it!
            try
            {
                using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
                {
                    var shows = from s in sabSyncEntities.shows
                                where s.tvdb_id == seriesId
                                select new
                                {
                                    s.id
                                };

                    foreach (var episode in episodeList) //Get all Episodes for show
                    {
                        if (sabSyncEntities.episodes.Any(e => e.tvdb_id == episode.EpisodeId)) //If episode was already added...update it
                        {
                            //Update all existing episodes
                            var episodeToUpdate = (from e in sabSyncEntities.episodes where e.tvdb_id == episode.EpisodeId select e).FirstOrDefault(); //Select the first episode ID matching the TvDB Episode ID

                            episodeToUpdate.season_number = episode.SeasonNumber;
                            episodeToUpdate.episode_number = episode.EpisodeNumber;
                            episodeToUpdate.episode_name = episode.EpisodeName;
                            episodeToUpdate.air_date = episode.FirstAired;
                            episodeToUpdate.overview = episode.Overview;

                            sabSyncEntities.episodes.ApplyCurrentValues(episodeToUpdate);
                            continue;
                        }

                        episodes newItem = new episodes
                        {
                            id = new long(),
                            show_id = shows.FirstOrDefault().id,
                            season_number = episode.SeasonNumber,
                            episode_number = episode.EpisodeNumber,
                            episode_name = episode.EpisodeName,
                            air_date = episode.FirstAired,
                            tvdb_id = episode.EpisodeId,
                            overview = episode.Overview
                        };
                        sabSyncEntities.AddToepisodes(newItem);
                    }
                    sabSyncEntities.SaveChanges(); //Insert into Database after processing each series
                }
            }

            catch (Exception ex)
            {
                Logger.Log(ex.ToString());
            }
        }
Esempio n. 6
0
        public void AddToHistory(Episode episode, NzbInfo nzb)
        {
            using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
            {
                var data = (from e in sabSyncEntities.episodes.AsEnumerable()
                           where
                               e.shows.show_name.Equals(episode.ShowName, StringComparison.InvariantCultureIgnoreCase) && e.episode_number == episode.EpisodeNumber &&
                               e.season_number == episode.SeasonNumber
                           select new
                           {
                               ShowId = e.shows.id,
                               EpisodeId = e.id
                           }).FirstOrDefault();

                if (data == null)
                {
                    data = (from e in sabSyncEntities.episodes.AsEnumerable()
                            where
                                e.shows.show_name.Equals(episode.ShowName, StringComparison.InvariantCultureIgnoreCase) &&
                                Convert.ToDateTime(e.air_date) == episode.AirDate
                            select new
                                       {
                                           ShowId = e.shows.id,
                                           EpisodeId = e.id
                                       }).FirstOrDefault();
                }

                histories newItem = new histories
                {
                    id = new long(),
                    show_id = data.ShowId,
                    episode_id = data.EpisodeId,
                    feed_title = episode.FeedItem.Title,
                    quality = episode.Quality,
                    proper = Convert.ToInt32(episode.IsProper),
                    provider = nzb.Site.Name,
                    date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")
                };

                Logger.Log("Episode added to History Database: {0} - S{1}E{2}", episode.ShowName, episode.SeasonNumber.ToString("00"), episode.EpisodeNumber.ToString("00"));
                sabSyncEntities.AddTohistories(newItem);
                sabSyncEntities.SaveChanges();

            }
        }
Esempio n. 7
0
        public void UpdateFromTvDb (List<long?> seriesIdList)
        {
            using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
            {
                var shows = from s in sabSyncEntities.shows
                            select s;

                //Update the shows (and add new episodes)
                foreach (var seriesId in seriesIdList)
                {
                    var show = (from s in shows where s.tvdb_id == seriesId select s).FirstOrDefault();
                        //set show to the first (of one) that is found (Should be one, if not something else is FUBAR)

                    ProcessingShow("Updating: " + show.show_name);

                    //Get the updated series/new episode data for this seriesId
                    var updatedShowInfo = TvDb.GetShowUpdates(seriesId);

                    show.air_day = updatedShowInfo.AirDay;
                    show.air_time = updatedShowInfo.AirTime;
                    show.run_time = updatedShowInfo.RunTime;
                    show.genre = updatedShowInfo.Genre.Trim('|');
                    show.tvdb_name = updatedShowInfo.SeriesName;
                    show.overview = updatedShowInfo.Overview;
                    show.status = updatedShowInfo.Status;
                    show.poster_url = updatedShowInfo.PosterUrl;
                    show.banner_url = updatedShowInfo.BannerUrl;

                    sabSyncEntities.shows.ApplyCurrentValues(show); //Apply the current values
                    sabSyncEntities.SaveChanges(); //Save them to the server

                    AddEpisodes(updatedShowInfo.Episodes, seriesId); //Add the new episodes/update the old ones
                }
                ProcessingShow("Shows updated: " + seriesIdList.Count);
            }
        }
Esempio n. 8
0
        public void GetTvDbUpdates()
        {
            //Get all updates to Series and Episodes since last check, get updates for watched shows and episodes

            try
            {
                using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
                {
                    var oldTime = (from t in sabSyncEntities.info select t).FirstOrDefault(); //Get the time from the DB

                    if (oldTime == null)
                        return;

                    TvDbUpdates updates = TvDb.GetUpdates(Convert.ToInt32(oldTime.last_tvdb.Value)); //Get the Updates since oldTime

                    oldTime.last_tvdb = updates.Time;

                    List<long?> seriesToUpdate = new List<long?>(); //Used to store the list of shows that need to be updated

                    var shows = from s in sabSyncEntities.shows
                                select s;

                    foreach (var seriesId in updates.Series)
                    {
                        if (shows.Any(s => s.tvdb_id == seriesId)) //If we're watching this show add to the list
                            seriesToUpdate.Add(seriesId);
                    }

                    UpdateFromTvDb(seriesToUpdate); //Update the list of shows we are watching

                    sabSyncEntities.info.ApplyCurrentValues(oldTime);
                    sabSyncEntities.SaveChanges(); //Save the new time to the info table
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString());
            }
        }
Esempio n. 9
0
        public void GetTvDbServerTime()
        {
            int time = TvDb.GetServerTime();
            try
            {
                using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
                {
                    if ((from i in sabSyncEntities.info select i).Count() != 0) //Get the count of items in info, if not 0 then return (Time was already added).
                        return;

                    info newTime = new info()
                    {
                        id = new long(),
                        last_tvdb = time
                    };
                    sabSyncEntities.AddToinfo(newTime);
                    sabSyncEntities.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString());
                throw;
            }
        }
Esempio n. 10
0
        private void objectListViewFeeds_CellEditFinishing(object sender, CellEditEventArgs e)
        {
            string columnName = e.Column.Text.ToLower();
            string oldValue = e.Value.ToString();
            string newValue = e.NewValue.ToString();

            if (e.Cancel)
                return;

            if (columnName.Equals("url", StringComparison.InvariantCultureIgnoreCase))
            {
                using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
                {
                    var feed = (from f in sabSyncEntities.providers where f.url.Equals(oldValue) select f).FirstOrDefault();

                    feed.url = newValue;
                    sabSyncEntities.providers.ApplyCurrentValues(feed);
                    sabSyncEntities.SaveChanges();
                }
            }

            if (columnName.Equals("name", StringComparison.InvariantCultureIgnoreCase))
            {
                using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
                {
                    var feed = (from f in sabSyncEntities.providers where f.name.Equals(oldValue) select f).FirstOrDefault();

                    feed.name = newValue;
                    sabSyncEntities.providers.ApplyCurrentValues(feed);
                    sabSyncEntities.SaveChanges();
                }
            }
        }
Esempio n. 11
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Confirm Delete, then delete selected
            if (MessageBox.Show("Are you sure?", "Confirm Delete", MessageBoxButtons.YesNo) != DialogResult.Yes)
                return;

            using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
            {
                for (int i = 0; i < objectListViewShows2.SelectedItems.Count; i++)
                {
                    int id = Convert.ToInt32(objectListViewShows2.SelectedItems[i].Text);

                    var show = (from s in sabSyncEntities.shows where s.id == id select s).FirstOrDefault();
                    var episodes = from ep in sabSyncEntities.episodes where ep.show_id == id select ep;
                    var history = from h in sabSyncEntities.histories where h.show_id == id select h;

                    //Delete each item in history for the selected show
                    foreach (var h in history)
                        sabSyncEntities.DeleteObject(h);

                    //Delete each episode for the selected show
                    foreach (var episode in episodes)
                        sabSyncEntities.DeleteObject(episode);
                    sabSyncEntities.DeleteObject(show); //Delete the show
                }
                sabSyncEntities.SaveChanges(); //Save the changes
            }
            GetShows();
        }
Esempio n. 12
0
        private void buttonShows2_details_save_Click(object sender, EventArgs e)
        {
            if (objectListViewShows2.SelectedItems.Count == 1)
            {
                //showId from selected show
                //Quality Dropbox Index
                //NumberSelect Ignore Season value
                //Aliases

                int showId = Convert.ToInt32(objectListViewShows2.SelectedItem.Text);
                int quality = comboBoxShows2_quality.SelectedIndex;
                int ignoreSeasons = Convert.ToInt32(numericUpDownShows2_ignore_seasons.Value);
                string aliases = textBoxShows2_aliases.Text;

                using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
                {
                    var show = (from s in sabSyncEntities.shows where s.id == showId select s).First();

                    show.quality = quality;
                    show.ignore_season = ignoreSeasons;
                    show.aliases = aliases;

                    sabSyncEntities.shows.ApplyCurrentValues(show);
                    sabSyncEntities.SaveChanges();
                }
            }

            if (objectListViewShows2.SelectedItems.Count > 1)
            {
                //Save Quality (and Ignore Seasons?) for all selected shows

                //return if combobox for quality multi does not have a value selected
                if (comboBoxShows2_quality_multi.SelectedIndex < 0)
                    return;

                int quality = comboBoxShows2_quality_multi.SelectedIndex;

                using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
                {
                    for (int i = 0; i < objectListViewShows2.SelectedItems.Count; i++)
                    {
                        int id = Convert.ToInt32(objectListViewShows2.SelectedItems[i].Text);
                        var show = (from s in sabSyncEntities.shows where s.id == id select s).First();

                        show.quality = quality;
                        sabSyncEntities.shows.ApplyCurrentValues(show);
                    }
                    sabSyncEntities.SaveChanges();
                }
            }

            //Nothing is selected, return
            else
                return;
        }
Esempio n. 13
0
        private void btnPurgeHistory_Click(object sender, EventArgs e)
        {
            //Clear all items in the History

            if (MessageBox.Show("Are you sure?", "Confirm Purge", MessageBoxButtons.YesNo) != DialogResult.Yes)
                return;

            using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
            {
                var items = from i in sabSyncEntities.histories select i;

                foreach (var item in items)
                    sabSyncEntities.DeleteObject(item);

                sabSyncEntities.SaveChanges();
            }
            GetHistory();
        }
Esempio n. 14
0
        private void btnDeleteHistory_Click(object sender, EventArgs e)
        {
            //Popup to Confirm, then delete selected row

            if (objectListViewHistory.SelectedItems.Count != 1)
                return;

            if (MessageBox.Show("Are you sure?", "Confirm Delete", MessageBoxButtons.YesNo) != DialogResult.Yes)
                return;

            int id = Convert.ToInt32(objectListViewHistory.SelectedItem.Text);

            using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
            {
                var item = (from i in sabSyncEntities.histories where i.id == id select i).FirstOrDefault();
                sabSyncEntities.DeleteObject(item);
                sabSyncEntities.SaveChanges();
            }
            GetHistory();
        }
Esempio n. 15
0
        private void btnDeleteFeeds_Click(object sender, EventArgs e)
        {
            //Popup to Confirm, then delete selected row

            if (objectListViewFeeds.SelectedItems.Count != 1)
                return;

            if (MessageBox.Show("Are you sure?", "Confirm Delete", MessageBoxButtons.YesNo) != DialogResult.Yes)
                return;

            int id = Convert.ToInt32(objectListViewFeeds.SelectedItem.Text);

            using (SABSyncEntities sabSyncEntities = new SABSyncEntities())
            {
                var feed = (from f in sabSyncEntities.providers where f.id == id select f).FirstOrDefault();
                sabSyncEntities.DeleteObject(feed);
                sabSyncEntities.SaveChanges();
            }
            GetFeeds();
        }