Skip to content

Commit

Permalink
feat: add get subtitle helper
Browse files Browse the repository at this point in the history
  • Loading branch information
trueChazza committed Jun 23, 2022
1 parent 5924f6d commit 88003b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/media_server_web/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ defmodule MediaServerWeb.Helpers do
def reduce_size_for_poster_url(url) do
String.replace(url, "original", "w342")
end

def get_subtitle(path) do
File.ls!(path)
|> Enum.filter(fn item -> String.contains?(item, ".srt") end)
|> List.first()
end
end
20 changes: 20 additions & 0 deletions test/media_server_web/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,24 @@ defmodule MediaServerWeb.HelpersTest do
"https://some.domain.url/t/p/original/somePosterIdentifier.jpg"
) === "https://some.domain.url/t/p/w342/somePosterIdentifier.jpg"
end

@path "fixtures/movies/Caminandes Llama Drama (2013)"
@expected [".DS_Store", "Caminandes.Llama.Drama.1080p.mp4", "Caminandes.Llama.Drama.1080p.srt"]
@filtered "Caminandes.Llama.Drama.1080p.srt"

test "it should have subtitle" do
assert File.ls!(@path) == @expected

assert MediaServerWeb.Helpers.get_subtitle(@path) == @filtered
end

@path_without "fixtures/movies/Caminandes Gran Dillama (2013)"
@expected_without [".DS_Store", "Caminandes.Gran.Dillama.1080p.mp4"]
@filtered_without nil

test "it should not have subtitle" do
assert File.ls!(@path_without) == @expected_without

assert MediaServerWeb.Helpers.get_subtitle(@path_without) == @filtered_without
end
end

0 comments on commit 88003b2

Please sign in to comment.