private void CheckForVideo(Slide slide, String currentSlideRelID, SlidePart slidePart, PresentationDocument document) { var videos = slide.Descendants <VideoFromFile>(); foreach (VideoFromFile video in videos) { String path = slidePart.GetReferenceRelationship(video.Link).Uri.OriginalString; String fileExtension = System.IO.Path.GetExtension(path); String description = $"Found video on slide {SlideModel.rIdtoSlideIndex(currentSlideRelID)}, file extension is {fileExtension}"; Boolean fixable; String filename = System.IO.Path.GetFileName(path); if (fileExtension == ".mp4") { fixable = false; } else { fixable = true; } IIssue issue = new VideoIssueItem(filename, video, description, fixable); powerpoint.slides[currentSlideRelID].addToIssueList(issue); } }
/// <summary> /// Consider two output types: /// .txt if pptx doesn't contain videos /// .zip if it contains videos (a .txt file + the video files) /// </summary> /// <param name="source"></param> /// <returns></returns> public async Task <Dictionary <int, string> > ProcessVideoParts(string source, MSOfficeJob job, string tempDirectory) { Dictionary <int, string> TextContent = new Dictionary <int, string>(); int index = 1; using (PresentationDocument ppt = PresentationDocument.Open(source, false)) { // Get the relationship ID of the first slide. PresentationPart part = ppt.PresentationPart; OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements; foreach (SlideId slideID in slideIds) { //get the right content according to type. for now only text is getting through string relId = slideID.RelationshipId; // Get the slide part from the relationship ID. SlidePart slide = (SlidePart)part.GetPartById(relId); //extract the videos and put placeholders IEnumerable <A.VideoFromFile> videos = slide.Slide.Descendants <A.VideoFromFile>(); foreach (A.VideoFromFile vid in videos) { string videoRelId = vid.Link; ReferenceRelationship rel = slide.GetReferenceRelationship(videoRelId); Uri uri = rel.Uri; var filename = uri.ToString().Split('/').Last(); var s = ppt.Package.GetPart(uri).GetStream(); byte[] videoBytes = null; using (BinaryReader br = new BinaryReader(s)) { videoBytes = br.ReadBytes((int)s.Length); } //write video to result directory File.WriteAllBytes(Path.Combine(tempDirectory, filename), videoBytes); //send to amara string langauge = "en-us"; if (ppt.PackageProperties.Language != null) { langauge = ppt.PackageProperties.Language; } AmaraSubtitleJob vj = new AmaraSubtitleJob() { SubmitTime = DateTime.Now, FinishTime = DateTime.Now, Status = JobStatus.Started, MimeType = "video/" + filename.Substring(filename.LastIndexOf('.') + 1), //define this properly User = job.User, UserId = job.UserId, DownloadCounter = 0, FileContent = videoBytes, InputFileHash = RoboBrailleProcessor.GetMD5Hash(videoBytes), SubtitleFormat = job.SubtitleFormat, SubtitleLangauge = job.SubtitleLangauge, FileName = job.Id.ToString() + "-" + filename.Substring(0, filename.LastIndexOf('.')), FileExtension = filename.Substring(filename.LastIndexOf('.') + 1) }; //retrieve the message from amara byte[] filebytes = null; Guid subtitleJobId = vcr.SubmitWorkItem(vj).Result; while (vcr.GetWorkStatus(subtitleJobId) == 2) { await Task.Delay(2000); } filebytes = vcr.GetResultContents(subtitleJobId).getFileContents(); File.WriteAllBytes(Path.Combine(tempDirectory, filename.Substring(0, filename.LastIndexOf('.')) + vj.ResultFileExtension), filebytes); slide.Slide.CommonSlideData.ShapeTree.AppendChild( new ShapeProperties( new TextBody( new A.Paragraph( new A.Run( new A.Text("Video file name = " + filename + " subtitle attached to video has id: " + vj.Id.ToString()) ))))); } // Build a StringBuilder object. StringBuilder paragraphText = new StringBuilder(); // Get the inner text of the slide: IEnumerable <A.Text> texts = slide.Slide.Descendants <A.Text>(); foreach (A.Text text in texts) { if (text.Text.Length > 1) { paragraphText.Append(text.Text + " "); } else { paragraphText.Append(text.Text); } } string slideText = paragraphText.ToString(); TextContent.Add(index, slideText); index++; } //until now there are: video files + subtitle files //at the end there will be: a txt file + video files + subtitle files (all zipped up) } return(TextContent); }