Updated MI NFO builder to take in a filepath
This commit is contained in:
parent
84226034ec
commit
faf4f2e7e4
3 changed files with 20 additions and 24 deletions
|
|
@ -56,7 +56,9 @@ defmodule Pinchflat.Downloading.MediaDownloader do
|
||||||
|
|
||||||
defp determine_nfo_filepath(media_item, parsed_json) do
|
defp determine_nfo_filepath(media_item, parsed_json) do
|
||||||
if media_item.source.media_profile.download_nfo do
|
if media_item.source.media_profile.download_nfo do
|
||||||
NfoBuilder.build_and_store_for_media_item(parsed_json)
|
filepath = Path.rootname(parsed_json["filepath"]) <> ".nfo"
|
||||||
|
|
||||||
|
NfoBuilder.build_and_store_for_media_item(filepath, parsed_json)
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,11 @@ defmodule Pinchflat.Metadata.NfoBuilder do
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Builds an NFO file for a media item (read: single "episode") and
|
Builds an NFO file for a media item (read: single "episode") and
|
||||||
stores it in the same directory as the media file. Has the same name
|
stores it at the specified location.
|
||||||
as the media file, but with a .nfo extension.
|
|
||||||
|
|
||||||
Returns the filepath of the NFO file.
|
Returns the filepath of the NFO file.
|
||||||
"""
|
"""
|
||||||
def build_and_store_for_media_item(metadata) do
|
def build_and_store_for_media_item(filepath, metadata) do
|
||||||
filepath = Path.rootname(metadata["filepath"]) <> ".nfo"
|
|
||||||
nfo = build_for_media_item(metadata)
|
nfo = build_for_media_item(metadata)
|
||||||
|
|
||||||
FilesystemHelpers.write_p!(filepath, nfo)
|
FilesystemHelpers.write_p!(filepath, nfo)
|
||||||
|
|
|
||||||
|
|
@ -2,37 +2,33 @@ defmodule Pinchflat.Metadata.NfoBuilderTest do
|
||||||
use Pinchflat.DataCase
|
use Pinchflat.DataCase
|
||||||
|
|
||||||
alias Pinchflat.Metadata.NfoBuilder
|
alias Pinchflat.Metadata.NfoBuilder
|
||||||
|
alias Pinchflat.Filesystem.FilesystemHelpers
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
{:ok, %{metadata: render_parsed_metadata(:media_metadata)}}
|
filepath = FilesystemHelpers.generate_metadata_tmpfile(:json)
|
||||||
|
|
||||||
|
on_exit(fn -> File.rm!(filepath) end)
|
||||||
|
|
||||||
|
{:ok,
|
||||||
|
%{
|
||||||
|
metadata: render_parsed_metadata(:media_metadata),
|
||||||
|
filepath: filepath
|
||||||
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "build_and_store_for_media_item/1" do
|
describe "build_and_store_for_media_item/2" do
|
||||||
test "returns the filepath", %{metadata: metadata} do
|
test "returns the filepath", %{metadata: metadata, filepath: filepath} do
|
||||||
result = NfoBuilder.build_and_store_for_media_item(metadata)
|
result = NfoBuilder.build_and_store_for_media_item(filepath, metadata)
|
||||||
|
|
||||||
assert File.exists?(result)
|
assert File.exists?(result)
|
||||||
|
|
||||||
File.rm!(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "builds filepath based on media location", %{metadata: metadata} do
|
test "builds an NFO file", %{metadata: metadata, filepath: filepath} do
|
||||||
result = NfoBuilder.build_and_store_for_media_item(metadata)
|
result = NfoBuilder.build_and_store_for_media_item(filepath, metadata)
|
||||||
|
|
||||||
assert String.contains?(result, Path.rootname(metadata["filepath"]))
|
|
||||||
assert String.ends_with?(result, ".nfo")
|
|
||||||
|
|
||||||
File.rm!(result)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "builds an NFO file", %{metadata: metadata} do
|
|
||||||
result = NfoBuilder.build_and_store_for_media_item(metadata)
|
|
||||||
nfo = File.read!(result)
|
nfo = File.read!(result)
|
||||||
|
|
||||||
assert String.contains?(nfo, ~S(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>))
|
assert String.contains?(nfo, ~S(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>))
|
||||||
assert String.contains?(nfo, "<title>#{metadata["title"]}</title>")
|
assert String.contains?(nfo, "<title>#{metadata["title"]}</title>")
|
||||||
|
|
||||||
File.rm!(result)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue