Skip to content

Commit

Permalink
improve video export function
Browse files Browse the repository at this point in the history
  • Loading branch information
breunigs committed Feb 3, 2024
1 parent 22ec8cb commit ba8287a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
40 changes: 34 additions & 6 deletions data/articles/static/datenexport.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,20 @@ defmodule Data.Article.Static.Datenexport do
<p>Videos lassen sich mit den Tasten , und . (Komma und Punkt) um Einzelbilder vor- bzw. zurückspulen. Ggf. mehrmals drücken, die verwendete Technik dazu ist nicht ganz ausgereift. Wenn es immer noch nicht klappt, einmal von Hand das Video kurz abspielen und wieder pausieren – danach sollte es gehen.</p>
<h4>Ganze Videos</h4>
<p><a href={@video_download_path} rel="nofollow" download={@video_download_name}>Aktuelles Video in guter Qualität herunterladen</a>. Bitte nicht übertreiben und die Videos nacheinander herunterladen. Die Webseite ist nicht für den Massen-Download optimiert, weil ich den Aufwand dazu lieber in andere Sachen stecke.</p>
<p><a href={@video_download_path} rel="nofollow" download={@video_download_name}>Aktuelles Video in guter Qualität herunterladen</a> (<a href="#" data-text={@video_street_names} onclick="alert(this.dataset.text)">Straßennamen anzeigen</a>). Bitte nicht übertreiben und die Videos nacheinander herunterladen. Die Webseite ist nicht für den Massen-Download optimiert, weil ich den Aufwand dazu lieber in andere Sachen stecke.</p>
<h5>Historische Videos</h5>
<%= if @historic_videos == [] do %>
<p>Zu dieser Route sind keine älteren Aufnahmen bekannt.</p>
<% else %>
<p>Zu dieser Route (Abschnitt/Richtung) sind ältere Aufnahmen verfügbar:</p>
<ul>
<%= for {date, url, name} <- @historic_videos do %>
<li><a href={url} rel="nofollow" download={name}><%= date %> in guter Qualität herunterladen</a></li>
<%= for {date, url, name, streets} <- @historic_videos do %>
<li>
<a href={url} rel="nofollow" download={name}><%= date %> in guter Qualität herunterladen</a>
<br>
(<a href="#" data-text={streets} onclick="alert(this.dataset.text)">Straßennamen anzeigen</a>)
</li>
<% end %>
</ul>
<% end %>
Expand Down Expand Up @@ -89,14 +93,16 @@ defmodule Data.Article.Static.Datenexport do

%{
video_download_path: path,
video_download_name: "veloroute.hamburg_video_#{title}.m4s"
video_download_name: "veloroute.hamburg_video_#{title}.m4s",
video_street_names: street_names(video, title)
}
end

defp video_assigns(_assigns, fallback_title),
do: %{
video_download_path: "",
video_download_name: "veloroute.hamburg_video_#{fallback_title}.m4s"
video_download_name: "veloroute.hamburg_video_#{fallback_title}.m4s",
video_street_names: street_names(nil, nil)
}

defp download_assigns(%{video_hash: hash, video_start: timestamp}) do
Expand Down Expand Up @@ -134,7 +140,7 @@ defmodule Data.Article.Static.Datenexport do
|> Enum.uniq()
|> Enum.map(fn {historic_hash, date, text} ->
named = video_assigns(%{video_hash: historic_hash}, "#{date}-#{text}")
{date, named.video_download_path, named.video_download_name}
{date, named.video_download_path, named.video_download_name, named.video_street_names}
end)
|> Enum.sort()

Expand All @@ -156,4 +162,26 @@ defmodule Data.Article.Static.Datenexport do
end

defp clean(str), do: String.replace(str, ~r/[^a-zA-ZäüößÄÜÖẞ0-9_.-]+/u, "_")

defp street_names(nil, _title), do: "Für dieses Video sind leider keine Straßennamen bekannt"

defp street_names(video, title) do
video = Video.Generator.get(video)

names = if video, do: video.street_names(), else: []

names =
Enum.map(names, fn
%{timestamp: ts, text: street} ->
"#{Video.Timestamp.as_archival(ts)} #{if street == "", do: "?", else: street}"
end)

"""
#{title}
© OpenStreetMap (ODbL) https://www.openstreetmap.org/about/
#{Enum.join(names, "\n")}
"""
end
end
2 changes: 1 addition & 1 deletion lib/veloroute_web/live/frame_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ defmodule VelorouteWeb.FrameLive do
article = article || if route && !Article.List.related?(current, route), do: route

article =
if current == Data.Article.Static.ErweiterteFunktionen,
if current == Data.Article.Static.Datenexport,
do: nil,
else: article

Expand Down
11 changes: 11 additions & 0 deletions lib/video/timestamp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ defmodule Video.Timestamp do
timestamp |> in_milliseconds() |> as_html()
end

@spec as_archival(integer() | t()) :: binary()
def as_archival(duration_in_ms) when is_integer(duration_in_ms) do
{hours, minutes, seconds, _ms} = duration_split(duration_in_ms)

"#{hours}h #{pad_left(minutes)}m #{pad_left(seconds)}s"
end

def as_archival(timestamp) when valid_timestamp(timestamp) do
timestamp |> in_milliseconds() |> as_archival()
end

@doc """
Takes a timestamp and converts it to ISO8601 format:
https://en.wikipedia.org/wiki/ISO_8601#Durations
Expand Down
12 changes: 12 additions & 0 deletions test/article/article_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ defmodule ArticleTest do
assert [] == broken
end

test "historic track reference exists on file system" do
{:ok, known} = Settings.video_target_dir_abs() |> File.ls()
known = MapSet.new(known)

missing_files =
Enum.reject(list_historic_tracks(), fn ref ->
MapSet.member?(known, ref.historic_hash)
end)

assert [] == missing_files
end

test "historic track reference has valid date" do
broken =
Enum.reject(list_historic_tracks(), fn ref ->
Expand Down

0 comments on commit ba8287a

Please sign in to comment.