-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing video results in corrupted file. #974
Comments
There's probably rather more to deleting a movie than removing a chunk of XML. |
@shoang22 you're going to want to remove the relationship from the slide (package) part to the part containing the movie (Media part maybe?). Otherwise I expect PowerPoint isn't going to like seeing the orphaned movie. Not sure if that's the whole problem, unfortunately the repair error doesn't give us any idea of what it figures to be a "problem with content". |
And what would be the strategy for doing this - in Python code? I ask, @scanny, because this logic is probably common to other removals. |
Basically dig out the relationship and delete it. The relationship(s) would be identified by an Then you need to get to the slide part because that's the source side of the relationship, so something like: slide_part = slide.part
slide_part.rels.drop_rel("rIdN") Somebody can dig through and refine that with actual code if they have a mind to :) |
Something like this? def remove_movie(file_path: str) -> None:
slides_folder = os.path.dirname(file_path) + "/slides"
os.makedirs(slides_folder, exist_ok=True)
prs = pptx.Presentation(file_path)
for idx, slide in enumerate(prs.slides):
for shape in slide.shapes:
if type(shape) == pptx.shapes.picture.Movie:
p = slide.part
x = etree.fromstring(p.rels.xml)
before = etree.tostring(x, pretty_print=True)
print(before.decode())
vid = shape.element
vid.getparent().remove(vid)
p.rels.pop("rId2")
y = etree.fromstring(p.rels.xml)
after = etree.tostring(y, pretty_print=True)
print(after.decode())
prs.save(file_path.rpartition(".")[0] + "_no_movies.pptx") Prints:
But I'm still getting the same error when I attempt to open the file. |
Okay, so a couple possible approaches:
The
You might want to do a mix of these two approaches. The |
Hello,
I'm trying to remove all movies on each slide with the following:
The code executes successfully, but when I try to open the output file, I get the following error:
Is there something that I'm doing wrong?
The text was updated successfully, but these errors were encountered: