153 lines
4.5 KiB
Elixir
153 lines
4.5 KiB
Elixir
defmodule Bright.TorrentfileTest do
|
|
use Bright.DataCase
|
|
|
|
alias Bright.Torrentfile
|
|
alias Bright.Cache
|
|
|
|
@test_ts_fixture "./test/fixtures/test-fixture.ts"
|
|
@test_tracker_url "http://localhost:6969/announce"
|
|
@test_web_seed_url "https://futureporn-b2.b-cdn.net/test-fixture.ts"
|
|
@test_site_url "https://futureporn.net"
|
|
|
|
describe "torrentfile" do
|
|
import Bright.StreamsFixtures
|
|
|
|
test "version/0" do
|
|
{:ok, ver_num} = Torrentfile.version()
|
|
assert :ok
|
|
assert Regex.match?(~r"v\d\.\d\.\d", ver_num)
|
|
end
|
|
|
|
@tag :unit
|
|
test "torrentfile_path" do
|
|
assert Regex.match?(~r"\/torrentfile", Torrentfile.torrentfile_path())
|
|
end
|
|
|
|
test "create/2" do
|
|
input_path = @test_ts_fixture
|
|
stream = stream_fixture()
|
|
|
|
vod =
|
|
vod_fixture(%{
|
|
stream_id: stream.id,
|
|
s3_cdn_url: "https://futureporn-b2.b-cdn.net/test-fixture.ts"
|
|
})
|
|
|
|
{:ok, output} = Torrentfile.create(vod, input_path)
|
|
assert :ok
|
|
assert is_binary(output.save_path)
|
|
assert output.save_path =~ ".torrent"
|
|
assert is_binary(output.btih)
|
|
assert is_binary(output.btmh)
|
|
assert output.btih === "7eb6caf98a7e727004ddbdbbd2035cb58300899a"
|
|
|
|
assert output.btmh ===
|
|
"1220f3292c3088ede7ceb29c335ad2ce690c8b934ecd03cde2daaf95ac82327eb25b"
|
|
|
|
assert File.exists?(output.save_path)
|
|
end
|
|
|
|
test "create/7" do
|
|
input_path = @test_ts_fixture
|
|
output_path = Cache.generate_filename("test", "torrent")
|
|
tracker_url = @test_tracker_url
|
|
comment = @test_site_url
|
|
source_url = @test_site_url
|
|
web_seed_url = @test_web_seed_url
|
|
meta_version = 3
|
|
|
|
{:ok, output} =
|
|
Torrentfile.create(
|
|
input_path,
|
|
output_path,
|
|
tracker_url,
|
|
comment,
|
|
source_url,
|
|
web_seed_url,
|
|
meta_version
|
|
)
|
|
|
|
assert :ok
|
|
|
|
assert is_binary(output.save_path)
|
|
assert output.save_path === output_path
|
|
assert output.btih === "da4f5b7724bb17e32f8a38792b007f316b33e962"
|
|
assert is_binary(output.btih)
|
|
# assert is_binary(output.btmh)
|
|
assert File.exists?(output_path)
|
|
end
|
|
|
|
@tag :unit
|
|
test "parses magnet link, save path, btih and btmh correctly" do
|
|
output = """
|
|
magnet:?xt=urn:btih:157835a64d398fd63d83b5fd6dac5612bd60b6c6&xt=urn:btmh:12201bf9590518d84900ca3e4a88a7fe5f6a246deff2cf37d3acc24b7f64a8b0b572&dn=test-fixture.ts&tr=https%3A%2F%2Ftracker.futureporn.net%2Fannounce
|
|
|
|
Torrent Save Path: /home/cj/Downloads/test-fixture.torrent
|
|
"""
|
|
|
|
expected = %{
|
|
magnet:
|
|
"magnet:?xt=urn:btih:157835a64d398fd63d83b5fd6dac5612bd60b6c6&xt=urn:btmh:12201bf9590518d84900ca3e4a88a7fe5f6a246deff2cf37d3acc24b7f64a8b0b572&dn=test-fixture.ts&tr=https%3A%2F%2Ftracker.futureporn.net%2Fannounce",
|
|
save_path: "/home/cj/Downloads/test-fixture.torrent",
|
|
btih: "157835a64d398fd63d83b5fd6dac5612bd60b6c6",
|
|
btmh: "12201bf9590518d84900ca3e4a88a7fe5f6a246deff2cf37d3acc24b7f64a8b0b572"
|
|
}
|
|
|
|
assert Torrentfile.parse_output(output) == expected
|
|
end
|
|
|
|
@tag :unit
|
|
test "returns nil values when output is empty" do
|
|
assert Torrentfile.parse_output("") == %{magnet: nil, save_path: nil, btih: nil, btmh: nil}
|
|
end
|
|
|
|
@tag :unit
|
|
test "handles missing save path" do
|
|
output = "magnet:?xt=urn:btih:12345"
|
|
|
|
assert Torrentfile.parse_output(output) == %{
|
|
magnet: "magnet:?xt=urn:btih:12345",
|
|
save_path: nil,
|
|
btih: "12345",
|
|
btmh: nil
|
|
}
|
|
end
|
|
|
|
@tag :unit
|
|
test "handles missing magnet link" do
|
|
output = "Torrent Save Path: /downloads/test.torrent"
|
|
|
|
assert Torrentfile.parse_output(output) == %{
|
|
magnet: nil,
|
|
save_path: "/downloads/test.torrent",
|
|
btih: nil,
|
|
btmh: nil
|
|
}
|
|
end
|
|
|
|
@tag :unit
|
|
test "handles missing btih" do
|
|
output = "Torrent Save Path: /downloads/test.torrent"
|
|
|
|
assert Torrentfile.parse_output(output) == %{
|
|
btih: nil,
|
|
magnet: nil,
|
|
btmh: nil,
|
|
save_path: "/downloads/test.torrent"
|
|
}
|
|
end
|
|
|
|
@tag :unit
|
|
test "handles missing btmh" do
|
|
output = "Torrent Save Path: /downloads/test.torrent"
|
|
|
|
assert Torrentfile.parse_output(output) == %{
|
|
btmh: nil,
|
|
magnet: nil,
|
|
btih: nil,
|
|
save_path: "/downloads/test.torrent"
|
|
}
|
|
end
|
|
end
|
|
end
|