front end media display tweaks

This commit is contained in:
meeb
2020-12-06 19:36:56 +11:00
parent 870f44d5e4
commit f3ab3b97f5
5 changed files with 44 additions and 13 deletions

View File

@@ -89,6 +89,16 @@ class Source(models.Model):
SOURCE_TYPE_YOUTUBE_PLAYLIST: 'id',
}
PUBLISHED_FIELD = { # Field returned by indexing which contains the published date
SOURCE_TYPE_YOUTUBE_CHANNEL: 'upload_date',
SOURCE_TYPE_YOUTUBE_PLAYLIST: 'upload_date',
}
TITLE_FIELD = { # Field returned by indexing which contains the media title
SOURCE_TYPE_YOUTUBE_CHANNEL: 'title',
SOURCE_TYPE_YOUTUBE_PLAYLIST: 'title',
}
uuid = models.UUIDField(
_('uuid'),
primary_key=True,
@@ -443,7 +453,8 @@ class Media(models.Model):
@property
def title(self):
return self.loaded_metadata.get('title', '').strip()
k = self.source.TITLE_FIELD.get(self.source.source_type, '')
return self.loaded_metadata.get(k, '').strip()
@property
def name(self):
@@ -452,7 +463,8 @@ class Media(models.Model):
@property
def upload_date(self):
upload_date_str = self.loaded_metadata.get('upload_date', '').strip()
k = self.source.PUBLISHED_FIELD.get(self.source.source_type, '')
upload_date_str = self.loaded_metadata.get(k, '').strip()
try:
return datetime.strptime(upload_date_str, '%Y%m%d')
except (AttributeError, ValueError) as e:

View File

@@ -7,8 +7,8 @@
<div class="row no-margin-bottom">
{% for m in media %}
<div class="col s12 m6 l4 xl3">
<a href="{% url 'sync:media-item' pk=m.pk %}" class="collection-item">
<div class="card mediacard">
<div class="card mediacard">
<a href="{% url 'sync:media-item' pk=m.pk %}" class="">
<div class="card-image">
<img src="{% if m.thumb %}{% url 'sync:media-thumb' pk=m.pk %}{% else %}{% static 'images/nothumb.png' %}{% endif %}">
<span class="card-title truncate">{{ m.source }}<br>
@@ -16,8 +16,8 @@
<span>{{ m.published|date:'Y-m-d' }}</span>
</span>
</div>
</div>
</a>
</a>
</div>
</div>
{% empty %}
<div class="col s12">

View File

@@ -338,7 +338,11 @@ class MediaThumbView(DetailView):
thumb = b64decode('R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAA'
'AAAABAAEAAAICTAEAOw==')
content_type = 'image/gif'
return HttpResponse(thumb, content_type=content_type)
response = HttpResponse(thumb, content_type=content_type)
# Thumbnail media is never updated so we can ask the browser to cache it
# for ages, 604800 = 7 days
response['Cache-Control'] = 'public, max-age=604800'
return response
class MediaItemView(DetailView):