Added code to compensate for yt-dlp bug

This commit is contained in:
Kieran Eglin 2024-03-14 09:07:53 -07:00
parent 028497f415
commit bd54e08555
No known key found for this signature in database
GPG key ID: 193984967FCF432D
2 changed files with 25 additions and 3 deletions

View file

@ -54,10 +54,23 @@ defmodule Pinchflat.Metadata.MetadataParser do
|> Enum.reverse() |> Enum.reverse()
|> Enum.find_value(fn attrs -> attrs["filepath"] end) |> Enum.find_value(fn attrs -> attrs["filepath"] end)
if thumbnail_filepath do
# NOTE: whole ordeal needed due to a bug I found in yt-dlp
# https://github.com/yt-dlp/yt-dlp/issues/9445
# Can be reverted to remove this entire conditional once fixed
%{
thumbnail_filepath:
thumbnail_filepath
|> String.split(~r{\.}, include_captures: true)
|> List.insert_at(-3, "-thumb")
|> Enum.join()
}
else
%{ %{
thumbnail_filepath: thumbnail_filepath thumbnail_filepath: thumbnail_filepath
} }
end end
end
defp parse_infojson_metadata(metadata) do defp parse_infojson_metadata(metadata) do
%{ %{

View file

@ -94,6 +94,15 @@ defmodule Pinchflat.Metadata.MetadataParserTest do
assert String.ends_with?(result.thumbnail_filepath, ".webp") assert String.ends_with?(result.thumbnail_filepath, ".webp")
end end
# NOTE: this can be removed once this bug is fixed
# https://github.com/yt-dlp/yt-dlp/issues/9445
# and the associated conditional in the parser is removed
test "automatically appends `-thumb` to the thumbnail filename", %{metadata: metadata} do
result = Parser.parse_for_media_item(metadata)
assert String.contains?(result.thumbnail_filepath, "-thumb.webp")
end
test "doesn't freak out if the media has no thumbnails", %{metadata: metadata} do test "doesn't freak out if the media has no thumbnails", %{metadata: metadata} do
metadata = Map.put(metadata, "thumbnails", %{}) metadata = Map.put(metadata, "thumbnails", %{})