public ExtractResult ImageExtract(int expectedId, string base64, string subs) { if (string.IsNullOrWhiteSpace(base64)) { return(new ExtractResult(false, "Failed to create image extract because base 64 data was null or empty")); } subs = subs ?? string.Empty; byte[] bytes = Convert.FromBase64String(base64); try { List <ContentBase> contents = new List <ContentBase>(); contents.Add(new TextContent(true, subs)); var htmlCtrl = ContentEx.GetFirstHtmlCtrl(); var refs = htmlCtrl?.GetReferences(); string title = refs?.Title ?? CurrentMediaElement.Id; var image = CreateImage(base64); var imgContent = ContentEx.CreateImageContent(image, title); if (imgContent != null) { contents.Add(imgContent); } var priority = MediaPlayerState.Instance.Config.DefaultExtractPriority; var res = ContentEx.CreateSMElement(expectedId, priority, contents, refs, false); return(new ExtractResult(res == CreationResult.Ok, res.Name())); } catch (Exception) { return(new ExtractResult(false, "Failed to create image extract")); } }
public static async Task <CreationResult> Create( string urlOrId, double startTime = 0, double endTime = -1, int parentElementId = -1, double watchPoint = 0, ViewMode viewMode = MediaPlayerConst.DefaultViewMode, bool shouldDisplay = true) { // TODO: Time the verification check JObject metadata = await YdlUtils.GetYouTubeVideoMetadata(urlOrId); if (metadata == null || string.IsNullOrWhiteSpace((string)metadata["id"])) { LogTo.Warning($"Failed to recognise {urlOrId} as a YouTube video"); return(CreationResult.FailUnknown); } YouTubeMediaElement ytEl; string youtubeId = (string)metadata["id"]; string title = (string)metadata["title"]; string uploader = (string)metadata["uploader"]; string date = (string)metadata["upload_date"]; string thumbnailUrl = (string)metadata["thumbnail"]; ytEl = new YouTubeMediaElement { Id = youtubeId, StartTime = startTime, EndTime = endTime, WatchPoint = watchPoint, ViewMode = viewMode, }; List <ContentBase> contents = new List <ContentBase>(); string elementHtml = string.Format(CultureInfo.InvariantCulture, MediaPlayerConst.YouTubeElementFormat, title, ytEl.GetJsonB64()); contents.Add(new TextContent(true, elementHtml)); if (Config.IncludeYouTubeThumbnail) { Image img = DownloadThumbnail(thumbnailUrl); if (img != null) { var imgContent = ContentEx.CreateImageContent(img, string.Format(YTConst.VideoThumbImgRegPath, ytEl.Id)); if (imgContent != null) { contents.Add(imgContent); } } } var refs = new References() .WithTitle(title) .WithAuthor(uploader) .WithDate(HumanReadableDate(date)) .WithLink(ytEl.Url); var priority = MediaPlayerConst.DefaultExtractPriority; return(ContentEx.CreateSMElement(parentElementId, priority, contents, refs, shouldDisplay)); }