public static YouTubeInfo LoadVideo(string url) { var match = _videoIdExtractor.Match(url); string videoId = null; if (match.Groups.Count >= 2) { if (!string.IsNullOrEmpty(match.Groups[match.Groups.Count - 1].Value)) { videoId = match.Groups[match.Groups.Count - 1].Value; } } if (string.IsNullOrEmpty(videoId)) { videoId = getIdFromShortYoutubeURL(url); } if (string.IsNullOrEmpty(videoId)) { videoId = HttpUtility.ParseQueryString(url).Get(0); } if (string.IsNullOrEmpty(videoId)) { return(null); } YouTubeInfo info = LoadVideoData(videoId); return(info); }
public static YouTubeInfo AttachToYtInfo(Attachment a) { YouTubeInfo info = new YouTubeInfo(); info.ThumbNailUrl = a.VideoThumbURL; info.EmbedUrl = a.VideoEmbedURL; info.LinkUrl = a.VideoLinkURL; return(info); }
static void saveYouTube() { if (YouTubeInfo == null) { AppSettings.AddOrUpdateValue("youtube_meta", string.Empty); return; } XmlSerializer xs = new XmlSerializer(YouTubeInfo.GetType()); using (StringWriter sw = new StringWriter()) { xs.Serialize(sw, YouTubeInfo); AppSettings.AddOrUpdateValue("youtube_meta", sw.ToString()); } }
//if Url!=null, uses it. otherwice asks for URL private static Attachment AttachFromYoutube(ArgPoint Point, string Url) { string URLToUse = Url; if (URLToUse == null) { InpDialog dlg = new InpDialog(); dlg.ShowDialog(); URLToUse = dlg.Answer; if (URLToUse == null || !URLToUse.StartsWith("http://")) { return(null); } } BusyWndSingleton.Show("Processing Youtube attachment..."); Attachment res = new Attachment(); try { YouTubeInfo videoInfo = YouTubeProvider.LoadVideo(URLToUse); if (videoInfo == null) { return(null); } res.Format = (int)AttachmentFormat.Youtube; res.VideoEmbedURL = videoInfo.EmbedUrl; res.VideoThumbURL = videoInfo.ThumbNailUrl; res.VideoLinkURL = videoInfo.LinkUrl; res.Link = videoInfo.LinkUrl; res.Title = videoInfo.VideoTitle; res.Name = URLToUse; res.Thumb = ImageToBytes(GetYoutubeThumb(videoInfo.ThumbNailUrl), new JpegBitmapEncoder()); if (Point != null) { Point.Attachment.Add(res); } ///PublicBoardCtx.Get().SaveChanges(); } finally { BusyWndSingleton.Hide(); } return(res); }
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)); }
public YouTubeResultEventArgs(YouTubeInfo info) { this.Info = info; }