Video support

This commit is contained in:
Thomas Sileo 2018-09-02 19:43:09 +02:00
parent bd0eaf5252
commit 3b186f23d3
5 changed files with 44 additions and 9 deletions

25
app.py
View file

@ -224,6 +224,14 @@ def remove_mongo_id(dat):
return dat
@app.template_filter()
def get_video_link(data):
for link in data:
if link.get("mimeType", "").startswith("video/"):
return link.get("href")
return None
@app.template_filter()
def get_actor_icon_url(url, size):
return _get_file_url(url, size, Kind.ACTOR_ICON)
@ -281,6 +289,11 @@ def url_or_id(d):
@app.template_filter()
def get_url(u):
print(f'GET_URL({u!r})')
if isinstance(u, list):
for l in u:
if l.get('mimeType') == 'text/html':
u = l
if isinstance(u, dict):
return u["href"]
elif isinstance(u, str):
@ -293,13 +306,17 @@ def get_url(u):
def get_actor(url):
if not url:
return None
if isinstance(url, list):
url = url[0]
if isinstance(url, dict):
url = url.get("id")
print(f"GET_ACTOR {url}")
try:
return get_backend().fetch_iri(url)
except (ActivityNotFoundError, ActivityGoneError):
return f"Deleted<{url}>"
except Exception:
return f"Error<{url}>"
except Exception as exc:
return f"Error<{url}/{exc!r}>"
@app.template_filter()
@ -319,7 +336,8 @@ def format_timeago(val):
@app.template_filter()
def has_type(doc, _type):
def has_type(doc, _types):
for _type in _to_list(_types):
if _type in _to_list(doc["type"]):
return True
return False
@ -1326,6 +1344,7 @@ def admin_lookup():
actor=data.get_actor().to_dict(),
)
print(data)
return render_template(
"lookup.html", data=data, meta=meta, url=request.form.get("url")
)

View file

@ -105,6 +105,10 @@ MEDIA_CACHE = MediaCache(GRIDFS, USER_AGENT)
def create_indexes():
DB.activities.create_index([("remote_id", pymongo.ASCENDING)])
DB.activities.create_index([("activity.object.id", pymongo.ASCENDING)])
DB.activities.create_index([
("activity.object.id", pymongo.ASCENDING),
("meta.deleted", pymongo.ASCENDING),
])
# Index for the block query
DB.activities.create_index(

View file

@ -324,3 +324,6 @@ input[type=submit] {
color: $primary-color;
text-transform: uppercase;
}
.note-video {
margin: 30px 0 10px 0;
}

View file

@ -29,7 +29,7 @@
{{ utils.display_actor_inline(data, size=80) }}
{% elif data | has_type('Create') %}
{{ utils.display_note(data.object, ui=True) }}
{% elif data | has_type('Note') %}
{% elif data | has_type(['Note', 'Article', 'Video']) %}
{{ utils.display_note(data, ui=True) }}
{% elif data | has_type('Announce') %}
{% set boost_actor = meta.actor %}

View file

@ -36,7 +36,7 @@
<div class="note-wrapper">
<div style="clear:both;height:20px;">
<a href="{{ actor | url_or_id | get_url }}" style="margin:0;text-decoration:none;margin: 0;text-decoration: none;display: block;width: 80%;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;float: left;" class="no-hover"><strong>{{ actor.name or actor.preferredUsername }}</strong>
<span class="l">@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor.preferredUsername }}</span>{% else %}{{ actor.preferredUsername }}{% endif %}@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor | url_or_id | get_url | domain }}</span>{% else %}{{ actor | url_or_id | get_url | domain }}{% endif %}</span></a>
<li><span class="l">@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor.preferredUsername }}</span>{% else %}{{ actor.preferredUsername }}{% endif %}@{% if not no_color and obj.id | is_from_outbox %}<span class="pcolor">{{ actor | url_or_id | get_url | domain }}</span>{% else %}{{ actor | url_or_id | get_url | domain }}{% endif %}</span></a>
{% if not perma %}
<span style="float:right;width: 20%;text-align: right;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;display: block;">
@ -46,7 +46,14 @@
{% endif %}
</div>
{% if obj.summary %}<p class="p-summary">{{ obj.summary | clean }}</p>{% endif %}
{% if obj | has_type('Video') %}
<div class="note-video">
<video controls preload="metadata" src="{{ obj.url | get_video_link }}" width="480">
</video>
</div>
{% endif %}
<div class="note-container{% if perma %} perma{%endif%} p-name e-content">
{% if obj | has_type('Article') %}
{{ obj.name }} <a href="{{ obj | url_or_id | get_url }}">{{ obj | url_or_id | get_url }}</a>
{% else %}
@ -57,12 +64,14 @@
{% if obj.attachment and obj | has_type('Note') %}
<div style="padding:20px 0;">
{% if obj.attachment | not_only_imgs %}
<h3 class="l">Attachment</h3>
<ul>
<h3 class="l">Attachments</h3>
<ul style="padding:0;">
{% endif %}
{% for a in obj.attachment %}
{% if (a.mediaType and a.mediaType.startswith("image/")) or (a.type and a.type == 'Image') %}
<a href="{{ a.url | get_attachment_url(None) }}"><img src="{{a.url | get_attachment_url(720) }}" class="img-attachment"></a>
{% elif (a.mediaType and a.mediaType.startswith("video/")) %}
<li><video controls preload="metadata" src="{{ a.url }}" width="480"></video></li>
{% else %}
<li><a href="{{a.url }}" class="l">{% if a.filename %}{{ a.filename }}{% else %}{{ a.url }}{% endif %}</a></li>
{% endif %}