-module(inlay@soundcloud). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/inlay/soundcloud.gleam"). -export([detect/1, render/2]). -file("src/inlay/soundcloud.gleam", 45). -spec detect_soundcloud(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()). detect_soundcloud(Url) -> case gleam@uri:path_segments(erlang:element(6, Url)) of [_, _] -> {some, {sound_cloud_track, erlang:element(6, Url)}}; [_, <<"sets"/utf8>>, _] -> {some, {sound_cloud_track, erlang:element(6, Url)}}; _ -> none end. -file("src/inlay/soundcloud.gleam", 8). -spec detect(gleam@uri:uri()) -> gleam@option:option(inlay@embed:embed()). detect(Url) -> case erlang:element(4, Url) of {some, <<"soundcloud.com"/utf8>>} -> detect_soundcloud(Url); {some, <<"www.soundcloud.com"/utf8>>} -> detect_soundcloud(Url); _ -> none end. -file("src/inlay/soundcloud.gleam", 16). -spec render(inlay@embed:embed(), inlay@embed:config()) -> {ok, lustre@vdom@vnode:element(any())} | {error, nil}. render(Embed, Config) -> case Embed of {sound_cloud_track, Path} -> {Width, Height} = case erlang:element(12, Config) of {some, {sound_cloud_config, W, H}} -> {gleam@option:unwrap(W, 300), gleam@option:unwrap(H, 166)}; none -> {300, 166} end, Encoded_url = gleam_stdlib:percent_encode( <<"https://soundcloud.com"/utf8, Path/binary>> ), Src = <<"https://w.soundcloud.com/player/?url="/utf8, Encoded_url/binary>>, {ok, lustre@element@html:'div'( [], [lustre@element@html:iframe( [lustre@attribute:src(Src), lustre@attribute:width(Width), lustre@attribute:height(Height), lustre@attribute:attribute( <<"frameborder"/utf8>>, <<"0"/utf8>> ), lustre@attribute:attribute( <<"allow"/utf8>>, <<"autoplay"/utf8>> ), lustre@attribute:attribute( <<"loading"/utf8>>, <<"lazy"/utf8>> )] )] )}; _ -> {error, nil} end.