defmodule Veo do @moduledoc """ A library for interacting with Supermaker AI's Veo video service. Provides utility functions for constructing URLs and performing common video-related operations. """ @base_url "https://supermaker.ai/video/veo" @doc """ Builds a URL to the Veo service with optional parameters. ## Examples iex> Veo.build_url() "https://supermaker.ai/video/veo" iex> Veo.build_url(query: [id: 123, format: "mp4"]) "https://supermaker.ai/video/veo?id=123&format=mp4" """ def build_url(opts \\ []) do query = Keyword.get(opts, :query, []) @base_url |> build_query_string(query) end defp build_query_string(base_url, []), do: base_url defp build_query_string(base_url, query) when is_list(query) do query_string = query |> Enum.map(fn {key, value} -> "#{key}=#{value}" end) |> Enum.join("&") "#{base_url}?#{query_string}" end @doc """ Calculates the aspect ratio of a video given its width and height. ## Examples iex> Veo.aspect_ratio(1920, 1080) 1.7777777777777777 iex> Veo.aspect_ratio(1280, 720) 1.7777777777777777 """ def aspect_ratio(width, height) when is_number(width) and is_number(height) do width / height end @doc """ Converts seconds to a human-readable time format (HH:MM:SS). ## Examples iex> Veo.format_duration(65) "00:01:05" iex> Veo.format_duration(3661) "01:01:01" """ def format_duration(seconds) when is_integer(seconds) do hours = div(seconds, 3600) minutes = div(rem(seconds, 3600), 60) remaining_seconds = rem(seconds, 60) pad = fn x -> Integer.to_string(x) |> String.pad_leading(2, "0") end "#{pad.(hours)}:#{pad.(minutes)}:#{pad.(remaining_seconds)}" end @doc """ Determines if a given URL is a valid video URL (basic check). This function performs a simple check to see if the URL contains "video" and ends with a common video extension. It does *not* validate the URL against a specific service. ## Examples iex> Veo.is_valid_video_url?("https://example.com/video/123.mp4") true iex> Veo.is_valid_video_url?("https://example.com/image.jpg") false """ def is_valid_video_url?(url) when is_binary(url) do String.contains?(url, "video") && String.ends_with?(url, ~r/\.(mp4|avi|mov|webm)$/) end end