knadh / tg-archive

A tool for exporting Telegram group chats into static websites like mailing list archives.
MIT License
829 stars 121 forks source link

added video embedding #103

Closed iamcool0090 closed 1 year ago

iamcool0090 commented 1 year ago

for some reason the media.type is 'photo' for a video object( '.mp4' ) so used this method of identification of video files by comparing file extension against a list of video extensions. media object

knadh commented 1 year ago

Thanks @iamcool0090. I think this can be simplified into something like this. Could you please test and see if this works?

{% set ext = {{ m.media.url.split('/')[-1].split('.')[-1] }} %}
{% if is in(ext, ['mp4', 'webm', 'ogg', 'ogv', 'mov']) %}
    <video width="100%" height="100%" controls>
        <source src="{{ config.media_dir }}/{{ m.media.url }}">
    </video>
    <a href="{{ config.media_dir }}/{{ m.media.url }}">{{ m.media.title }}</a>
{% else %}
    <a href="{{ config.media_dir }}/{{ m.media.url }}">
        <img src="{{ config.media_dir }}/{{ m.media.thumb }}" class="thumb" /><br />
        <span class="filename">{{ m.media.title }}</span>
    </a>
{% endif %}
iamcool0090 commented 1 year ago

Yes this way of comparing the media extension with a set of media extensions is a better approach. Changed some part of the code you provided.

It's working perfectly

Thank You

iamcool0090 commented 1 year ago

{% set ext = m.media.url.split('/')[-1].split('.')[-1] %}
{% if ext in ['mp4', 'webm', 'ogg', 'ogv', 'mov'] %}
    <video width="100%" height="100%" controls>
        <source src="{{ config.media_dir }}/{{ m.media.url }}">
    </video>
    <a href="{{ config.media_dir }}/{{ m.media.url }}">{{ m.media.title }}</a>
{% else %}
    <a href="{{ config.media_dir }}/{{ m.media.url }}">
        <img src="{{ config.media_dir }}/{{ m.media.thumb }}" class="thumb" /><br />
        <span class="filename">{{ m.media.title }}</span>
    </a>
{% endif %}