protected override bool Update(object newValue) { if (_SocialMedium.Name == "YouTube") { // ReSharper disable once PossibleNullReferenceException var url = (newValue as string).Trim(); var description = string.Empty; var runningTime = default(TimeSpan); var date = DefaultDbDate; if (!string.IsNullOrWhiteSpace(url)) { YouTubeInfo info = null; if (url.IsValidYouTubeVideoUrl()) { var id = url.GetYouTubeVideoId(); info = YouTubeUtility.GetVideoInfo(id, true, 1); } else if (url.IsValidYouTubePlaylistUrl()) { var id = url.GetYouTubePlaylistId(); info = YouTubeUtility.GetPlaylistInfo(id, true, 1); } else if (url.IsValidYouTubeChannelUrl() || url.IsValidYouTubeCustomChannelUrl() || url.IsValidYouTubeUserChannelUrl()) { var id = YouTubeUtility.LookupChannelId(url, 1); if (!string.IsNullOrWhiteSpace(id)) { info = YouTubeUtility.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(string.Empty, Page.PoliticianKey); Politicians.UpdateYouTubeVideoVerified(false, Page.PoliticianKey); } return(base.Update(newValue)); }
private static bool ValidateYouTubeAddress(DataItemBase item) { string message = null; var value = item.DataControl.GetValue(); if (!string.IsNullOrWhiteSpace(value)) { if (value.IsValidYouTubeVideoUrl()) { var id = value.GetYouTubeVideoId(); var info = YouTubeUtility.GetVideoInfo(id, true, 1); if (!info.IsValid) { message = YouTubeInfo.VideoIdNotFoundMessage; } else if (!info.IsPublic) { message = YouTubeInfo.VideoNotPublicMessage; } } else if (value.IsValidYouTubePlaylistUrl()) { var id = value.GetYouTubePlaylistId(); var info = YouTubeUtility.GetPlaylistInfo(id, true, 1); if (!info.IsValid) { message = YouTubeInfo.PlaylistIdNotFoundMessage; } else if (!info.IsPublic) { message = YouTubeInfo.PlaylistNotPublicMessage; } } else if (value.IsValidYouTubeChannelUrl() || value.IsValidYouTubeCustomChannelUrl() || value.IsValidYouTubeUserChannelUrl()) { var id = YouTubeUtility.LookupChannelId(value, 1); if (string.IsNullOrWhiteSpace(id)) { message = YouTubeInfo.ChannelIdNotFoundMessage; } else { var info = YouTubeUtility.GetChannelInfo(id, true, 1); if (!info.IsValid) { message = YouTubeInfo.ChannelIdNotFoundMessage; } else if (!info.IsPublic) { message = YouTubeInfo.ChannelNotPublicMessage; } } } else { message = "The URL is not a valid YouTube channel, playlist or video URL"; } } if (string.IsNullOrWhiteSpace(message)) { item.DataControl.SetValue( Validation.StripWebProtocol(value)); } else { item.Feedback.PostValidationError(item.DataControl, message); } return(string.IsNullOrWhiteSpace(message)); }