Skip to content

Commit

Permalink
Cleaned up code (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
spietras authored Jul 20, 2024
1 parent db89e04 commit 3daa4d3
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/main.liq
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ SOURCE_PATH = "src/"
RESOURCES_PATH = "#{SOURCE_PATH}/resources/"
FALLBACK_PATH = "#{RESOURCES_PATH}/audio/fallback.mp3"

TARGET_METADATA = ["title", "artist"]
ALLOWED_METADATA_KEYS = ["title", "artist"]

### Utils

def get_env(~default="", key) =
list.assoc(default=default, key, environment())
end

def keep_metadata(keys, source) =
def filter_metadata(keys, source) =
predicate = fun (md) -> list.mem(fst(md), keys)

metadata.map(
Expand All @@ -22,15 +22,16 @@ end

### Variables

host = get_env(default="0.0.0.0", "FUSION__SERVER__HOST")
port = int_of_string(get_env(default="9000", "FUSION__SERVER__PORT"))
streamcast_host = get_env(default="localhost", "FUSION__STREAMCAST__ICY__HOST")
streamcast_port =
server_host = get_env(default="0.0.0.0", "FUSION__SERVER__HOST")
server_port = int_of_string(get_env(default="9000", "FUSION__SERVER__PORT"))
streamcast_icy_host =
get_env(default="localhost", "FUSION__STREAMCAST__ICY__HOST")
streamcast_icy_port =
int_of_string(get_env(default="8000", "FUSION__STREAMCAST__ICY__PORT"))
streamcast_user = get_env(default="source", "FUSION__STREAMCAST__ICY__USER")
streamcast_password =
streamcast_icy_user = get_env(default="source", "FUSION__STREAMCAST__ICY__USER")
streamcast_icy_password =
get_env(default="password", "FUSION__STREAMCAST__ICY__PASSWORD")
streamcast_mount =
streamcast_icy_mount =
get_env(default="radio.mp3", "FUSION__STREAMCAST__ICY__MOUNT")

### Inputs
Expand All @@ -39,26 +40,29 @@ music = single(FALLBACK_PATH)

live =
input.srt(
bind_address=host, port=port, read_timeout=null(), write_timeout=null()
bind_address=server_host,
port=server_port,
read_timeout=null(),
write_timeout=null()
)
live = buffer(live)

### Stream

radio = fallback(track_sensitive=false, [live, music])
radio = keep_metadata(TARGET_METADATA, radio)
radio = filter_metadata(ALLOWED_METADATA_KEYS, radio)
radio = mksafe(radio)

### Outputs

output.icecast(
%mp3,
host=streamcast_host,
port=streamcast_port,
user=streamcast_user,
password=streamcast_password,
mount=streamcast_mount,
icy_metadata=TARGET_METADATA,
host=streamcast_icy_host,
port=streamcast_icy_port,
user=streamcast_icy_user,
password=streamcast_icy_password,
mount=streamcast_icy_mount,
icy_metadata=ALLOWED_METADATA_KEYS,
icy_song=fun (_) -> null(),
radio
)

0 comments on commit 3daa4d3

Please sign in to comment.