Browse Source

Fix duration display for less than 1 minute

Previously, a video 30 seconds long would have just displayed its
duration as "30". This fixes it to "0:30".
merge-requests/55/head
Deimos 6 years ago
parent
commit
bfa159a1bf
  1. 10
      tildes/tildes/models/topic/topic.py

10
tildes/tildes/models/topic/topic.py

@ -392,7 +392,15 @@ class Topic(DatabaseModel):
duration = self.get_content_metadata("duration") duration = self.get_content_metadata("duration")
if duration: if duration:
duration_delta = timedelta(seconds=duration) duration_delta = timedelta(seconds=duration)
metadata_strings.append(str(duration_delta).lstrip("0:"))
# When converted to str, timedelta always includes hours and minutes,
# so we want to strip off all the excess zeros and/or colons. However,
# if it's less than a minute we'll need to add one back.
duration_str = str(duration_delta).lstrip("0:")
if duration < 60:
duration_str = f"0:{duration_str}"
metadata_strings.append(duration_str)
# display the published date if it's more than 3 days before the topic # display the published date if it's more than 3 days before the topic
published_timestamp = self.get_content_metadata("published") published_timestamp = self.get_content_metadata("published")

Loading…
Cancel
Save