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()); } }
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(); }
private void GetUpcoming() { //Get upcoming Shows //select from episodes where air_date at today or less than 7 days upcoming_airs.AspectToStringConverter = delegate(object obj) { DateTime dt = (DateTime)obj; return dt.ToString("dddd, MMMM dd, yyyy h:mm"); }; using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { DateTime dateYesterday = DateTime.Now.Date.AddDays(-1); DateTime dateWeek = DateTime.Now.Date.AddDays(7); var shows = from s in sabSyncEntities.episodes.AsEnumerable() where s.air_date != "" && Convert.ToDateTime(s.air_date) >= dateYesterday && Convert.ToDateTime(s.air_date) < dateWeek && s.shows.ignore_season < s.season_number select new UpcomingObject() { ShowName = s.shows.show_name, SeasonNumber = s.season_number, EpisodeNumber = s.episode_number, EpisodeName = s.episode_name, AirDate = s.air_date, AirTime = s.shows.air_time, Overview = s.overview }; // Group by month-year, rather than date this.upcoming_airs.GroupKeyGetter = delegate(object x) { string airDate = ((UpcomingObject)x).AirDate; DateTime dt = Convert.ToDateTime(airDate); return new DateTime(dt.Year, dt.Month, dt.Day); }; this.upcoming_airs.GroupKeyToTitleConverter = delegate(object x) { DateTime dt = (DateTime)x; DateTime yesterday = DateTime.Now.AddDays(-1); DateTime today = DateTime.Now; DateTime tomorrow = DateTime.Now.AddDays(1); if (dt.ToShortDateString().Equals(yesterday.ToShortDateString())) return String.Format("Yesterday ({0})", dt.ToString("MMMM dd, yyyy")); if (dt.ToShortDateString().Equals(today.ToShortDateString())) return String.Format("Today ({0})", dt.ToString("MMMM dd, yyyy")); if (dt.ToShortDateString().Equals(tomorrow.ToShortDateString())) return String.Format("Today ({0})", dt.ToString("MMMM dd, yyyy")); return ((DateTime)x).ToString("MMMM dd, yyyy"); }; objectListViewUpcoming.SetObjects(shows.ToList()); } //AutoSize the Columns upcoming_show_name.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); upcoming_season_number.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); upcoming_episode_number.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); upcoming_episode_name.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); upcoming_airs.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); objectListViewUpcoming.Sort(upcoming_airs); //Sort By The 'Airs' Column }
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(); }
private IList<ShowAlias> GetShowAliases() { //Get from DB IList<ShowAlias> aliasList = new List<ShowAlias>(); using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { var aliases = from a in sabSyncEntities.shows where !String.IsNullOrEmpty(a.aliases) select new { a.show_name, a.aliases }; foreach (var alias in aliases) { foreach (var badName in alias.aliases.Split(';')) { ShowAlias showAlias = new ShowAlias(); showAlias.Alias = alias.show_name; showAlias.BadName = badName; aliasList.Add(showAlias); } } } return aliasList; }
private string GetEpisodeName(string showName, DateTime airDate) { string myFirstAired = airDate.ToString("yyyy-MM-dd"); using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { //Return the first matching EpisodeName for this showName, seasonNumber and episodeNumber combo return (from e in sabSyncEntities.episodes where e.shows.show_name.Equals(showName, StringComparison.InvariantCultureIgnoreCase) && e.air_date == myFirstAired select e.episode_name).FirstOrDefault(); } }
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()); } }
public bool IsQualityWanted(Episode episode) { string description = (episode.FeedItem.Description ?? string.Empty).ToLower(); string title = episode.FeedItem.Title.ToLower(); //Get show quality from DB //TODO Clean this up, must be a better way to do it... using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { var qualityNumber = (from q in sabSyncEntities.shows.AsEnumerable() where q.show_name.Equals(episode.ShowName, StringComparison.InvariantCultureIgnoreCase) select new { q.quality }).FirstOrDefault(); if (qualityNumber == null) {; Logger.Log("Quality is not wanted"); return false; } if (qualityNumber.quality == 0) //If quality is 0 get it! { //Figure out what the episode Quality for this episode is... foreach (var q in QualityTable) { if (title.Contains(q.Value) || description.Contains(q.Value)) { episode.Quality = q.Key; Logger.Log("Quality -{0}- is wanted for: {1}.", q.Value, episode.ShowName); return true; } } return false; //In the unlikely (Web DL) event that the quality is not shown in the title, return false since it will not be wanted } var qualityString = (from q in QualityTable where q.Key == qualityNumber.quality select q.Value).FirstOrDefault(); Logger.Log("Title is: {0}", title); bool titleContainsQuality = title.Contains(qualityString); bool descriptionContainsQuality = description.Contains(qualityString); if (titleContainsQuality || descriptionContainsQuality) { episode.Quality = Convert.ToInt32(qualityNumber.quality); Logger.Log("Quality -{0}- is wanted for: {1}.", qualityString, episode.ShowName); return true; } } Logger.Log("Quality is not wanted"); return false; }
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()); } }
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; } }
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); } }
private void GetHistory() { using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { var history = from h in sabSyncEntities.histories select new HistoryObject { Id = h.id, ShowName = h.shows.show_name, SeasonNumber = h.episodes.season_number, EpisodeNumber = h.episodes.episode_number, EpisodeName = h.episodes.episode_name, FeedTitle = h.feed_title, Quality = h.quality, ProperLong = h.proper, Provider = h.provider, DateString = h.date }; //Add an Image to the Provider Column history_provider.ImageGetter = delegate(object rowObject) { HistoryObject ho = (HistoryObject)rowObject; if (ho.Provider == "nzbmatrix") return 0; if (ho.Provider == "nzbsDotOrg") return 1; if (ho.Provider == "nzbsrus") return 2; if (ho.Provider == "nzbmatrix") return 3; if (ho.Provider == "lilx") return 4; return -1; //No Image }; history_quality.AspectToStringConverter = delegate(object obj) { Int32 quality = (Int32)obj; if (quality == 0) return "Best Possible"; if (quality == 1) return "xvid"; if (quality == 2) return "720p"; return "unknown"; //Default to unknown if well... unknown }; objectListViewHistory.SetObjects(history.ToList()); history_show_name.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); history_episode_name.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); history_feed_title.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); history_date.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); objectListViewFeeds.Sort(history_date, SortOrder.Descending); } }
private void GetShows() { using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { var shows = from s in sabSyncEntities.shows select s; objectListViewShows2.SetObjects(shows.ToList()); } objectListViewShows2.Sort(shows2_show_name); //Sort By The 'Show Name' Column }
private void GetFeeds() { using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { var feeds = from f in sabSyncEntities.providers select f; objectListViewFeeds.SetObjects(feeds.ToList()); } }
private void getBannerToolStripMenuItem_Click(object sender, EventArgs e) { if (objectListViewShows2.SelectedItems.Count != 1) return; long id = Convert.ToInt64(objectListViewShows2.SelectedItem.Text); int index = objectListViewShows2.SelectedIndex; using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { var showId = (from s in sabSyncEntities.shows where s.id == id select s.id).FirstOrDefault(); Database db = new Database(); db.GetBanner(showId); objectListViewShows2.SelectedIndex = 0; objectListViewShows2.SelectedIndex = index; } }
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(); }
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; }
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(); }
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()); } }
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(); } } }
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(); } }
private void objectListViewShows2_SelectionChanged(object sender, EventArgs e) { //Create view on left when index is changed //if single item selected show more informaion if (objectListViewShows2.SelectedItems.Count == 1) { tableLayoutPanelOverview.Visible = true; tableLayoutPanelShows2_show_details.Visible = true; labelShows2_tvdb_name.Visible = true; buttonShows2_details_save.Visible = true; using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { //Get all information about the show, grab last and next episode information at some point long id = Convert.ToInt64(objectListViewShows2.SelectedItem.Text); var show = (from s in sabSyncEntities.shows.AsEnumerable() where s.id == id select s).FirstOrDefault(); labelShows2_name_value.Text = show.show_name; labelShows2_tvdb_id_value.Text = show.tvdb_id.ToString(); labelShows2_tvdb_name.Text = show.tvdb_name; comboBoxShows2_quality.SelectedIndex = (int)show.quality; numericUpDownShows2_ignore_seasons.Value = (int)show.ignore_season; textBoxShows2_aliases.Text = show.aliases; labelShows2_air_day_value.Text = show.air_day; labelShows2_air_time_value.Text = show.air_time; labelShows2_status_value.Text = show.status; labelShows2_genre_value.Text = show.genre.Replace('|', '/'); textBoxShows2_overview.Text = show.overview; var episodes = from n in sabSyncEntities.episodes where n.shows.id == id select new EpisodeObject { AirDate = n.air_date, AirTime = n.shows.air_time, SeasonNumber = n.season_number, EpisodeNumber = n.episode_number, EpisodeName = n.episode_name, EpisodeId = n.id }; List<EpisodeObject> episodeList = new List<EpisodeObject>(); episodeList = episodes.ToList(); episodeList.Sort(); var last = episodeList.FindLast(d => d.Airs != new DateTime(1,1,1) && d.Airs < DateTime.Today); var next = episodeList.Find(d => d.Airs != new DateTime(1, 1, 1) && d.Airs >= DateTime.Today); if (next != null) { labelShows2_airs_next_date_value.Text = GetDateString(next.Airs); labelShows2_airs_next_season_number_value.Text = next.SeasonNumber.ToString(); labelShows2_airs_next_episode_number_value.Text = next.EpisodeNumber.ToString(); labelShows2_airs_next_title_value.Text = next.EpisodeName; //If SABSync downloaded this episode show a check mark! if (sabSyncEntities.histories.Any(h => h.episode_id == next.EpisodeId)) pictureBoxShows2_next_downloaded.Visible = true; else pictureBoxShows2_next_downloaded.Visible = false; } else { labelShows2_airs_next_date_value.Text = "N/A"; labelShows2_airs_next_season_number_value.Text = "N/A"; labelShows2_airs_next_episode_number_value.Text = "N/A"; labelShows2_airs_next_title_value.Text = "N/A"; } if (last != null) { labelShows2_airs_last_date_value.Text = GetDateString(last.Airs); labelShows2_airs_last_season_number_value.Text = last.SeasonNumber.ToString(); labelShows2_airs_last_episode_number_value.Text = last.EpisodeNumber.ToString(); labelShows2_airs_last_title_value.Text = last.EpisodeName; //If SABSync downloaded this episode show a check mark! if (sabSyncEntities.histories.Any(h => h.episode_id == last.EpisodeId)) pictureBoxShows2_last_downloaded.Visible = true; else pictureBoxShows2_last_downloaded.Visible = false; } else { labelShows2_airs_last_date_value.Text = "N/A"; labelShows2_airs_last_season_number_value.Text = "N/A"; labelShows2_airs_last_episode_number_value.Text = "N/A"; labelShows2_airs_last_title_value.Text = "N/A"; } //Show the Banner! string image = String.Format("Images{0}Banners{1}{2}.jpg", Path.DirectorySeparatorChar, Path.DirectorySeparatorChar, objectListViewShows2.SelectedItem.Text); if (File.Exists(image)) pictureBoxShows2_banner.Image = Image.FromFile(image); else pictureBoxShows2_banner.Image = global::SABSync.Images.SABSync_Banner; } } if (objectListViewShows2.SelectedItems.Count > 1) //Multiple Selected { pictureBoxShows2_banner.Image = global::SABSync.Images.SABSync_Banner; //Display only Quality (and Ignore seasons options?) tableLayoutPanelOverview.Visible = false; tableLayoutPanelShows2_show_details.Visible = false; labelShows2_tvdb_name.Visible = false; buttonShows2_details_save.Visible = true; //Create a new Label this.labelShows2_quality_multi.Text = "Quality:"; this.labelShows2_quality_multi.AutoSize = true; this.labelShows2_quality_multi.Location = new Point(13, 50); this.labelShows2_quality_multi.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); //Create a new Combobox this.comboBoxShows2_quality_multi.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxShows2_quality_multi.SelectedIndex = -1; this.comboBoxShows2_quality_multi.Location = new Point(70, 45); this.comboBoxShows2_quality_multi.Size = new System.Drawing.Size(88, 21); this.comboBoxShows2_quality_multi.Visible = true; //Add the Controls to the Container this.groupBoxShows2_details.Controls.Add(labelShows2_quality_multi); this.groupBoxShows2_details.Controls.Add(comboBoxShows2_quality_multi); } else { //Display some default information } }
public bool IsSeasonIgnored(Episode episode) { //Is this season ignored per the Database?? using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { var ignored = (from i in sabSyncEntities.shows where i.show_name.Equals(episode.ShowName, StringComparison.InvariantCultureIgnoreCase) select i.ignore_season).FirstOrDefault(); if (ignored >= episode.SeasonNumber) return true; } return false; }
private void toolStripMenuItemShows2_list_update_all_Click(object sender, EventArgs e) { //Update all shows (Forced) using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { var seriesIds = from s in sabSyncEntities.shows select s.tvdb_id; List<long?> seriesIdList = seriesIds.ToList(); Database db = new Database(); Thread dbThread = new Thread(new ThreadStart(delegate { db.UpdateFromTvDb(seriesIdList); })); db.ProcessingShow += new Database.ProcessingShowHandler(db_ProcessingShow); dbThread.Name = "Update Cache Thread Forced (All)"; dbThread.Start(); } }
private string GetEpisodeName(string showName, int seasonNumber, int episodeNumber) { using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { //Return the first matching EpisodeName for this showName, seasonNumber and episodeNumber combo return (from e in sabSyncEntities.episodes where e.shows.show_name.Equals(showName, StringComparison.InvariantCultureIgnoreCase) && e.season_number == seasonNumber && e.episode_number == episodeNumber select e.episode_name).FirstOrDefault(); } }
private void toolStripMenuItemShows2_list_update_selected_Click(object sender, EventArgs e) { //Update selected shows (1+) using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { List<long?> seriesIdList = new List<long?>(); for (int i = 0 ; i < objectListViewShows2.SelectedItems.Count; i++) { int id = Convert.ToInt32(objectListViewShows2.SelectedItems[i].Text); var seriesId = (from s in sabSyncEntities.shows where s.id == id select s.tvdb_id).FirstOrDefault(); seriesIdList.Add(seriesId); } Database db = new Database(); Thread dbThread = new Thread(new ThreadStart(delegate { db.UpdateFromTvDb(seriesIdList); })); db.ProcessingShow += new Database.ProcessingShowHandler(db_ProcessingShow); dbThread.Name = "Update Cache Thread Forced (Selected)"; dbThread.Start(); } }
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()); } }
private bool IsInLocalHistory(Episode episode) { //TODO: Move this to Database Logger.Log("Checking SABSync.db for: [{0} - S{1:00}E{2:00}]", episode.ShowName, episode.SeasonNumber, episode.EpisodeNumber); using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { var ep = (from e in sabSyncEntities.histories where e.shows.show_name.Equals(episode.ShowName) & e.episodes.season_number.Value.Equals(episode.SeasonNumber) & e.episodes.episode_number.Value.Equals(episode.EpisodeNumber) select new { e.proper, e.quality }); //Grab all matches containing matching show name, season number and episode number if (ep.Count() > 0) { if (ep.Count(y => y.quality < episode.Quality) == ep.Count()) //If they are equal then higher quality episode has not yet been downloaded { Logger.Log("Episode is better quality than previously downloaded, deleting previous version"); foreach (DirectoryInfo tvDir in Config.TvRootFolders) { string dir = GetEpisodeDir(episode, tvDir); string fileMask = GetEpisodeFileMask(episode, tvDir); DeleteForUpgrade(dir, fileMask); } return false; } //Check if Both are Propers if (episode.IsProper) { if (ep.AsEnumerable().Any(p => Convert.ToBoolean(p.proper.Value) && episode.Quality == p.quality)) { Logger.Log("Found in Local History"); return true; } return false; //Episode in History is not a proper } //Episode to be downloaded is not a proper and episode was found in local history Logger.Log("Found in Local History"); return true; } } return false; //Not found, return false }
private IList<FeedInfo> GetFeeds() { //Load from DB using (SABSyncEntities sabSyncEntities = new SABSyncEntities()) { IList<FeedInfo> fi = new List<FeedInfo>(); foreach (var feed in from f in sabSyncEntities.providers select new { f.name, f.url }) fi.Add(new FeedInfo(feed.name, feed.url)); return fi; } }
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(); }