Announcement

Collapse
No announcement yet.

Winamp Scripting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    More examples and a suggestion

    More examples
    code:

    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Const LogFile = "c:\songlog.txt"
    Set fso = CreateObject("Scripting.FileSystemObject")

    Sub WAObj_ChangedTrack
    Dim s, text
    s = playlist(playlist.position).ATFString("%artist% - %album% '('%filename%')'")

    If Not fso.FileExists(LogFile) Then
    Set text = fso.CreateTextFile(LogFile)
    Else
    Set text = fso.OpenTextFile(LogFile, ForAppending)
    End If
    text.WriteLine s
    text.Close
    End Sub

    Suggestion

    Why not putting error messages in the lower edit box, instead of calling MessageBox() all the time. Very nasty if script contains a lot of errors (not that I have a lot of errors in my scripts).

    Comment


    • #17
      That box wont exist at all eventually, or even the dialog. Well I might have one that could be called up for testing or whatever. If you want to avoid errors, just put

      On Error Resume Next

      At the start, or make your own error handler. I will probably make some kind of console output method for use by scripts evenutally though.

      There still the complicated matter of events from dynamically created objects. (ie handling events on objects create by 'createobject'). This is a known 'problem' that involves a few different solutions, none of which are that great.
      Music Plugins

      Comment


      • #18
        Here is my final (for now) script:
        code:

        Const ForReading=1, ForWriting=2, ForAppending=8
        Const LogFile="c:\songlog.txt"
        Const FormatText="$if(%title%,[%artist% - ]%title%,$filepart(%filename%))"
        Set fso=CreateObject("Scripting.FileSystemObject")
        Set ieo=CreateObject("InternetExplorer.Application")
        ieo.Navigate2("about:blank")
        ieo.visible=True

        Sub ShowPlaylist
        Dim s, i
        i=1
        For Each file In playlist
        s = s & "<br/>" & vbCrLf & i & ". " & file.ATFString(FormatText)
        i = i + 1
        Next

        ' The following line gives error. Why??
        ieo.document.write("<pre>")

        ieo.document.write(s)
        ieo.document.write("<br/>" & vbCrLf)
        ieo.document.write("<br/>" & vbCrLf)
        ieo.document.write("Tracking played items:" & "<br/>" & vbCrLf)
        End Sub

        ShowPlaylist

        Sub WAObj_ChangedTrack
        Dim s, text
        s = playlist(playlist.position).ATFString(FormatText)

        If Not fso.FileExists(LogFile) Then
        Set text = fso.CreateTextFile(LogFile)
        Else
        Set text = fso.OpenTextFile(LogFile, ForAppending)
        End If
        text.WriteLine s
        text.Close

        ieo.document.write(s & "<br/>")
        End Sub

        1. Why can't I write ieo.document.write("<pre>")?
        2. Do you have a limit on how much script code to write?
        3. And why do you have to use () around parameters when it's not on the right side. Like:
        code:

        ' Here it is neccessary with the "()"
        Dim var
        var = function("param", 23)

        ' Here it is *not* neccessary:
        function "param", 23

        4. Please put the Scripting dialog inside the preferences, or put it inside a embedWindow thing (skinned frame).

        Comment


        • #19
          Nice script, keep in mind this is just preview stuff though, so its just for playing with at the moment.

          I had to replace

          If Not fso.FileExists(LogFile) Then
          Set text = fso.CreateTextFile(LogFile)
          Else
          Set text = fso.OpenTextFile(LogFile, ForAppending)
          End If

          with just
          Set text = fso.CreateTextFile(LogFile)

          to get it working though. Dunno vbscript that well, so Im not sure what the problem was. Ive got a version which outputs the error and line etc on the error which makes it easier to find bugs in scripts. Id like to make a similar script which highlights the current item and outputs album covers etc. its easy enough using %dir%\folder.jpg.

          1. I dunno, it worked ok for me - try removing some other lines, its possible its just too much code for the buffer.

          2. 1024 bytes currently, Ill increase this, but there wont be a limit eventually, it will just allocate as much space as necessary for the file.

          3. I dunno, some vbscript quirk. vbscript.dll does all the parsing of code, I just handle my own object.

          4. The dialog will dissapear completely and I will just load scripts from files. I wont waste time for now making it look pretty. There will be a dialog you can invoke which will list all the running scripts and let you stop them etc. Plus it will let you start new scripts.

          Please dont view the interface as any indication of the finished project, its just a quick hack to expose what can potentially be done.

          PS. I found John's site which has the source to Winamp COM.

          It probably has some helpful stuff in there, but it seems quite different to my implementation, so I cant make too much use of it.
          Music Plugins

          Comment


          • #20
            I just doubled the buffer to 2048 bytes, your script runs fine with this new buffer. So it was just hitting the limit. You can try it out with this version with a bigger buffer.
            Attached Files
            Music Plugins

            Comment


            • #21
              Have now modified it to allow getting the selected items. So you can now process items that are selected and do whatever you like on them. With a bit of polish this would already be quite a useful plugin, but I will work on making it more complete.

              While you can do 'system' things on the items, it would also be useful to do 'winamp' things on the items (ie, remove from the playlist, randomize selection etc).

              -------

              k = playlist.getselection()
              msgbox "You selected " + cstr(ubound(k,1)) + " items"

              for each g in k
              msgbox CStr(g.position) + ". " + g.ATFString("%title% / %album%")
              next
              Music Plugins

              Comment


              • #22
                forgot the attachment
                Attached Files
                Last edited by shaneh; 2 September 2004, 11:38.
                Music Plugins

                Comment


                • #23
                  hi there, i planned to offer scripting support to Winamp too, but at first i had thought about using SpiderMonkey as a scripting engine (Mozilla's javascript), and eventually switched to LUA.
                  Unhappily, my job has been taking too much time, so that project is stalling in a very early stage.

                  SM or LUA would allow a feature that may not be available with the VB runtime: running scripts in a sandbox disallowing unsecure operations in a customizable way.
                  I don't want to download a script that will install some spyware using kinda obfuscated code like VB code can be (especially with CreateObject() )
                  - Winamp Desk Band 1.2.2-alpha -

                  Comment


                  • #24
                    Hey,
                    adding scripting support using windows script hosting is quite easy, and flexible. Its literally one or two lines to add support for javascript, perl and any other language (once you have the support for actually hosting the scripting engine). Plus the whole 'createobject' thing makes it very powerful indeed.

                    Also, it has a quite extensible security model, IE uses the same one. Basically you can implement your own security manager and can choose to allow or disallow object creation at runtime. This allows you to let 'safe' objects the ability to still be scripted (ie like 'safe' activex objects in IE), or you can loosen the restrictions and let file system objects etc be created if necessary.

                    I have already done this in 'Winamp HTML', however I went out of my way to weaken the security to allow unsafe stuff.

                    My reasoning for this is there is already safe scripting support in Winamp, through wasabi or whatever. Anything interesting requires some kind of permissions.

                    If I wanted it to be truly safe, I would have to restrict it to just stop and play type stuff, with no execution, or even changing meta data in the media library, it would be quite an undertaking to make it truly safe. Plus this is already possible with modern skin scripting.

                    Basically I want it to be a way for people to write their own plugins or to script common tasks easily and quickly. Scripts that are actually able to do stuff. So therefore you should use the same caution installing other peoples scripts as you would plugins. Scripts certainly wouldnt be something that came bundled with skins or something like that.

                    Having said that, it probably wouldnt be too much trouble to at least selectivly block 'createobject' etc type stuff per script if necessary. Although I probably wouldnt bother flagging each of my objects methods as safe or not so there could still be holes.
                    Last edited by shaneh; 2 September 2004, 16:43.
                    Music Plugins

                    Comment


                    • #25
                      Basically I want it to be a way for people to write their own plugins or to script common tasks easily and quickly. Scripts that are actually able to do stuff. So therefore you should use the same caution installing other peoples scripts as you would plugins.
                      That's exactly what i wanted to achieve with my plugin
                      I think you're very right in the way you're doing it.
                      To be honest I also considered using VB or JS (WSH...) but, there are two things that made be reject that idea.
                      1. I don't like VB and JS (that's why i also rejected SpiderMonkey) as programming languages... just personal tastes
                      2. It's not 100% certain that the WSH will be present on a particular windows box (i'm assuming you're actually using the Windows Script Host)
                      - Winamp Desk Band 1.2.2-alpha -

                      Comment


                      • #26
                        1. You can use any language that has an active script engine. Perl has one, and there are other languages (tcl, pascal etc). You can let the user decide which one to use by just having a standard name convention (ie .vb, .vbs, .pl).

                        I dont like VB that much either, but as it is MS' baby, it is the most powerful. And the more I learn about this scripting stuff, the more it makes sense to use a language such as VB (for scripting). Plus people know VBscript and JS thanks to the web and VB/VBA etc. It saves them from having to learn another language, which is kind of the point in the first place.

                        2. Its not actually WSH, its ActiveScript. WSH is just one host for the engine, in exactly the same way this project is a host for the engine. It would be available on any platform which has IE ~3+. Either way, you could always let people install it if they want it.
                        Last edited by shaneh; 3 September 2004, 01:16.
                        Music Plugins

                        Comment


                        • #27
                          You may now do basic querying of the media library. I will make a much better implementation of this later on, but this one will still remain as it is still useful. It returns an array of initialised items rather than a collection to enumerate over. This isnt too efficient for large queries, but should be ok for smaller ones.

                          As the query returns much richer info, I will have it cache it in the items so you can obtain it without using ATFString and the like. Obviously items obtained from a media library query do not have a 'position' in the playlist.

                          ---basic example----

                          Dim x, s

                          Set wd = CreateObject("Word.Basic")
                          wd.appshow
                          wd.filenew

                          wd.Insert "Songs by Metallica" + VbNewLine

                          mlq = medialibrary.runqueryarray("Metallica")
                          x = 0
                          s = ""

                          For each track in mlq
                          x = x + 1
                          s = s + track.ATFString("%album% - %title%") + VbNewLine
                          if x > 200 then
                          wd.Insert s
                          s = ""
                          x = 0
                          end if
                          next

                          wd.Insert s
                          Attached Files
                          Last edited by shaneh; 3 September 2004, 04:57.
                          Music Plugins

                          Comment


                          • #28
                            NxS Script Control

                            I have recently started out my own project called NxS Script Control. It is plug-in that uses Active Scripting like ShaneH's gen_script1.dll.

                            It integrates with the Winamp Preferences (adds it's own page) and you can load/save script files.

                            The object in script that controls Winamp is called "Winamp", and it currently has these methods:
                            - Play()
                            - Stop()
                            - Next()
                            - Prev()
                            - AddToLog("string to add")

                            It has a log list that outputs error messages and text passed to AddToLog.

                            I will eventually add more stuff, like in ShaneH's plug-in.

                            Download it and try it out...
                            Attached Files

                            Comment


                            • #29
                              Here is more script for the masses!!
                              code:

                              Dim x, s, wd

                              Set wd = CreateObject("InternetExplorer.Application")
                              wd.Navigate2("about:blank")

                              wd.document.write "<html><head>"
                              wd.document.write "<title>Winamp Media Library</title>"
                              wd.document.write "</head>"
                              wd.document.write "<body bgcolor=black text=#CEFFCE>"
                              wd.document.write "<p>"

                              k = playlist.getselection()
                              wd.document.write "You selected " + CStr(UBound(k,1)) + " items: "
                              wd.document.write "</p><p>"

                              For Each g In k
                              wd.document.write CStr(g.position) + ". " + g.ATFString("%title% / %album%")
                              Next
                              wd.document.write "</p>"

                              wd.document.write vbNewLine & "<table border=1>" & vbNewLine

                              mlq = medialibrary.runqueryarray("?")
                              x = 0
                              s = ""

                              For Each track In mlq
                              x = x + 1
                              s = s & "<tr>" & _
                              track.ATFString("<td>[%artist%]</td>[<td>%title%</td>]") _
                              & "</tr>" & VbNewLine
                              ' Write out in increments of 200 songs (buffer)
                              If x > 200 Then
                              wd.document.write s
                              s = ""
                              x = 0
                              End If
                              Next

                              wd.document.write s + vbNewLine

                              wd.document.write "</table>"

                              wd.document.write "<p><u>Result from ping command:</u></p>"
                              wd.document.write "<pre>" & CatchConsoleOutput("ping localhost") & "</pre>"

                              wd.document.write "</body></html>"

                              wd.visible = True ' All written, show IE
                              ' I just love "InternetExplorer.Application" :-)

                              ' How to execute an application
                              Sub RunApp(app)
                              Dim WshShell
                              Set WshShell = CreateObject("WScript.Shell")
                              WshShell.Run app, 5
                              End Sub
                              ' Example:
                              ' RunApp "notepad.exe"

                              ' How to catch output from console apps
                              Function CatchConsoleOutput(app)
                              Dim WshShell, prog, s
                              Set WshShell = CreateObject("WScript.Shell")
                              Set prog = WshShell.Exec(app)
                              While (prog.Status = 0) And (Not prog.StdOut.AtEndOfStream)
                              s = s & prog.StdOut.Read(1)
                              Wend
                              CatchConsoleOutput = s
                              End Function

                              Hope you like it...

                              Comment


                              • #30
                                why not take the best of all worlds and make one plugin in a collaborative effort ?

                                IMHO, saivert's interface is better (the one i started was basically based on the same idea).
                                One good thing would be to have a list of the currently loaded scripts, and be able to stop and start them at will (like in the Winbot IRC bot).

                                For my plugin, my intent was to implement all the functionality of the SDK through some objects (Winamp, Winamp.mainwnd, Winamp.playlist etc), plus event handling.
                                i also wanted the ability to be able to add dynamic extensions to the plugin, for example to add some database or networking support, for instance. I guess it's not that useful here, as Active Scripting can use COM objects

                                As for languages, it would be nice also if a different script file extension (js, vbs...) would use the appropriate engine.

                                Last but not least, to make this plugin really useful, even though it's the most boring part in development, a big effort should be put on documentation, else, only few people will bother trying to learn the API from samples only.

                                These were my 2 cts
                                - Winamp Desk Band 1.2.2-alpha -

                                Comment

                                Working...
                                X
                                😀
                                🥰
                                🤢
                                😎
                                😡
                                👍
                                👎