mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
add computed duration field
This commit is contained in:
parent
78d94dfe84
commit
be10ad4663
11 changed files with 45 additions and 5 deletions
|
@ -52,7 +52,7 @@ defmodule Philomena.Elasticsearch do
|
||||||
index_name = index.index_name()
|
index_name = index.index_name()
|
||||||
mapping = index.mapping().mappings.properties
|
mapping = index.mapping().mappings.properties
|
||||||
|
|
||||||
Elastix.Mapping.put(elastic_url(), index_name, "_doc", %{properties: mapping})
|
Elastix.Mapping.put(elastic_url(), index_name, "_doc", %{properties: mapping}, include_type_name: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def index_document(doc, module) do
|
def index_document(doc, module) do
|
||||||
|
|
|
@ -31,6 +31,7 @@ defmodule Philomena.Images.ElasticsearchIndex do
|
||||||
downvoters: %{type: "keyword"},
|
downvoters: %{type: "keyword"},
|
||||||
downvotes: %{type: "integer"},
|
downvotes: %{type: "integer"},
|
||||||
duplicate_id: %{type: "integer"},
|
duplicate_id: %{type: "integer"},
|
||||||
|
duration: %{type: "float"},
|
||||||
faves: %{type: "integer"},
|
faves: %{type: "integer"},
|
||||||
favourited_by_user_ids: %{type: "keyword"},
|
favourited_by_user_ids: %{type: "keyword"},
|
||||||
favourited_by_users: %{type: "keyword"},
|
favourited_by_users: %{type: "keyword"},
|
||||||
|
@ -46,7 +47,9 @@ defmodule Philomena.Images.ElasticsearchIndex do
|
||||||
mime_type: %{type: "keyword"},
|
mime_type: %{type: "keyword"},
|
||||||
orig_sha512_hash: %{type: "keyword"},
|
orig_sha512_hash: %{type: "keyword"},
|
||||||
original_format: %{type: "keyword"},
|
original_format: %{type: "keyword"},
|
||||||
|
pixels: %{type: "integer"},
|
||||||
score: %{type: "integer"},
|
score: %{type: "integer"},
|
||||||
|
size: %{type: "integer"},
|
||||||
sha512_hash: %{type: "keyword"},
|
sha512_hash: %{type: "keyword"},
|
||||||
source_url: %{type: "keyword"},
|
source_url: %{type: "keyword"},
|
||||||
tag_count: %{type: "integer"},
|
tag_count: %{type: "integer"},
|
||||||
|
@ -93,6 +96,9 @@ defmodule Philomena.Images.ElasticsearchIndex do
|
||||||
comment_count: image.comments_count,
|
comment_count: image.comments_count,
|
||||||
width: image.image_width,
|
width: image.image_width,
|
||||||
height: image.image_height,
|
height: image.image_height,
|
||||||
|
pixels: image.image_width * image.image_height,
|
||||||
|
size: image.image_size,
|
||||||
|
duration: image.image_duration,
|
||||||
tag_count: length(image.tags),
|
tag_count: length(image.tags),
|
||||||
aspect_ratio: image.image_aspect_ratio,
|
aspect_ratio: image.image_aspect_ratio,
|
||||||
wilson_score: wilson_score(image),
|
wilson_score: wilson_score(image),
|
||||||
|
|
|
@ -49,6 +49,7 @@ defmodule Philomena.Images.Image do
|
||||||
field :image_format, :string
|
field :image_format, :string
|
||||||
field :image_mime_type, :string
|
field :image_mime_type, :string
|
||||||
field :image_aspect_ratio, :float
|
field :image_aspect_ratio, :float
|
||||||
|
field :image_duration, :float
|
||||||
field :image_is_animated, :boolean, source: :is_animated
|
field :image_is_animated, :boolean, source: :is_animated
|
||||||
field :ip, EctoNetwork.INET
|
field :ip, EctoNetwork.INET
|
||||||
field :fingerprint, :string
|
field :fingerprint, :string
|
||||||
|
@ -131,6 +132,7 @@ defmodule Philomena.Images.Image do
|
||||||
:image_format,
|
:image_format,
|
||||||
:image_mime_type,
|
:image_mime_type,
|
||||||
:image_aspect_ratio,
|
:image_aspect_ratio,
|
||||||
|
:image_duration,
|
||||||
:image_orig_sha512_hash,
|
:image_orig_sha512_hash,
|
||||||
:image_sha512_hash,
|
:image_sha512_hash,
|
||||||
:uploaded_image,
|
:uploaded_image,
|
||||||
|
@ -145,6 +147,7 @@ defmodule Philomena.Images.Image do
|
||||||
:image_format,
|
:image_format,
|
||||||
:image_mime_type,
|
:image_mime_type,
|
||||||
:image_aspect_ratio,
|
:image_aspect_ratio,
|
||||||
|
:image_duration,
|
||||||
:image_orig_sha512_hash,
|
:image_orig_sha512_hash,
|
||||||
:image_sha512_hash,
|
:image_sha512_hash,
|
||||||
:uploaded_image,
|
:uploaded_image,
|
||||||
|
|
|
@ -69,11 +69,11 @@ defmodule Philomena.Images.Query do
|
||||||
defp anonymous_fields do
|
defp anonymous_fields do
|
||||||
[
|
[
|
||||||
int_fields:
|
int_fields:
|
||||||
~W(id width height comment_count score upvotes downvotes faves uploader_id faved_by_id tag_count),
|
~W(id width height comment_count score upvotes downvotes faves uploader_id faved_by_id tag_count pixels size),
|
||||||
float_fields: ~W(aspect_ratio wilson_score),
|
float_fields: ~W(aspect_ratio wilson_score duration),
|
||||||
date_fields: ~W(created_at updated_at first_seen_at),
|
date_fields: ~W(created_at updated_at first_seen_at),
|
||||||
literal_fields:
|
literal_fields:
|
||||||
~W(faved_by orig_sha512_hash sha512_hash uploader source_url original_format),
|
~W(faved_by orig_sha512_hash sha512_hash uploader source_url original_format mime_type),
|
||||||
ngram_fields: ~W(description),
|
ngram_fields: ~W(description),
|
||||||
custom_fields: ~W(gallery_id),
|
custom_fields: ~W(gallery_id),
|
||||||
default_field: {"namespaced_tags.name", :term},
|
default_field: {"namespaced_tags.name", :term},
|
||||||
|
|
|
@ -31,6 +31,7 @@ defmodule Philomena.Uploader do
|
||||||
"size" => analysis.size,
|
"size" => analysis.size,
|
||||||
"format" => analysis.extension,
|
"format" => analysis.extension,
|
||||||
"mime_type" => analysis.mime_type,
|
"mime_type" => analysis.mime_type,
|
||||||
|
"duration" => analysis.duration,
|
||||||
"aspect_ratio" => analysis.aspect_ratio,
|
"aspect_ratio" => analysis.aspect_ratio,
|
||||||
"orig_sha512_hash" => analysis.sha512,
|
"orig_sha512_hash" => analysis.sha512,
|
||||||
"sha512_hash" => analysis.sha512,
|
"sha512_hash" => analysis.sha512,
|
||||||
|
|
|
@ -14,6 +14,9 @@ defmodule PhilomenaWeb.ImageSorter do
|
||||||
comment_count
|
comment_count
|
||||||
tag_count
|
tag_count
|
||||||
wilson_score
|
wilson_score
|
||||||
|
pixels
|
||||||
|
size
|
||||||
|
duration
|
||||||
)
|
)
|
||||||
|
|
||||||
def parse_sort(params, query) do
|
def parse_sort(params, query) do
|
||||||
|
|
|
@ -61,6 +61,14 @@
|
||||||
= @image.image_width
|
= @image.image_width
|
||||||
| x
|
| x
|
||||||
= @image.image_height
|
= @image.image_height
|
||||||
|
|
||||||
|
= if not is_nil(@image.image_duration) and @image.image_is_animated and @image.image_duration > 0 do
|
||||||
|
span.image-size
|
||||||
|
|
|
||||||
|
- dur = ceil(@image.image_duration)
|
||||||
|
- {hh, mm, ss} = {div(dur, 3600), div(rem(dur, 3600), 60), rem(dur, 60)}
|
||||||
|
= :io_lib.format("~2..0B:~2..0B:~2..0B", [hh, mm, ss])
|
||||||
|
|
||||||
=<> String.upcase(to_string(@image.image_format))
|
=<> String.upcase(to_string(@image.image_format))
|
||||||
- size_kb = div(@image.image_size, 1000)
|
- size_kb = div(@image.image_size, 1000)
|
||||||
- size_mb = Float.round(size_kb / 1000.0, 2)
|
- size_mb = Float.round(size_kb / 1000.0, 2)
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
= error_tag f, :image_height
|
= error_tag f, :image_height
|
||||||
= error_tag f, :image_name
|
= error_tag f, :image_name
|
||||||
= error_tag f, :image_mime_type
|
= error_tag f, :image_mime_type
|
||||||
|
= error_tag f, :image_duration
|
||||||
= error_tag f, :image_orig_sha512_hash
|
= error_tag f, :image_orig_sha512_hash
|
||||||
|
|
||||||
.field.field--inline
|
.field.field--inline
|
||||||
|
|
|
@ -59,6 +59,8 @@ defmodule PhilomenaWeb.Api.Json.ImageView do
|
||||||
width: image.image_width,
|
width: image.image_width,
|
||||||
height: image.image_height,
|
height: image.image_height,
|
||||||
mime_type: image.image_mime_type,
|
mime_type: image.image_mime_type,
|
||||||
|
size: image.image_size,
|
||||||
|
duration: image.image_duration,
|
||||||
format: image.image_format,
|
format: image.image_format,
|
||||||
aspect_ratio: image.image_aspect_ratio,
|
aspect_ratio: image.image_aspect_ratio,
|
||||||
name: image.image_name,
|
name: image.image_name,
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
defmodule Philomena.Repo.Migrations.AddDurationToImages do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table("images") do
|
||||||
|
add :image_duration, :float
|
||||||
|
end
|
||||||
|
|
||||||
|
# After successful migration:
|
||||||
|
# alias Philomena.Elasticsearch
|
||||||
|
# alias Philomena.Images.Image
|
||||||
|
# Elasticsearch.update_mapping!(Image)
|
||||||
|
end
|
||||||
|
end
|
|
@ -882,7 +882,8 @@ CREATE TABLE public.images (
|
||||||
destroyed_content boolean DEFAULT false NOT NULL,
|
destroyed_content boolean DEFAULT false NOT NULL,
|
||||||
hidden_image_key character varying,
|
hidden_image_key character varying,
|
||||||
scratchpad character varying,
|
scratchpad character varying,
|
||||||
hides_count integer DEFAULT 0 NOT NULL
|
hides_count integer DEFAULT 0 NOT NULL,
|
||||||
|
image_duration double precision
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -4706,3 +4707,4 @@ INSERT INTO public."schema_migrations" (version) VALUES (20200503002523);
|
||||||
INSERT INTO public."schema_migrations" (version) VALUES (20200607000511);
|
INSERT INTO public."schema_migrations" (version) VALUES (20200607000511);
|
||||||
INSERT INTO public."schema_migrations" (version) VALUES (20200617111116);
|
INSERT INTO public."schema_migrations" (version) VALUES (20200617111116);
|
||||||
INSERT INTO public."schema_migrations" (version) VALUES (20200617113333);
|
INSERT INTO public."schema_migrations" (version) VALUES (20200617113333);
|
||||||
|
INSERT INTO public."schema_migrations" (version) VALUES (20200706171350);
|
||||||
|
|
Loading…
Reference in a new issue