public override ISource Create(Uri uri, string pageData) { string userHref = pageData.GetStringBetween("<link rel=\"canonical\"", " href=\"", "\""); string username = userHref.GetStringBetween("/user/", null); string title = pageData.GetStringBetween("<meta name=\"title\" content=\"", "\""); string description = pageData.GetStringBetween("<meta name=\"description\" content=\"", "\""); string thumbnail = pageData.GetStringBetween("<meta property=\"og:image\" content=\"", "\""); // thumbnail format changed (no http/s) // //i1.ytimg.com/i/dbL-i29FDPYok8X8yIynNQ/1.jpg?v=9aee31 string ajaxSessionInfo = pageData.GetStringBetween("window.ajax_session_info", "'", "'"); var parameters = new ParameterList(); parameters.AddValue(UserParameterName, username); parameters.AddValue(UserHrefParameterName, userHref); parameters.AddValue(TitleParameterName, title); parameters.AddValue(DescriptionParameterName, description); parameters.AddValue(ThumbnailParameterName, thumbnail); parameters.AddValue(AjaxSessionInfoParameterName, ajaxSessionInfo); var channelSource = new YoutubeVideoChannelSource(uri, this, parameters); var downloadSources = ParseDownloadSources(pageData, channelSource); foreach (var downloadSource in downloadSources) channelSource.Add(downloadSource); return channelSource; }
private IEnumerable<IDownloadSource> ParseDownloadSources(string pageData, YoutubeVideoChannelSource channelSource) { var sources = new List<IDownloadSource>(); DownloadSourceCreator downloadSourceCreator = null; int currentPosition = 0; while (true) { string videoId = pageData.GetStringBetween(ref currentPosition, "\"encryptedVideoId\">", "<"); if (string.IsNullOrEmpty(videoId)) break; videoId = videoId.Trim(); string videoUri = pageData.GetStringBetween(ref currentPosition, "<div class=\"playnav-video-thumb\"", " href=\"", "\""); string videoThumb = pageData.GetStringBetween(ref currentPosition, " src=\"", "\""); string videoTitle = pageData.GetStringBetween(ref currentPosition, "title=\"", "\"").HtmlDecode(); string videoTime = pageData.GetStringBetween(ref currentPosition, "<span class=\"video-time\">", "<"); string videoViews = pageData.GetStringBetween(ref currentPosition, "<div class=\"metadata\">", ">", " views"); videoThumb = new Uri(channelSource.Uri, videoThumb).AbsoluteUri; int parsedViews = int.Parse(videoViews, System.Globalization.NumberStyles.AllowThousands); var absoluteUri = new Uri(channelSource.Uri, videoUri); if (downloadSourceCreator == null) downloadSourceCreator = (DownloadSourceCreator)Factory.Context.FindFactoryByCreatorType(typeof(DownloadSourceCreator)).GetCreator(absoluteUri); var videoParameters = new ParameterList(); videoParameters.AddValue(VideoDownloadSourceCreator.IdParameterName, videoId); videoParameters.AddValue(VideoDownloadSourceCreator.TitleParameterName, videoTitle); videoParameters.AddValue(VideoDownloadSourceCreator.DescriptionParameterName, channelSource.Description); videoParameters.AddValue(VideoDownloadSourceCreator.ThumbnailParameterName, videoThumb); videoParameters.AddValue(YoutubeVideoDownloadSourceCreator.UserParameterName, channelSource.User); videoParameters.AddValue(YoutubeVideoDownloadSourceCreator.UserHrefParameterName, channelSource.UserHref); videoParameters.AddValue(YoutubeVideoDownloadSourceCreator.TimeParameterName, videoTime); videoParameters.AddValue(YoutubeVideoDownloadSourceCreator.ViewCountParameterName, parsedViews); var ds = new YoutubeVideoDownloadSource(absoluteUri, downloadSourceCreator, videoParameters); sources.Add(ds); } return sources; }