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

Adds Play Internet Sound #28183

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

Adds Play Internet Sound #28183

wants to merge 19 commits into from

Conversation

Bm0n
Copy link
Contributor

@Bm0n Bm0n commented Jan 30, 2025

What Does This PR Do

Ports:
tgstation/tgstation#30457
tgstation/tgstation#30598
tgstation/tgstation#33839
tgstation/tgstation#36080
tgstation/tgstation#52426 (Playsound/TGchat elements MOST SIMILAR TO THIS VERSION)
tgstation/tgstation#72805 (Some elements)
tgstation/tgstation#74170 (Some elements)
tgstation/tgstation#85953
Monkestation/Monkestation2.0#3826 (Server originally a part of this PR)
If I missed any I am sorry, I tried my best.
cmss13-devs/cmss13#8606 (516 player)

Adds an admin verb that uses yt-dlp to play internet sounds instead of having to upload OGGs to the server.

yt-dlp can play more than just YouTube videos(unlikely to work with youtube unless there's some server fuckery going on with passing cookies), SoundCloud and Bandcamp are two other examples. You can read up on it here: https://github.com/yt-dlp/yt-dlp

Config set to null by default. yt-dlp requires an HTTP server to send sound requests to: https://github.com/Absolucy/ss13-yt-wrap

Big shoutout to affected for helping with the HTTP server stuff and code

Why It's Good For The Game

Play sound but actually good.

A proven reliable system from TG and its downstream to play music.

And if my experience from using this on TG is anything to go off of it shouldn't lag the shit out of the server or players when used.

Images of changes

To note: The terminal is only seen by the server host.

2025.01.30-04.17.1.mp4

Testing

I used a VM for most of my testing to ensure everything was working with multiple clients.

Ran the verb many many many times to make sure it was working.


Declaration

  • I confirm that I either do not require pre-approval for this PR, or I have obtained such approval and have included a screenshot to demonstrate this below.

Changelog

🆑
add: Added Play Internet Sound to the Event tab.
/:cl:

@Bm0n
Copy link
Contributor Author

Bm0n commented Jan 30, 2025

I would like to request a test merge to see how this impacts the server and players.

@ParadiseSS13-Bot ParadiseSS13-Bot added -Status: Awaiting type assignment This PR is waiting for its type to be assigned internally Configuration Change This PR changes the game configuration files. Please run via the host. labels Jan 30, 2025
@AffectedArc07
Copy link
Member

Two major hesitancy points on this

  1. Shell calls should not be in a codebase. I'd sooner make this a rustg module (which I am happy to assist with or even do myself) as I don't trust this given byond runs as LOCAL SERVICE.
  2. Youtube has been cracking down on this shit more and I saw some servers in coderbus going on about needing to pass cookies through to yt-dlp to actually download, and I am not putting a login token for my YT account on the server.

@Bm0n
Copy link
Contributor Author

Bm0n commented Jan 30, 2025

Two major hesitancy points on this

  1. Shell calls should not be in a codebase. I'd sooner make this a rustg module (which I am happy to assist with or even do myself) as I don't trust this given byond runs as LOCAL SERVICE.

I don't think TG or its downstream have had any issues with using a shell here but I understand the hesitancy. Unfortunately, I
don't know anything about rustg and considering I sometimes even struggle with DM I am not sure how much help I would be.

I could try to help you with a rustg module but again I don't know how much help I would be. I am starting from zero knowledge.

  1. Youtube has been cracking down on this shit more and I saw some servers in coderbus going on about needing to pass cookies through to yt-dlp to actually download, and I am not putting a login token for my YT account on the server.

TG switched from youtube-dl to yt-dlp for this reason and it's kind of a back and forth between Youtube and yt-dlp right now.
I had no problems during my testing, but I know from my time on TG that they cannot not play songs from topic or music channels on Youtube.

yt-dlp does have utility outside of Youtube. SoundCloud and Bandcamp work and are great sources of music which were commonly used.

@AffectedArc07
Copy link
Member

https://github.com/Absolucy/ss13-yt-wrap

@Absolucy made this which removes the need for shell calls so I'll get this deployed and advise on PR changes.

Copy link
Member

@AffectedArc07 AffectedArc07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the config option to a URL for ytdl_service_url and maybe add a link to https://github.com/Absolucy/ss13-yt-wrap in the comment, telling them to include the full path including the /get.

The way this is done is a GET request to http://10.0.0.10:23432/get with the following body

{
    "url": "https://soundcloud.com/affectedarc07/ss13-remix-2-quarantine-edition"
}

This returns

{
    "title": "SS13 Remix 2 - Quarantine Edition",
    "webpage_url": "https://soundcloud.com/affectedarc07/ss13-remix-2-quarantine-edition",
    "sound_url": "https://cf-media.sndcdn.com/1GpwbLvtIvC7.128.mp3?Policy=eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoiKjovL2NmLW1lZGlhLnNuZGNkbi5jb20vMUdwd2JMdnRJdkM3LjEyOC5tcDMqIiwiQ29uZGl0aW9uIjp7IkRhdGVMZXNzVGhhbiI6eyJBV1M6RXBvY2hUaW1lIjoxNzM4MjczMDA1fX19XX0_&Signature=BqECQUH4Nc6VXsr7Mx3dn2B3ap1gk~PcX4WMB9MBStm~RN33TSvqJP-8B0ZX35B8ujvTYsnLU543BEOcjN~ztL~cvGTPNDgY0rgj2rU4oHMFyCqEmArNTzhtrnLzMftEe~6pgUUvCNAwxI~7tfYpoR6shPtEs4IxCqAXZedqsBaXNDOh5dzY5QePF9wM3LJRxSHt05xBTKpgGVLrc13933DlLvM6f1g0VQwcGIgZMQqlgUzYF0oxi9FnJK7MSCvBNakN5yPqqOd~QuTLNGSLreyYziCscyHzeXTxs-kDQjJNB~mwS1wi0NaMzs1Bk9FoU6qftOzLtmzHlGjfiNVH2A__&Key-Pair-Id=APKAI6TU7MMXM5DG6EPQ",
    "duration": 223.269,
    "start": 0,
    "end": 223.269,
    "upload_date": null,
    "channel": "AffectedArc07",
    "artist": null,
    "album": null,
    "track": null
}

I used my own soundcloud because it wasnt working with YT without the cookies, but works with many other websites


This removes the need for shell calls and drastically simplifies the PR. If you need me to spin up an instance for you to test this lmk. Also the fact we are sending a body with a GET request is not good

A client SHOULD NOT generate content in a GET request unless it is made directly to an origin server that has previously indicated, in or out of band, that such a request has a purpose and will be adequately supported. An origin server SHOULD NOT rely on private agreements to receive content, since participants in HTTP communication are often unaware of intermediaries along the request chain

See; https://www.rfc-editor.org/rfc/rfc9110#section-9.3.1-6

@ParadiseSS13-Bot ParadiseSS13-Bot added -Status: Awaiting review This PR is awaiting review from the review team and removed -Status: Awaiting type assignment This PR is waiting for its type to be assigned internally labels Jan 31, 2025
@@ -0,0 +1,57 @@
//Runs the command in the system's shell, returns a list of (error code, stdout, stderr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

@Bm0n
Copy link
Contributor Author

Bm0n commented Feb 2, 2025

The alert/inputs are tgui now

Co-authored-by: AffectedArc07 <[email protected]>
Signed-off-by: Bm0n <[email protected]>
@@ -1,4 +1,5 @@
GLOBAL_DATUM_INIT(filename_forbidden_chars, /regex, regex(@{""|[\\\n\t/?%*:|<>]|\.\."}, "g"))
GLOBAL_DATUM_INIT(is_color, /regex, regex("^#\[0-9a-fA-F]{6}$"))
GLOBAL_DATUM_INIT(regex_rgb_text, /regex, regex(@"^#?(([0-9a-fA-F]{8})|([0-9a-fA-F]{6})|([0-9a-fA-F]{3}))$"))
GLOBAL_DATUM_INIT(is_http_protocol, /regex, regex("^https?://"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo this (and several of these tbh) is global pollution and could be just fine as a /proc/is_http_protocol(url) that just has the regex as a static variable inside the proc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i personally think it's fine, these are kept to a bare minimum on paradise compared to tg

@Carthusia
Copy link

the original system to play oggs will still be there correct?

@Bm0n
Copy link
Contributor Author

Bm0n commented Feb 7, 2025

the original system to play oggs will still be there correct?

yeah it's still there

@silverplatedelta silverplatedelta added the Administration This PR relates to ingame administration features label Feb 12, 2025
@github-actions github-actions bot added the Merge Conflict This PR is merge conflicted label Feb 12, 2025
@github-actions github-actions bot removed the Merge Conflict This PR is merge conflicted label Feb 13, 2025
@Bm0n
Copy link
Contributor Author

Bm0n commented Feb 19, 2025

More feedback for when prefs/local mutes block plays.

image

image

Also fixed play internet sound not respecting admin midi preferences.... oops



var/web_sound_input = tgui_input_text(src, "Enter content URL (supported sites only, leave blank to stop playing)", "Play Internet Sound", null)
if(istext(web_sound_input))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't trust reading indents on a phone but if the entire proc is indented after this if, surely its better to guard clause it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not completely indented after that if statement. There is an else statement that returns a var to stop sounds if there is no input text and another if statement to check for HTTPS in the URL (if there is no https it returns) and finally a last if statement to actually send data to tgchat or stop sounds (this should catch everything)

yeah it's not the prettiest code in the world

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind I am just dumb and was looking at the wrong if statement.

I added a return to the end of the proc on that if statement

@AffectedArc07
Copy link
Member

Did we get anywhere on 516 yet? Its almost in mainline and I want this PR in soon.

@Bm0n
Copy link
Contributor Author

Bm0n commented Feb 24, 2025

Did we get anywhere on 516 yet? Its almost in mainline and I want this PR in soon.

(I know we talked about this on Discord, this is mostly to reiterate for the benefit of others)

In a nutshell, no. There's an issue with player.js working with webview2. From what I understand (and this could be totally wrong) it's a different process to get audio to auto-play through a browser on webview2 compared to trident. There's also an issue with stopping sounds bluescreening TGchat but that's probably a side-effect of the aforementioned issue.

player.js came with our TGchat port and is a part of TGchat, I was banking heavily off it being reviewed and in the codebase unused. I don't know JavaScript all that well, I am not going to be the one to fix this issue.

The silver lining to all of this is that player.js is broken in the exact same way on TG (and by extension all of its downstream). Knowing how heavily this is used I doubt it'll die with webview2, somebody will fix this it's just a matter of when.

Not sure how much longer we're going to be on 515 but for the time being I can put a check in for it to do nothing on 516 clients.

@AffectedArc07
Copy link
Member

AffectedArc07 commented Feb 26, 2025

$50 to anyone who makes this work on 516.

Bounty claimed - cmss13-devs/cmss13#8606

@Bm0n
Copy link
Contributor Author

Bm0n commented Feb 27, 2025

Confirmed that the new player is working on 516 and 515.

@ParadiseSS13-Bot ParadiseSS13-Bot added the TGUI This PR modifies TGUI, will conflict label Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Status: Awaiting review This PR is awaiting review from the review team Administration This PR relates to ingame administration features Configuration Change This PR changes the game configuration files. Please run via the host. TGUI This PR modifies TGUI, will conflict
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants