[Enhancement] Start tracking a media item's duration (#146)

* Added duration field, started importing it during indexing and download

* Added duration to RSS feed
This commit is contained in:
Kieran
2024-03-28 21:51:04 -07:00
committed by GitHub
parent bdd97bde01
commit fae7ba3304
8 changed files with 56 additions and 5 deletions
+2
View File
@@ -22,6 +22,7 @@ defmodule Pinchflat.Media.MediaItem do
:source_id,
:short_form_content,
:upload_date,
:duration_seconds,
# these fields are captured only on download
:media_downloaded_at,
:media_filepath,
@@ -57,6 +58,7 @@ defmodule Pinchflat.Media.MediaItem do
field :short_form_content, :boolean, default: false
field :media_downloaded_at, :utc_datetime
field :upload_date, :date
field :duration_seconds, :integer
field :media_filepath, :string
field :media_size_bytes, :integer
+2 -1
View File
@@ -30,7 +30,8 @@ defmodule Pinchflat.Metadata.MetadataParser do
original_url: metadata["original_url"],
description: metadata["description"],
media_filepath: metadata["filepath"],
livestream: metadata["was_live"]
livestream: metadata["was_live"],
duration_seconds: metadata["duration"] && round(metadata["duration"])
}
end
@@ -80,6 +80,7 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do
<link>#{media_item.original_url}</link>
<description>#{safe(media_item.description)}</description>
<pubDate>#{generate_upload_date(media_item)}</pubDate>
<itunes:duration>#{media_item.duration_seconds}</itunes:duration>
<enclosure
url="#{media_stream_path(url_base, media_item)}"
length="#{media_item.media_size_bytes}"
+5 -2
View File
@@ -10,7 +10,8 @@ defmodule Pinchflat.YtDlp.Media do
:original_url,
:livestream,
:short_form_content,
:upload_date
:upload_date,
:duration_seconds
]
defstruct [
@@ -20,7 +21,8 @@ defmodule Pinchflat.YtDlp.Media do
:original_url,
:livestream,
:short_form_content,
:upload_date
:upload_date,
:duration_seconds
]
alias __MODULE__
@@ -86,6 +88,7 @@ defmodule Pinchflat.YtDlp.Media do
description: response["description"],
original_url: response["webpage_url"],
livestream: response["was_live"],
duration_seconds: response["duration"] && round(response["duration"]),
short_form_content: response["webpage_url"] && short_form_content?(response),
upload_date: response["upload_date"] && MetadataFileHelpers.parse_upload_date(response["upload_date"])
}