[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
+24 -1
View File
@@ -104,7 +104,8 @@ defmodule Pinchflat.YtDlp.MediaTest do
original_url: "https://www.youtube.com/watch?v=TiZPUDkDYbk",
livestream: false,
short_form_content: false,
upload_date: Date.from_iso8601!("2021-01-01")
upload_date: Date.from_iso8601!("2021-01-01"),
duration_seconds: 60
} == Media.response_to_struct(response)
end
@@ -174,5 +175,27 @@ defmodule Pinchflat.YtDlp.MediaTest do
assert %Media{upload_date: nil} = Media.response_to_struct(response)
end
test "parses the duration" do
response = %{
"webpage_url" => "https://www.youtube.com/watch?v=TiZPUDkDYbk",
"aspect_ratio" => 1.0,
"duration" => 60.4,
"upload_date" => "20210101"
}
assert %Media{duration_seconds: 60} = Media.response_to_struct(response)
end
test "doesn't blow up if duration is missing" do
response = %{
"webpage_url" => "https://www.youtube.com/watch?v=TiZPUDkDYbk",
"aspect_ratio" => 1.0,
"duration" => nil,
"upload_date" => "20210101"
}
assert %Media{duration_seconds: nil} = Media.response_to_struct(response)
end
end
end