Author Topic: The HgLuv Networked Jukebox  (Read 2016 times)

Offline hy

  • Administrator
  • Newbie
  • *****
  • Posts: 26
    • View Profile
  • Expertises:
  • Linux Network Administration
  • PHP, MySQL
  • Mono/C# I am miserable at it, but I do it anyway. :)
The HgLuv Networked Jukebox
« on: November 27, 2017, 02:17:04 pm »
This is the script from the jukebox you see in various parts of the grid.    It is networked, and will run on any grid (even SL!)  and allows you to share and add parcel music streams with a group.

It is set to LuvRadio by default, but you can create your own groups and lists, just by changing the jukebox name :)

The web part of the jukebox server currently works by spitting out a random stream that matches a keyword or genre.. 
so if you type  /66 disco       and there are a dozen stations labeled keyword "disco" , it will choose one randomly and start playing.
When adding a stream to the list, you can specify as many keywords as you want, to help narrow down the search..  such as...

/66 add http://radiostreamer.com/michael_jackson   disco pop michael jackson awesome

..  and it will add those keywords.  So a person who types    /66 jackson      will get a michael jackson station.

The code is posted below.  You can cut and paste it into any object..  a jukebox of your choice.. old radio, a lamp, a plant..  what have you.     

Let's add some new streams!  Unless you really like Michael Jackson 24/7.   haha



Code: [Select]
[// LuvBox - Networked jukebox written by Hyacinth Jewell @ HGluv Grid.(aka Hyacinth Landry in meatspace)
//
// Free to use, mess around with, and access with our public server at http://grid.hgluv.com/jukebox/jukebox.php  (until someone messes it up!  lol)
//
// This script acts as a kind of "dumb terminal" so the actual search, stream list management
// etc..  is very flexible, and done by your web server.   So you can use any scheme you can dream up.   All this script does is enforce the
// everyone/group/owner restrictions, and sends the commands along to the server.    The server simply spits out text...
// if it begins with "http://" , it plays a music stream.   Anything else, it just displays the output in chat.
//
// No warrantees.   This is provided as-is.   Security of your web server is your responsibility.
// If your landlord is paranoid and does not allow the required script commands: llHTTPRequest (with response data),  llSetPrimitiveParams..
// It is not our fault.   Get a new landlord, or better yet, come to HGluv grid and someone will help you set up your own rig. :)
//
// Example PHP script and updates can be found at http://grid.hgluv.com/jukebox/
//


string jukeboxurl="http://grid.hgluv.com/jukebox/jukebox.php";   // change if you host your own
string mkey = "c4762d4f-f770-48d5-a85c-f8baa20d2943";    //  IMPORTANT: Only change if you host your own jukebox server and wish to restrict access.
//                                                     //   If you change this, management will stop working on the HGluv public jukebox server
string jukeboxname = "jukebox";                         //  You can change this through the menu.  "jukebox" is the default / shared one
string access = "everyone";                             // everyone. group, owner    -  Who can switch the stream
string accessManage = "owner";                          // owner, group, everyone   -  Who can add/delete streams
integer chan=66;                                        // chat channel jukebox listens on.  Type  /66 help ...  etc..
string lock = "";                                       // lock="locked"; for lock.    blank for unlocked.   If locked only owner can use.

//   Non-user servicible parts below..
string streamurl="";
key http_request_id;
string lasturl="";



default
{
    state_entry()
    {
    list tmp = llGetPrimitiveParams([PRIM_DESC]);
    list tmp2 = llParseString2List(llList2String(tmp,0),"|","|");
    jukeboxname=llList2String(tmp2,0);
    access=llList2String(tmp2,1);
    accessManage=llList2String(tmp2,2);
    if (access == "") access="everyone";
    if (accessManage == "") accessManage="owner";
    if (jukeboxname == "") { jukeboxname="jukebox"; }


    llSetText("LuvBox - networked jukebox!\rtype /"+ (string)chan + " for help .. or type /" + (string)chan + " keyword",<.3,1,.33>,1);

    lasturl=jukeboxurl+"?req=random";
    llHTTPRequest(lasturl, [HTTP_METHOD,"GET",HTTP_MIMETYPE,"text/html"], "");

    llListen(chan,"","","");
    llSay(0,"LuvBox started!   Listening on channel "+chan);
    llSay(0,"Switch stream access: "+access);
    llSay(0,"Set stream access: "+accessManage);
    llSay(0,"Jukebox name: "+jukeboxname);
    llSay(0,"Type /"+(string)chan+" help for commands.");
    }

listen (integer chan, string name, key id, string msg){

    list parts=llParseString2List(msg," "," ");
    string cmd=llList2String(parts,0);
    string args1=llList2String(parts,1);


    if (id != llGetOwner()) {
        if (lock=="locked") {  llSay(0,"Jukebox is locked by owner.");  msg=""; }

        if (access == "owner" && id != llGetOwner()) {
            llSay(0, "Access is set to owner-only");
            msg="";
            cmd="";
            args1="";
            }

        if (access == "group" && !llDetectedGroup(0)) {
            llSay(0, "Access is set to group-only");
            msg="";
            cmd="";
            args1="";
            }
        }



    if (cmd == "reset" && id == llGetOwner()) { llSay(0,"Jukebox reset.");  llResetScript(); }
    if (cmd == "lock" && id == llGetOwner()) { llSay(0,"Jukebox is locked.");  lock="locked";  msg=""; }
    if (cmd == "unlock" && id == llGetOwner()) { llSay(0,"Jukebox is unlocked for access by" + access);  lock="";  msg=""; }


    if (cmd == "access" && id == llGetOwner()) {
          access="everyone";
          if (args1 == "group") { access="group"; }
          if (args1 == "owner") { access="owner"; }
          llSay(0, "Access set to "+access);
          llSay(0, "If you get a script error, you will need to manually set the object Description field to \""+jukeboxname+"|"+access+"|"+accessManage+"\" to save the settings permenantly.");
            string params=jukeboxname+"|"+access+"|"+accessManage;
            llSetPrimitiveParams([PRIM_DESC,params]);
          }

    if (cmd == "manage" && id == llGetOwner()) {
          accessManage="owner";
          if (args1 == "group") { accessManage="group"; }
          if (args1 == "everyone") { accessManage="everyone"; }
          llSay(0, "Management set to "+accessManage);
          llSay(0, "If you get a script error, you will need to manually set the object Description field to \""+jukeboxname+"|"+access+"|"+accessManage+"\" to save the settings permenantly.");
            string params=jukeboxname+"|"+access+"|"+accessManage;
            llSetPrimitiveParams([PRIM_DESC,params]);

          }

    if (cmd == "jukeboxname" && id == llGetOwner()) {
          jukeboxname="jukebox";
          if (args1 != "") { jukeboxname=args1; }
          llSay(0, "Jukeboxname set to "+jukeboxname);
          llSay(0, "If you get a script error, you will need to manually set the object Description field to \""+jukeboxname+"|"+access+"|"+accessManage+"\" to save the settings permenantly.");
            string params=jukeboxname+"|"+access+"|"+accessManage;
            llSetPrimitiveParams([PRIM_DESC,params]);

          }

    if (cmd =="del" && id==llGetOwner()) {

    lasturl=jukeboxurl+"?jukebox="+jukeboxname+"&del="+llEscapeURL(llGetSubString(msg,4,llStringLength(msg)));

    llHTTPRequest(lasturl, [HTTP_METHOD,"GET",HTTP_MIMETYPE,"text/html"], "");
    llSay(0,lasturl);
    msg="";
        }



    if (cmd =="add") {
        integer ok=0;
        if (id==llGetOwner()) ok=1;
        if (accessManage == "group" && llDetectedGroup(0)) ok=1;
        if (ok != 0) {

            lasturl=jukeboxurl+"?jukebox="+jukeboxname+"&add="+llEscapeURL(llGetSubString(msg,4,llStringLength(msg)));

            llHTTPRequest(lasturl, [HTTP_METHOD,"GET",HTTP_MIMETYPE,"text/html"], "");
            llSay(0,lasturl);
            msg="";
            } else { llSay(0,"Owner or group only."); msg=""; }
        }

    if (msg !="") {
    lasturl=jukeboxurl+"?jukebox="+jukeboxname+"&req="+llEscapeURL(msg);
    llHTTPRequest(lasturl, [HTTP_METHOD,"GET",HTTP_MIMETYPE,"text/html"], "");
            }

    }

http_response(key request_id, integer status, list metadata, string body)
    {
        string first7=llToLower(llGetSubString(body,0,6));
        llReleaseURL(lasturl);


        if (first7 == "http://") {
            llSetParcelMusicURL(body);
            llSay(0,"Music stream set to: "+body);
            }
            else {  llSay(0,body); }
        }
}/code]
« Last Edit: November 27, 2017, 02:27:14 pm by hy »