[Bugfix] Improve livestream detection (#362)

* Livestream status is now based off live_status instead of was_live

* Updated tests
This commit is contained in:
Kieran
2024-08-20 09:37:42 -07:00
committed by GitHub
parent 80209240d2
commit a6c61ccd0d
7 changed files with 17 additions and 14 deletions
+2 -2
View File
@@ -89,7 +89,7 @@ defmodule Pinchflat.YtDlp.Media do
NOTE: playlist_index is really only useful for playlists that will never change their order. NOTE: playlist_index is really only useful for playlists that will never change their order.
""" """
def indexing_output_template do def indexing_output_template do
"%(.{id,title,was_live,webpage_url,description,aspect_ratio,duration,upload_date,timestamp,playlist_index})j" "%(.{id,title,live_status,webpage_url,description,aspect_ratio,duration,upload_date,timestamp,playlist_index})j"
end end
@doc """ @doc """
@@ -104,7 +104,7 @@ defmodule Pinchflat.YtDlp.Media do
title: response["title"], title: response["title"],
description: response["description"], description: response["description"],
original_url: response["webpage_url"], original_url: response["webpage_url"],
livestream: !!response["was_live"], livestream: !!response["live_status"] && response["live_status"] != "not_live",
duration_seconds: response["duration"] && round(response["duration"]), duration_seconds: response["duration"] && round(response["duration"]),
short_form_content: response["webpage_url"] && short_form_content?(response), short_form_content: response["webpage_url"] && short_form_content?(response),
uploaded_at: response["upload_date"] && parse_uploaded_at(response), uploaded_at: response["upload_date"] && parse_uploaded_at(response),
@@ -101,7 +101,7 @@ defmodule Pinchflat.FastIndexing.FastIndexingHelpersTest do
id: "video2", id: "video2",
title: "Video 2", title: "Video 2",
webpage_url: "https://example.com/shorts/video2", webpage_url: "https://example.com/shorts/video2",
was_live: true, live_status: "is_live",
description: "desc2", description: "desc2",
aspect_ratio: 1.67, aspect_ratio: 1.67,
duration: 345.67, duration: 345.67,
@@ -43,11 +43,12 @@ defmodule Pinchflat.Metadata.MetadataParserTest do
test "it extracts the livestream flag", %{metadata: metadata} do test "it extracts the livestream flag", %{metadata: metadata} do
result = Parser.parse_for_media_item(metadata) result = Parser.parse_for_media_item(metadata)
assert result.livestream == metadata["was_live"] assert metadata["live_status"] == "not_live"
refute result.livestream
end end
test "the livestream flag defaults to false", %{metadata: metadata} do test "the livestream flag defaults to false", %{metadata: metadata} do
metadata = Map.put(metadata, "was_live", nil) metadata = Map.put(metadata, "live_status", nil)
result = Parser.parse_for_media_item(metadata) result = Parser.parse_for_media_item(metadata)
@@ -173,7 +173,7 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do
Phoenix.json_library().encode!(%{ Phoenix.json_library().encode!(%{
id: "video3", id: "video3",
title: "Video 3", title: "Video 3",
was_live: false, live_status: "not_live",
description: "desc3", description: "desc3",
# Only focusing on these because these are passed to functions that # Only focusing on these because these are passed to functions that
# could fail if they're not present # could fail if they're not present
@@ -289,7 +289,7 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do
id: "video2", id: "video2",
title: "Video 2", title: "Video 2",
webpage_url: "https://example.com/shorts/video2", webpage_url: "https://example.com/shorts/video2",
was_live: true, live_status: "is_live",
description: "desc2", description: "desc2",
aspect_ratio: 1.67, aspect_ratio: 1.67,
duration: 345.67, duration: 345.67,
+5 -3
View File
@@ -138,7 +138,9 @@ defmodule Pinchflat.YtDlp.MediaTest do
describe "indexing_output_template/0" do describe "indexing_output_template/0" do
test "contains all the greatest hits" do test "contains all the greatest hits" do
attrs = ~w(id title was_live webpage_url description aspect_ratio duration upload_date timestamp playlist_index)a attrs =
~w(id title live_status webpage_url description aspect_ratio duration upload_date timestamp playlist_index)a
formatted_attrs = "%(.{#{Enum.join(attrs, ",")}})j" formatted_attrs = "%(.{#{Enum.join(attrs, ",")}})j"
assert formatted_attrs == Media.indexing_output_template() assert formatted_attrs == Media.indexing_output_template()
@@ -152,7 +154,7 @@ defmodule Pinchflat.YtDlp.MediaTest do
"title" => "Trying to Wheelie Without the Rear Brake", "title" => "Trying to Wheelie Without the Rear Brake",
"description" => "I'm not sure what I expected.", "description" => "I'm not sure what I expected.",
"webpage_url" => "https://www.youtube.com/watch?v=TiZPUDkDYbk", "webpage_url" => "https://www.youtube.com/watch?v=TiZPUDkDYbk",
"was_live" => false, "live_status" => "not_live",
"aspect_ratio" => 1.0, "aspect_ratio" => 1.0,
"duration" => 60, "duration" => 60,
"upload_date" => "20210101", "upload_date" => "20210101",
@@ -239,7 +241,7 @@ defmodule Pinchflat.YtDlp.MediaTest do
assert %Media{duration_seconds: nil} = Media.response_to_struct(response) assert %Media{duration_seconds: nil} = Media.response_to_struct(response)
end end
test "sets livestream to false if the was_live field isn't present" do test "sets livestream to false if the live_status field isn't present" do
response = %{ response = %{
"webpage_url" => "https://www.youtube.com/watch?v=TiZPUDkDYbk", "webpage_url" => "https://www.youtube.com/watch?v=TiZPUDkDYbk",
"aspect_ratio" => 1.0, "aspect_ratio" => 1.0,
+1 -1
View File
@@ -93,7 +93,7 @@ defmodule Pinchflat.MediaFixtures do
id: "video1", id: "video1",
title: "Video 1", title: "Video 1",
webpage_url: "https://example.com/video1", webpage_url: "https://example.com/video1",
was_live: false, live_status: "not_live",
description: "desc1", description: "desc1",
aspect_ratio: 1.67, aspect_ratio: 1.67,
duration: 123.45, duration: 123.45,
+3 -3
View File
@@ -81,7 +81,7 @@ defmodule Pinchflat.SourcesFixtures do
id: "video1", id: "video1",
title: "Video 1", title: "Video 1",
webpage_url: "https://example.com/video1", webpage_url: "https://example.com/video1",
was_live: false, live_status: "not_live",
description: "desc1", description: "desc1",
aspect_ratio: 1.67, aspect_ratio: 1.67,
duration: 12.34, duration: 12.34,
@@ -91,7 +91,7 @@ defmodule Pinchflat.SourcesFixtures do
id: "video2", id: "video2",
title: "Video 2", title: "Video 2",
webpage_url: "https://example.com/video2", webpage_url: "https://example.com/video2",
was_live: true, live_status: "is_live",
description: "desc2", description: "desc2",
aspect_ratio: 1.67, aspect_ratio: 1.67,
duration: 345.67, duration: 345.67,
@@ -101,7 +101,7 @@ defmodule Pinchflat.SourcesFixtures do
id: "video3", id: "video3",
title: "Video 3", title: "Video 3",
webpage_url: "https://example.com/video3", webpage_url: "https://example.com/video3",
was_live: false, live_status: "not_live",
description: "desc3", description: "desc3",
aspect_ratio: 1.0, aspect_ratio: 1.0,
duration: 678.90, duration: 678.90,