private static int MoveVideoToAnswers(PoliticiansRow politician, int count, ref int duplicate) { var youTubeId = politician.YouTubeWebAddress.GetYouTubeVideoId(); VideoInfo videoInfo = null; if (!IsNullOrWhiteSpace(youTubeId)) { videoInfo = YouTubeVideoUtility.GetVideoInfo(youTubeId, false, 1); } if (videoInfo != null && videoInfo.IsValid) { count++; // get Why I'm Running answers var answers = Answers.GetDataByPoliticianKeyQuestionKey(politician.PoliticianKey, QuestionKey); if (answers.All(row => row.YouTubeUrl.GetYouTubeVideoId() != youTubeId)) { // doesn't exist -- add to first without a YouTubeUrl var rowToUpdate = answers.FirstOrDefault(row => IsNullOrWhiteSpace(row.YouTubeUrl)); if (rowToUpdate == null) { // new to add a row { rowToUpdate = answers.NewRow(politician.PoliticianKey, QuestionKey, Answers.GetNextSequence(politician.PoliticianKey, QuestionKey), Politicians.GetStateCodeFromKey(politician.PoliticianKey), IssueKey, Empty, Empty, VotePage.DefaultDbDate, "curt", Empty, Empty, default, Empty, Empty,
protected override bool Update(object newValue) { if (_SocialMedium.Name == "YouTube") { // ReSharper disable once PossibleNullReferenceException var url = (newValue as string).Trim(); var description = Empty; var runningTime = default(TimeSpan); var date = DefaultDbDate; if (!IsNullOrWhiteSpace(url)) { VideoInfo info = null; if (url.IsValidYouTubeVideoUrl()) { var id = url.GetYouTubeVideoId(); info = YouTubeVideoUtility.GetVideoInfo(id, true, 1); } else if (url.IsValidYouTubePlaylistUrl()) { var id = url.GetYouTubePlaylistId(); info = YouTubeVideoUtility.GetPlaylistInfo(id, true, 1); } else if (url.IsValidYouTubeChannelUrl() || url.IsValidYouTubeCustomChannelUrl() || url.IsValidYouTubeUserChannelUrl()) { var id = YouTubeVideoUtility.LookupChannelId(url, 1); if (!IsNullOrWhiteSpace(id)) { info = YouTubeVideoUtility.GetChannelInfo(id, true, 1); } } if (info?.IsValid == true && info.IsPublic) { description = info.ShortDescription; runningTime = info.Duration; date = info.PublishedAt; } } Politicians.UpdateYouTubeDescription(description, Page.PoliticianKey); Politicians.UpdateYouTubeRunningTime(runningTime, Page.PoliticianKey); Politicians.UpdateYouTubeDate(date, Page.PoliticianKey); Politicians.UpdateYouTubeAutoDisable(Empty, Page.PoliticianKey); Politicians.UpdateYouTubeVideoVerified(false, Page.PoliticianKey); } return(base.Update(newValue)); }