Depreciate generate_image_from_video_url(), put <video> in masonry instead #373

This commit is contained in:
freamon 2024-12-11 22:53:58 +00:00
parent 4ac3b0f97d
commit c851680b05
3 changed files with 31 additions and 35 deletions

View file

@ -927,9 +927,6 @@ def post_json_to_model(activity_log, post_json, user, community) -> Post:
post.image = image
elif is_video_url(post.url):
post.type = POST_TYPE_VIDEO
image = File(source_url=post.url)
db.session.add(image)
post.image = image
else:
post.type = POST_TYPE_LINK
post.url = remove_tracking_from_link(post.url)
@ -1012,7 +1009,7 @@ def make_image_sizes_async(file_id, thumbnail_width, medium_width, directory, to
session = get_task_session()
file: File = session.query(File).get(file_id)
if file and file.source_url:
# Videos
# Videos (old code. not invoked because file.source_url won't end .mp4 or .webm)
if file.source_url.endswith('.mp4') or file.source_url.endswith('.webm'):
new_filename = gibberish(15)
@ -1863,12 +1860,6 @@ def update_post_from_activity(post: Post, request_json: dict):
image = File(source_url=new_url)
if 'name' in request_json['object']['attachment'][0] and request_json['object']['attachment'][0]['name'] is not None:
image.alt_text = request_json['object']['attachment'][0]['name']
elif is_video_url(new_url):
post.type = POST_TYPE_VIDEO
if 'image' in request_json['object'] and 'url' in request_json['object']['image']:
image = File(source_url=request_json['object']['image']['url'])
else:
image = File(source_url=new_url)
else:
if 'image' in request_json['object'] and 'url' in request_json['object']['image']:
image = File(source_url=request_json['object']['image']['url'])
@ -1882,7 +1873,7 @@ def update_post_from_activity(post: Post, request_json: dict):
filename = opengraph.get('og:image') or opengraph.get('og:image:url')
if not filename.startswith('/'):
image = File(source_url=filename, alt_text=shorten_string(opengraph.get('og:title'), 295))
if is_video_hosting_site(new_url):
if is_video_hosting_site(new_url) or is_video_url(new_url):
post.type = POST_TYPE_VIDEO
else:
post.type = POST_TYPE_LINK

View file

@ -1260,12 +1260,7 @@ class Post(db.Model):
post.image = image
elif is_video_url(post.url): # youtube is detected later
post.type = constants.POST_TYPE_VIDEO
if 'image' in request_json['object'] and 'url' in request_json['object']['image']:
image = File(source_url=request_json['object']['image']['url'])
else:
image = File(source_url=post.url)
db.session.add(image)
post.image = image
# custom thumbnails will be added below in the "if 'image' in request_json['object'] and post.image is None:" section
else:
post.type = constants.POST_TYPE_LINK
domain = domain_from_url(post.url)

View file

@ -12,7 +12,7 @@
{% set post_title = post.title.replace('`', "'") %}
<div class="item{{ ' reported' if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator() }}{{ ' blocked' if content_blocked }}{{ ' blur' if blur_content }}"
{% if content_blocked %} title="{{ _('Filtered: ') }}{{ content_blocked }}"{% endif %}>
{% if post.image_id %}
{% if post.image_id and not (post.url and (post.url.endswith('.mp4') or post.url.endswith('.webm'))) %}
<div class="masonry_thumb" title="{{ post_title }}">
{% if post.type == POST_TYPE_LINK or post.type == POST_TYPE_VIDEO %}
{% if post.image.medium_url() %}
@ -36,22 +36,6 @@
alt="{{ post.image.alt_text if post.image.alt_text else '' }}" loading="{{ 'lazy' if low_bandwidth else 'eager' }}" /></a>
{% endif %}
</div>
<div class="masonry_info">
<div class="row">
<div class="col col-3">
<div class="voting_buttons_masonry">
{% include "post/_post_voting_buttons_masonry.html" %}
</div>
</div>
<div class="col col-8">
<p><a href="{{ url_for('activitypub.post_ap', post_id=post.id) }}" title="{{ post_title }}">{{ post_title }}</a></p>
</div>
<div class="col col-1 reply_col">
<a href="{{ url_for('activitypub.post_ap', post_id=post.id, sort='new' if sort == 'active' else None, _anchor='post_replies') }}" aria-label="{{ _('View comments') }}" aria-hidden="true"><span class="fe fe-reply"></span></a>
{% if post.reply_count %}<a href="{{ url_for('activitypub.post_ap', post_id=post.id, sort='new' if sort == 'active' else None, _anchor='post_replies') }}" aria-label="{{ _('View comments') }}">{{ post.reply_count }}</a>{% endif %}
</div>
</div>
</div>
{% else %}
{% if post.url and (post.url.endswith('.jpg') or post.url.endswith('.webp') or post.url.endswith('.png') or post.url.endswith('.gif') or post.url.endswith('.avif') or post.url.endswith('.jpeg')) %}
<div class="masonry_thumb" title="{{ post_title }}">
@ -74,11 +58,37 @@
</div>
</div>
{% elif post.url and (post.url.endswith('.mp4') or post.url.endswith('.webm')) -%}
<div class="masonry_thumb" title="{{ post_title }}">
<video class="responsive-video" controls preload="auto" {{ 'autoplay muted' if autoplay }} {{ 'loop' if post.community.loop_videos() }}>
{% if post.url.endswith('.mp4') -%}
<source src="{{ post.url }}" type="video/mp4" />
{% elif post.url.endswith('.webm') -%}
<source src="{{ post.url }}" type="video/webm" />
{% endif -%}
</video>
</div>
{% else %}
<div class="masonry_info_no_image">
<p><a href="{{ url_for('activitypub.post_ap', post_id=post.id) }}">{{ post_title }}</a></p>
<p><a href="{{ url_for('activitypub.post_ap', post_id=post.id) }}"></a></p>
</div>
{% endif %}
{% endif %}
<div class="masonry_info">
<div class="row">
<div class="col col-3">
<div class="voting_buttons_masonry">
{% include "post/_post_voting_buttons_masonry.html" %}
</div>
</div>
<div class="col col-8">
<p><a href="{{ url_for('activitypub.post_ap', post_id=post.id) }}" title="{{ post_title }}">{{ post_title }}</a></p>
</div>
<div class="col col-1 reply_col">
<a href="{{ url_for('activitypub.post_ap', post_id=post.id, sort='new' if sort == 'active' else None, _anchor='post_replies') }}" aria-label="{{ _('View comments') }}" aria-hidden="true"><span class="fe fe-reply"></span></a>
{% if post.reply_count %}<a href="{{ url_for('activitypub.post_ap', post_id=post.id, sort='new' if sort == 'active' else None, _anchor='post_replies') }}" aria-label="{{ _('View comments') }}">{{ post.reply_count }}</a>{% endif %}
</div>
</div>
</div>
</div>
{% endif %}