Skip to content

Commit

Permalink
Merge pull request #27 from CASEYGUNGEON/jukebox2
Browse files Browse the repository at this point in the history
internet jukebox
  • Loading branch information
Tk420634 authored and Superlagg committed Sep 24, 2024
1 parent c56bb94 commit d3f684a
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 3 deletions.
2 changes: 1 addition & 1 deletion code/__HELPERS/shell.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
shelleo_ids[shelleo_id] = TRUE
out_file = "[SHELLEO_NAME][shelleo_id][SHELLEO_OUT]"
err_file = "[SHELLEO_NAME][shelleo_id][SHELLEO_ERR]"
errorcode = shell("[interpreter] '[command]' > [out_file] 2> [err_file]")
errorcode = shell("[interpreter] \"[command]\" > [out_file] 2> [err_file]")
if(fexists(out_file))
stdout = file2text(out_file)
fdel(out_file)
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/job.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SUBSYSTEM_DEF(job)
var/list/prioritized_jobs = list()
var/list/latejoin_trackers = list() //Don't read this list, use GetLateJoinTurfs() instead

var/overflow_role = "Wastelander" //CHANGE
var/overflow_role = "Customer" //CHANGE

var/debug_admins_are_exempt_from_timelocks = FALSE

Expand Down
85 changes: 85 additions & 0 deletions code/game/machinery/dance_machine_online.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/obj/machinery/jukebox_online
name = "Online Jukebox"
desc = "A music player. This one has a massive selection."
icon = 'icons/obj/stationobjs.dmi'
icon_state = "jukebox"
verb_say = "intones"
density = TRUE
var/pendingsongurl = ""

/obj/machinery/jukebox_online/on_attack_hand(mob/living/user, act_intent, unarmed_attack_flags)
var/songinput = input(user, "Enter URL (supported sites only, leave blank to stop playing)", "Online Jukebox") as text|null
if(isnull(songinput) || !length(songinput))
stop_online_song()
return
pendingsongurl = songinput
var/adminmessage = "<span class=\"admin\">[user.name] wants to play <a href=\"[pendingsongurl]\">[pendingsongurl]</a><br/>You can <a href='byond://?src=\ref[src];action=allow;url=[pendingsongurl]'>Allow</a> or <a href='byond://?src=\ref[src];action=deny;url=[pendingsongurl]'>Deny</a>.</span>"
for(var/admin in GLOB.admins.Copy())
to_chat(admin, adminmessage, confidential = TRUE)

/obj/machinery/jukebox_online/Topic(href, href_list[])
if(pendingsongurl == href_list["url"])
if(href_list["action"] == "allow")
var/toplay = pendingsongurl
parse_url(toplay)
message_admins("[usr] approved [href_list["url"]]")
pendingsongurl = ""
return
if(href_list["action"] == "deny")
pendingsongurl = ""
message_admins("[usr] denied [href_list["url"]]")
return
else
to_chat(usr, "Someone else must have responded already.")


/obj/machinery/jukebox_online/proc/parse_url(url)
. = FALSE
var/ytdl = CONFIG_GET(string/invoke_youtubedl)
if(!ytdl)
to_chat(src, span_boldwarning("yt-dlp was not configured, action unavailable")) //Check config.txt for the INVOKE_YOUTUBEDL value
return
if(length(url))
url = trim(url)
if(findtext(url, ":") && !findtext(url, GLOB.is_http_protocol))
to_chat(src, span_boldwarning("Non-http(s) URIs are not allowed."))
to_chat(src, span_warning("For yt-dlp shortcuts like ytsearch: please use the appropriate full url from the website."))
return
var/shell_scrubbed_input = shell_url_scrub(url)
var/list/output = world.shelleo("[ytdl] --format \"bestaudio\[ext=mp3]/best\[ext=mp4]\[height<=360]/bestaudio\[ext=m4a]/bestaudio\[ext=aac]\" --dump-single-json --no-playlist -- \"[shell_scrubbed_input]\"")
var/errorlevel = output[SHELLEO_ERRORLEVEL]
var/stdout = output[SHELLEO_STDOUT]
//var/stderr = output[SHELLEO_STDERR]
if(!errorlevel)
var/list/data
try
data = json_decode(stdout)
catch(var/exception/e)
to_chat(src, span_boldwarning("yt-dlp JSON parsing FAILED:"))
to_chat(src, span_warning("[e]: [stdout]"))
return

if (data["url"])
var/storeddata = list()
storeddata["start"] = data["start_time"]
storeddata["end"] = data["end_time"]
storeddata["link"] = data["webpage_url"]
storeddata["title"] = data["title"]
play_online_song(data["url"], storeddata)
. = TRUE

/obj/machinery/jukebox_online/proc/play_online_song(url, extradata)
for(var/m in GLOB.player_list)
var/mob/M = m
var/client/C = M?.client
if(C)
if(C.prefs.toggles & SOUND_MIDI)
C.tgui_panel?.play_music(url, extradata)

/obj/machinery/jukebox_online/proc/stop_online_song()
for(var/m in GLOB.player_list)
var/mob/M = m
var/client/C = M?.client
if(C)
if(C.prefs.toggles & SOUND_MIDI)
C.tgui_panel?.stop_music()
2 changes: 1 addition & 1 deletion config/game_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ ROUNDSTART_RACES dragon
#JOIN_WITH_MUTANT_HUMANS

##Overflow job. Default is assistant
OVERFLOW_JOB Wastelander
OVERFLOW_JOB Customer

## Overflow slot cap. Set to -1 for unlimited. If limited, it will still open up if every other job is full.
OVERFLOW_CAP -1
Expand Down
1 change: 1 addition & 0 deletions fortune13.dme
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@
#include "code\game\machinery\constructable_frame.dm"
#include "code\game\machinery\cryopod.dm"
#include "code\game\machinery\dance_machine.dm"
#include "code\game\machinery\dance_machine_online.dm"
#include "code\game\machinery\defibrillator_mount.dm"
#include "code\game\machinery\dish_drive.dm"
#include "code\game\machinery\dna_scanner.dm"
Expand Down

0 comments on commit d3f684a

Please sign in to comment.