open-pod/test/openpod/provider/archive/parser_test.exs

74 lines
5 KiB
Elixir
Raw Normal View History

2020-06-08 23:37:11 +02:00
defmodule Openpod.Provider.Archive.ParserTest do
use ExUnit.Case
2020-06-08 23:37:11 +02:00
alias Openpod.Provider.Archive.Parser
setup_all do
json_metadata = "{\"created\":1590247789,\"d1\":\"ia601402.us.archive.org\",\"d2\":\"ia801402.us.archive.org\",\"dir\":\"/8/items/incontri-a-piano-terra\",\"files\":[{\"name\": \"metadata.json\",\"source\": \"original\",\"mtime\": \"1590258296\",\"size\": \"315\",\"md5\": \"a0c0e219cf3f13e54f2a4b3efef8e5c8\",\"crc32\": \"2d181b5c\",\"sha1\": \"8244b579a759edddd01c905dd11f8565e83d0898\",\"format\": \"JSON\"},{\"name\": \"cover.jpg\",\"source\": \"original\",\"mtime\": \"1590258445\",\"size\": \"10650\",\"md5\": \"15687b23e11f0099abbfe64eb1685c31\",\"crc32\": \"fbb1516a\",\"sha1\": \"98fa929c7554241cfa92bea8eba69b39c5d47603\",\"format\": \"JPEG\",\"rotation\": \"0\"},{\"name\":\"Confini mobili sulle alpi.mp3\",\"source\":\"original\",\"mtime\":\"1590135989\",\"size\":\"46933494\",\"md5\":\"e832ee9381a4f8af2d9727e2f49126ae\",\"crc32\":\"d709dd90\",\"sha1\":\"89c820a2dfd63cfbbf7aeefd191c653756b33fe3\",\"format\":\"VBR MP3\",\"length\":\"3902.35\",\"height\":\"0\",\"width\":\"0\",\"title\":\"Confini mobili sulle alpi (italian limes)\",\"creator\":\"APE Milano\",\"album\":\"Incontri a Piano Terra\",\"track\":\"02\",\"artist\":\"APE Milano\",\"genre\":\"podcast\"},{\"name\":\"Confini mobili sulle alpi.png\",\"source\":\"derivative\",\"format\":\"PNG\",\"original\":\"Confini mobili sulle alpi.mp3\",\"mtime\":\"1590137809\",\"size\":\"34656\",\"md5\":\"63893f9b00402a107682b5317e808523\",\"crc32\":\"b59ff609\",\"sha1\":\"a396716431cd0acedd243030093d0b31d792cfb3\"},{\"name\":\"Confini mobili sulle alpi_spectrogram.png\",\"source\":\"derivative\",\"format\":\"Spectrogram\",\"original\":\"Confini mobili sulle alpi.mp3\",\"mtime\":\"1590137854\",\"size\":\"273188\",\"md5\":\"557337665c6d9f962b2e91d169f25e1b\",\"crc32\":\"08b4b57c\",\"sha1\":\"88e088f9c4954aa8f0849b7e0d69cee8d7d42327\"}],\"files_count\":31,\"item_last_updated\":1590160774,\"item_size\":244544362,\"metadata\":{\"identifier\":\"incontri-a-piano-terra\",\"mediatype\":\"audio\",\"collection\":\"opensource_audio\",\"creator\":\"APE Milano\",\"description\":\"Qualche registrazione delle attivit\\u00e0 sociali che promuoviamo al Piano Terra di Milano\",\"language\":\"ita\",\"licenseurl\":\"https://creativecommons.org/licenses/by-nc-nd/4.0/\",\"scanner\":\"Internet Archive HTML5 Uploader 1.6.4\",\"subject\":[\"ape milano\",\"podcast\",\"montagna\"],\"title\":\"Incontri a Piano Terra\",\"uploader\":\"milanoape@gmail.com\",\"publicdate\":\"2020-05-22 08:30:21\",\"addeddate\":\"2020-05-22 08:30:21\",\"curation\":\"[curator]validator@archive.org[/curator][date]20200522085526[/date][comment]checked for malware[/comment]\",\"op_link\":\"http://www.ape-alveare.it/\",\"op_category\":\"Montagna\",\"op_explicit\":\"no\"},\"server\":\"ia601402.us.archive.org\",\"uniq\":122833277,\"workable_servers\":[\"ia601402.us.archive.org\",\"ia801402.us.archive.org\"]}"
2020-05-26 20:53:59 +02:00
token = %Parser{
identifier: "incontri-a-piano-terra",
archive_metadata: Jason.decode!(json_metadata),
2020-05-26 20:53:59 +02:00
}
{:ok, token: token}
end
2020-05-26 07:44:03 +02:00
test "podcast data are correctly converted", state do
2020-06-08 23:37:11 +02:00
%{podcast: podcast} = Parser.to_openpod_data(state[:token])
2020-05-26 20:53:59 +02:00
assert %{
title: "Incontri a Piano Terra",
description: "Qualche registrazione delle attività sociali che promuoviamo al Piano Terra di Milano",
webmaster: "milanoape@gmail.com",
managingEditor: "milanoape@gmail.com",
owner: %{
name: "APE Milano",
email: "milanoape@gmail.com",
},
keywords: ["ape milano", "podcast", "montagna"],
pubDate: ~U[2020-05-22 08:30:21Z],
2020-05-26 07:44:03 +02:00
lastBuildDate: ~U[2020-05-22 15:19:34Z],
author: "APE Milano",
language: "ita",
image: %{
link: "http://www.ape-alveare.it/",
title: "Incontri a Piano Terra",
url: "https://archive.org/download/incontri-a-piano-terra/cover.jpg"
},
link: "http://www.ape-alveare.it/",
category: "Montagna",
explicit: "no",
} == podcast
end
2020-06-07 22:23:29 +02:00
test "podcast subject metadata can also be a string", state do
token = state[:token] |> Map.update!(:archive_metadata, fn metadata -> put_in(metadata, ["metadata", "subject"], "foo;bar;baz") end)
2020-06-08 23:37:11 +02:00
%{podcast: podcast} = Parser.to_openpod_data(token)
2020-06-07 22:23:29 +02:00
assert %{
keywords: ["foo", "bar", "baz"],
} = podcast
end
2020-05-26 07:44:03 +02:00
test "items data are correctly converted", state do
2020-06-08 23:37:11 +02:00
%{items: items} = Parser.to_openpod_data(state[:token])
2020-05-26 20:53:59 +02:00
assert [
%{
title: "Confini mobili sulle alpi (italian limes)",
description: "",
pubDate: ~U[2020-05-22 08:26:29Z],
link: "https://archive.org/download/incontri-a-piano-terra/Confini%20mobili%20sulle%20alpi.mp3",
2020-05-26 07:44:03 +02:00
length: 3902,
summary: "",
keywords: ["Incontri a Piano Terra", "APE Milano", "podcast"],
explicit: "no",
2020-05-26 20:53:59 +02:00
# image: "https://archive.org/download/incontri-a-piano-terra/Confini%20mobili%20sulle%20alpi.png",
image: nil,
2020-05-26 07:44:03 +02:00
size: "46933494"
}
] == items
end
2020-05-26 07:44:03 +02:00
end