kensanata / mastodon-archive

Archive your statuses, favorites and media using the Mastodon API (i.e. login required)
https://alexschroeder.ch/software/Mastodon_Archive
GNU General Public License v3.0
358 stars 33 forks source link

HTML Export posts videos with a <img> tag #102

Closed lightnin closed 1 year ago

lightnin commented 1 year ago

When videos are included in posts they appear with a broken image icon in HTML exports.

Screenshot 2023-04-28 at 16 09 11

Clicking the icon loads the video correctly - but no preview is shown (as it is when viewing a normal mastodon timeline.)

The generated HTML appears to link the video with an img tag instead of a video tag.

Screenshot 2023-04-28 at 16 11 32

Here's a link to the same post live on my Pleroma instance: https://masto.amosamos.net/notice/AUs5GPCBAvYeZdrS8u

In my view videos in the exported HTML archive should look about like they do there, or on a normal Mastodon timeline - a preview with a play button.

(I made my export from Pleroma, but I'm assuming that this issue would affect Mastodon exports as well.)

lightnin commented 1 year ago

It looks like the following bit of code could be used to give the video the proper video tag, instead of tagging it as an image which is what happens now, causing the video to fail to load.

import magic
mime = magic.Magic(mime=True)
filename = mime.from_file(path_to_video)
if filename.find('video') != -1:
   print('it is video') 

From: https://stackoverflow.com/questions/14919609/how-to-check-if-a-file-is-a-video

lightnin commented 1 year ago

I ain't rich but I'd be happy to pay a 50 Euro bounty for a fix for this and #101, which would allow me to make the archive I need so badly for my PhD thesis. :)

kensanata commented 1 year ago

Try 1deb199 and let me know if it works for you? I personally don't archive media so I had to fiddle with my test JSON file by hand.

lightnin commented 1 year ago

Fantastic! Yes that works for the video. :) The other issue with the images is still there of course. This is outside of the scope of the bounty I offered, but I'm wondering if the browser will lazy load the videos automatically? The reason is that I'd like to host this as a static webpage on my site, but if it has to load 3 GB worth of video before the page is ready, it's gonna be rather slooow. Perhaps I'll test this tomorrow by putting up the html page on a test site. But either way - thanks! It's looking much better now.

kensanata commented 1 year ago

I don't see anything I could add for lazy loading, based on https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video … but if you know what to do, leave a comment and we'll figure it out.

kensanata commented 1 year ago

Hm, maybe try adding preload="none" to the video_template on https://github.com/kensanata/mastodon-archive/blob/main/mastodon_archive/html.py#L223 ? I'm not quite sure. If you have a lot of videos, you're in a better position to test this.