Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide DJ display name in pregenerated LS code, like the login name live_dj(), for use in video stream #6362

Closed
Moonbase59 opened this issue Jun 19, 2023 · 9 comments
Labels
enhancement Additions or changes are desired for a part of the software. in progress A workaround, temporary or permanent fix is in progress

Comments

@Moonbase59
Copy link
Contributor

Moonbase59 commented Jun 19, 2023

Installation Method

Docker Installation

AzuraCast Release Channel

Rolling Release Channel

Current AzuraCast Version

Rolling Release #9f7825e (2023-06-10 16:39)

What happened?

I’m trying to get my head around showing a "Live: DJ Display Name" indication in my video stream (code will be published here when finished).

Using Liquidsoap 2.2.0+git@dcf405ff4 (installed inside Docker; works well), I’d like to show the current live DJ’s display name, but I can’t get the code and API calls sorted out, so this little request (had to use GH since the "Features" page only allows so much text and no images).

I’ve gotten as far as to add a red "Live" indicator but can only show the DJ’s login name (from using live_dj()).

video m2t - VLC media player_010

It would be just great if we could also have a variable like live_dj_name within the pre-generated Liquidsoap code. Since you of course know the possibilities best, could we have that?

I think it might possibly fit into def dj_auth(login) or def live_connected(header), what do you think?

I’m sure it would be a great addition to those stations that use video streaming, to easily get at the DJ display name (and possibly even the DJ’s image), to make a real great video stream.

Relevant log output

No response

@Moonbase59 Moonbase59 added the needs investigation An issue that needs further investigation by a developer to determine the root cause. label Jun 19, 2023
@SpeedyCharly
Copy link

SpeedyCharly commented Jun 19, 2023

Our station doesn't do video streaming but such a feature would still be useful to us... We have a banner above our chatroom which displays an animation with the faces of all our djs. We could use these variables, importing them to our web site to switch the banner to ones displaying the dj during his/her live broadcast.
So add my vote to this wish list... and, @Moonbase59 please add this to the the Azuracast Feature Suggestion thread

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale An inactive github issue that has had no activity in 20 days. label Aug 15, 2023
@Moonbase59
Copy link
Contributor Author

Would still be nice to have, but in the meantime I call the API and have to traverse the list of streamers to get at it.

@github-actions github-actions bot removed the stale An inactive github issue that has had no activity in 20 days. label Aug 19, 2023
@BusterNeece
Copy link
Member

BusterNeece commented Aug 30, 2023

@Moonbase59 I looked into this, and tried expanding our API response parsing so we could pass rich JSON data back from the API, but Liquidsoap's type system seems to absolutely hate it. I flagged that with the LS team and haven't heard back. I'd love to be able to supply richer response data from API commands to the LS script, because there are several other things we could do with that.

@Moonbase59
Copy link
Contributor Author

Moonbase59 commented Aug 31, 2023

Hm, ok, so I stick with my API call for now.

The dumb thing is I have to traverse the streamers list and compare the login name to get the real name … code I hate… Here’s part of my video stream code that does that:

def azuracast_api_get(~timeout=2.0, url) =
    full_url = "#{my_api_url}/#{url}"

    log("API #{url} - Sending GET request to '#{full_url}'")
    try
        response = http.get(full_url,
            headers=[
                ("accept", "application/json"),
                ("User-Agent", "Liquidsoap AzuraCast"),
                ("X-API-Key", "#{my_api_key}")
            ],
            timeout=timeout
        )

        log("API #{url} - Response (#{response.status_code}): #{response}")
        "#{response}"
    catch err do
        log("API #{url} - Error: #{error.kind(err)} - #{error.message(err)}")
        "false"
    end
end

... (other code) ...

    if live_dj() != "" then
      url = "streamers"
      djs = azuracast_api_get(url)
      #log("API #{url} - #{djs}")
      # get current live DJ’s name and image from streamers list
      let json.parse (dj_list : [{
        streamer_username: string,
        display_name: string,
        has_custom_art: bool,
        art: string
        }]) = djs
      dj = list.find(fun(entry) -> entry.streamer_username == live_dj(), dj_list)
      log("API #{url} - #{dj}")
      live_dj_color.set(0xeb0000) # red
      live_dj_alpha.set(0.5)
      live_dj_text.set("Live: #{dj.display_name}")
      if dj.has_custom_art then
        # if we have a DJ image, use it instead of the station logo
        live_dj_image.set(dj.art)
        log("DJ IMAGE: #{live_dj_image()}")
      else
        # no image, use station logo
        live_dj_image.set(logo_file)
      end
    else
      ... (other code) ...

Still clumsy and badly indented, I know… ;-) …but works:

vlcsnap-2023-08-30-15h41m42s373

My assumption was you could easily do it in dj_auth(login) but spelunking in the code told me it’s not there already, so you’d have to do something like I do, after all…

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale An inactive github issue that has had no activity in 20 days. label Oct 27, 2023
@Moonbase59
Copy link
Contributor Author

Would still be a "nice-to-have", even if it can be done "the hard way".

@BusterNeece BusterNeece added enhancement Additions or changes are desired for a part of the software. in progress A workaround, temporary or permanent fix is in progress and removed needs investigation An issue that needs further investigation by a developer to determine the root cause. stale An inactive github issue that has had no activity in 20 days. labels Oct 29, 2023
@BusterNeece
Copy link
Member

Tagging this as in-progress since we absolutely do want to get into parsing JSON responses inside Liquidsoap. I have an idea on how to do it, I just haven't gotten back around to doing it. Lost most of this month to chronic back pain flare-ups.

@Moonbase59
Copy link
Contributor Author

Yeah, it’s actually not hard and I do it for my videostreams all the time. We could also just close this, if it requires extra API calls in LS. My videostream uses it like so:

The function to make API GET calls with:

def azuracast_api_get(~timeout=2.0, url) =
    full_url = "#{my_api_url}/#{url}"

    log(level=4, label="api_get", "API #{url} - Sending GET request to '#{full_url}'")
    try
        response = http.get(full_url,
            headers=[
                ("accept", "application/json"),
                ("User-Agent", "Liquidsoap AzuraCast"),
                ("X-API-Key", "#{my_api_key}")
            ],
            timeout=timeout
        )

        log(level=4, label="api_get", "API #{url} - Response (#{response.status_code}): #{response}")
        "#{response}"
    catch err do
        log(level=2, label="api_get", "API #{url} - Error: #{error.kind(err)} - #{error.message(err)}")
        "false"
    end
end

When metadata updates occur:

# API calls take time, let’s run this in a separate thread, so we don’t block anything
a.on_metadata(fun(m) -> thread.run(fast=false, {update_nowplaying(m)}))

and within that:

if m["is_live"] == "true" then
  if live_dj() != "" then
    url = "streamers"
    djs = azuracast_api_get(url)
    # get current live DJ’s name and image from streamers list
    let json.parse (dj_list : [{
      streamer_username: string,
      display_name: string,
      has_custom_art: bool,
      art: string
      }]) = djs
    dj = list.find(fun(entry) -> entry.streamer_username == live_dj(), dj_list)
    log(level=3, "API #{url} - #{dj}")
    show_color := 0xeb0000 # red
    show_alpha := 0.5
    show_text := "Live: #{dj.display_name}"
    if dj.has_custom_art then
      # if we have a DJ image, use it instead of the station logo
      show_image := dj.art
      log(level=3, label="nowplaying", "Show: \"#{show_text()}\", color=0x#{string.hex_of_int(pad=6,show_color())}, alpha=#{show_alpha()}, image='#{show_image()}'")
    else
      # no image, use station logo
      show_image := logo_file
      log(level=3, label="nowplaying", "Show: \"#{show_text()}\", color=0x#{string.hex_of_int(pad=6,show_color())}, alpha=#{show_alpha()}, image='#{show_image()}'")
    end

Get well soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Additions or changes are desired for a part of the software. in progress A workaround, temporary or permanent fix is in progress
Projects
None yet
Development

No branches or pull requests

3 participants