No announcement yet.

Winamp Scripting

  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    Added a few more methods and properties. Have changed the way the runqueryarray works, it now does a standard query. So queries are now of the form:
    "type = 0", "artist HAS metall" etc

    I will probably put the keyword query method back in under another name.

    Have changed the base object to "Application" in keeping with standard automation naming conventions.

    Can now create MediaItems by using "LoadItem" and a file name. Or using "GetItem" and a filename to retrieve stuff from the media library.

    ATFString can now query for media library items. (rating,playcount etc)

    Added basic play,pause etc operations, and a clear method for the playlist.

    I have decided that the array mechanism of doing media library queries is ok, as you need to make a copy any way in case another plugin frees your query. But I will probably add another more efficient version of the query that doesnt make a copy, for cases where you want to enumerate the results straight away, and dont need the copy sticking around to process later in an event for example.

    With that in mind, I am debating the merits of multi-threading the scripts, as it would require a lot of synchronisation, and I am not sure what is and isnt thread safe in winamp, plus there is the potential for deadlocks.

    As the scripts can potentially do anything, it is potentially quite dangerous to make the scripts run in a separate thread to winamp - they would be likely to conflict with other plugins. Thus they will simply run synchronously, just like normal plugins.

    Note that this will still allow events and so forth to run, they will just not run simultaneously. Just like normal plugins.


    @Lord Darius. As Ive said numerous times, this is not the interface the plugin will use. As it is obviously still a work in progress, while I am developing it, the first thing I need to do when I fire up winamp is type some test script and test it. This interface allows that. Files arent of any use at the moment as I am constantly changing what I am testing.

    The plugin will simply load scripts from files such as:

    plscommand_Upload to Ftp.js

    etc. The extension will indicate the scripting engine to use. And the plugin will pick them up and run them and add menus etc as appropriate. I will still supply I similar interface to this debug one, for testing scripts, and a means to see what scripts are currently connected for events (running) and let you stop them etc, plus let you load arbitrary scripts etc. Plus supply some kind of console ouput which you can view or hide. It will also have a browser component to it which will let you make use of the scripting inside a browser window in the media library.

    But I'll say it again just to be sure. This is not the interface the final plugin will use. It is for testing purposes only, do not draw judgement on it.

    As for documentation, you may load the included .tlb in an object browser (any vb/vba/vis studio/ms word type app has one) and you will see all the methods and properties. (done so far, IT IS NOT COMPLETE - testing purposes only, yada yada.).
    Attached Files
    Last edited by shaneh; 3 September 2004, 12:37.
    Music Plugins


    • #32
      This script will enqueue a random track from the artist of the current track every track change. I should probably have a test to check that it doesnt enqueue the same item. I will need to implement some ICompare type interface on the media items I guess.

      If you iterate through the playlist to make sure your not adding a dupe, itd be a nice little script to generate an ever growing playlist of a selection of a couple artists.

      Next up will be changing media library meta data, then working on the general interface. Then adding working on methods for manipulating 'send to' selections, then switching items about on the playlist and other less important commands. Afterwards, I will probably add an ID3 object for grabbing stuff out of those tags, prob a v2 thing. Wont be doing anything on it tomoorrow however.


      Sub Application_ChangedTrack
      set p = playlist(playlist.position)
      mlq = medialibrary.runqueryarray("artist HAS """ + p.ATFString("%artist%") + """")
      if ubound(mlq,1) > 1 then
      y = Int((ubound(mlq,1)) * Rnd + 1)
      end if
      end sub
      Last edited by shaneh; 3 September 2004, 13:55.
      Music Plugins


      • #33
        More chatting....

        @Lord Darius: I like the idea of a collaborative effort.
        I don't know about ShaneH - He may be working best on his own,
        but I would be happy If you and me decided to share code,
        and create something beatuful together ..hmmm, what's that suppose to mean ...

        @ShaneH: I know that you don't intend to have a dialog in a finished version.
        It will basically be the same with NxS Script Control, but I like to
        give users the ability to edit and manage scripts inside Winamp, instead of
        having both Explorer and Notepad open.
        NxS Script Control (new version below) detects which script engine to use
        by reading the script itself. The user must place a comment at the first line
        to indicate which script type it is.
        VBScript example:

        '@Language = VBScript

        JScript (JavaScript) example:

        /*@Language = JScript*/

        If such a comment isn't found then it will use the file's extension to select
        the engine. But this sucks since I would have to maintain a list of known
        extension like vbs, js, psc (PersScript) and more.
        You could also just try to parse the script using one engine after the other until
        an engine parsed it successfully, but then all scripts would have to be flawless.

        I will always include the source code with my plugins keeping it open-source.
        @Lord Darius: Please take time reading the source for NxS Script Control, and
        give me feedback (private message on forum or e-mail) on it. It will help me improve my
        coding skills and who know, maybe you will learn something too...
        Attached Files


        • #34
          +settimeout method, used for callback on a timeout. Timer is cancelled after triggered.

          settimeout 5000, getref("myfunc")
          sub myfunc
          msgbox "Called"
          end sub

          +quit method
          Used to terminate the script and stop listening for events.

          +Loads items from files plugins\scripts\startup_*.vbs and playlist_*.vbs. Items in startup* are run at startup, items in playlist* are run when selected from the playlist 'Scripts' menu.

          +Experimental 'attachevents' method for binding the events of a dynamically created object. Works similar to 'connectobject' of wscript. Its use is not recommended at the moment, and it wont work with IE either.

          Set calobj=CreateObject("MSCal.Calendar.7")
          attachevents calobj, "CALE"
          sub CALE_AfterUpdate
          msgbox "calendar event"
          end sub

          +changed 'stop' to 'stopplayback' due to global name conflict

          +Removed dialog for now, just uses files atm.

          +enumerator on the medialibrary. Can also get any item in the media library through Item(). ie.

          msgbox medialibrary(123).Title

          +Can read and change rating and playcount through the rating propery of media items

          +alubm,artist,title is cached when mediaitem is created through a media library query

          There is still lots of static buffers and globals etc which need to be cleaned up. Plus an interface for managing scripts (editing,running,stopping etc). I may put some check marks against the menu items of currently running scripts to simplify the interface, so you can start and stop them easily.
          Attached Files
          Last edited by shaneh; 6 September 2004, 12:59.
          Music Plugins


          • #35
            +Basic hot key support. Files named hotkey_*.vbs will be registered as hot key runnable. I will add a 'registerhotkey' type message later, with a callback for scripts that stay running.
            [I will probably remove the hotkey_* type files, and just register all playlist_*/sendto_*/menu_* etc files as hot key assignable instead).

            +Canceltimer(timerid). You can cancel a timer set by 'settimeout' by using the id received from 'settimeout'.

            +playlist.Deleteindex - remove an item from the playlist

            +playlist.Swapindex - swap two indexes in the playlist

            +mediaitem.insert(index) - insert the item at the specified position in the playlist

            +much improved 'changedtrack' event detection. avoids dupes without having to do filename comparisons etc.

            Some other example scripts, including one which makes the playcount only increment if its been played for over 9 seconds.
            Attached Files
            Music Plugins


            • #36
              Fixed many static buffers, much better loading from file support. Should support basically any size file. Removed hotkey_* type, all playlist_* files can be assigned hot keys.
              Improved visual display of items in playlist menu.
              Improved loading of playlist_* named files.
              Fixed some internal object management and the way scripts quit.

              +Added 'lastplay' property
              +Getting selected items now re-parses the 'length' of playlist items correctly so it doesnt get reset.
              (if the playlist hasnt yet loaded the extended file information, it will query the ML to avoid having ugly titles).

              Quite a few example scripts, some of which make use of a fairly generic quicksort algorithm which has been used to sort selected playlist entries by rating, playcount, last played etc. Its a useful bit of script for sorting stuff in the playlist in general - it could use a little bit of tweaking but its generally pretty reasonable.

              Plus some examples to just randomize a selection, reverse a selection, 'preview' a selection etc.
              Attached Files
              Music Plugins


              • #37
                hello again,

                I'd like to know if their a command the results of a quey in the library ?

                In fact I'd like to export my songs list but this MyFile.WriteLine(track.ATFString("%artist% - %album% - %tracknumber% %title%"))

                gives me this :

                Zero 7 - When It Falls - 11 Morning Song
                Zero 7 - When It Falls - 10 In Time
                Zero 7 - When It Falls - 09 Look Up
                Zero 7 - When It Falls - 08 Speed Dial No 2
                Zero 7 - When It Falls - 07 The Space Between
                Zero 7 - When It Falls - 06 When It Falls
                Zero 7 - When It Falls - 05 Over Our Heads
                Zero 7 - When It Falls - 04 Passing By
                Zero 7 - When It Falls - 03 Somersault
                Zero 7 - When It Falls - 02 Home
                Zero 7 - When It Falls - 01 Warm Sound
                Zebda - Utopie D'occase - 13 Le Répertoire
                Zebda - Utopie D'occase - 12 Le Paranoïaque
                Zebda - Utopie D'occase - 11 Le Bonhomme Derriè


                so I'd like to kwno how winamp chose the order of the results of a query !

                My other questions are : what does "ATFString" do ? And how can i make my vbs in a standalone script ?

                Sorry for the "newbie inside" style !
                Last edited by neFAST; 9 September 2004, 18:24.


                • #38
                  The results from the media library are just returned as given by the media library, as far as I know there is no way to specify the sort order. The results will need to be sorted after you get them. I will write a quick script to demonstrate how to sort them, it is not too difficult.

                  If they are already in exact reverse sort order, you could always work your way backwards from mlq.Count to 1. Otherwise, if each item is on its own line, you can just run it through the 'sort' command and it should work fine.

                  ATFString takes a filename and a format string and parses it through 'advanced title formatting', similar to that used in the playlist. The filename is taken from the 'mediaitem' it is operating on. My "toaster" plugin has a readme which explains in more detail all the available tags etc.

                  Because items like 'album' 'artist' and 'title' are cached after a media library query, you are actually better off using:

                  track.artst + track.album + track.ATFString("%tracknumber%") + track.title

                  As it will not have to re-look it up if the mediaitem (track) has come from a media library query.

                  You cannot currently write a script standalone, although it wouldnt be too difficult for me to implement, though I hadnt planned it. You will eventually be able to run scripts by just choosing a 'run script' command from within winamp then browsing for the file, if that is all you are after. For now just call it "playlist_whatever.vbs" and run it from the playlist menu.
                  Music Plugins


                  • #39
                    Thanks for the answer !
                    In fact I need the export to be a little quicker cause it takes something like 3mins for 16000 tracks.
                    And I think the quicksort could make this even longer !

                    I'm gonna test your trick "track.artst + track.album" to improve exporting time nad I'll tell ya.

                    in fact if I have perfect reverse order it's not a problem cause the export file is parsed with a php script. I just need to know it, that's why i did ask how the results are returned.

                    COuld you (quickly) tell me what does your plugin really do ? Is it something like a functions library ?
                    Plugins are in C++, aren't they ? and scripts in vb ...

                    Last question : %length% return length in seconds and *three* decimals !!! Is there any way to get h:m:s ?

                    And again : thanx !!


                    • #40
                      Use lengthf as outlined in the Toaster readme. You said you just wanted to do a one time export, so therefore why does the time it takes matter? (remember to put a 'quit' statement after the export otherwise the script keeps running).

                      3 mins is quite slow, but I guess it depends on your machine speed. I exported about 8,000 items to file in about 2 seconds, though I have a fairly reasonable machine. A sort would take a split second to do, try running 'sort exported.txt' and see how quick it is. (I am not sure if sort is standard on XP, but I think so, otherwise get cygwin). But still 3mins seems strange, try posting your script and I'll test it and see if its the same and see how it can be sped up.

                      If you are planning on doing programmatic exports regularly, then this might not be the plugin for you. It is designed for adding a quick customisation to Winamp without having to develop or install heaps of frivolous plugins. Its not really meant for use by external plugins, as they could typically do everything the script does, only faster as they dont have to parse script.

                      This plugin is indeed written in C++, it makes use of COM to create an instance of MS vbscript engine, and adds my own automation object to the script which can be used to control winamp. Thus allowing you to control winamp through vbscript.
                      Music Plugins


                      • #41
                        i've a 2.8Ghz so it's a bit strange.
                        Here's my code.
                        Const ForReading = 1, ForWriting = 2, ForAppending = 8

                        Set fso = CreateObject("Scripting.FileSystemObject")
                        Set MyFile = fso.OpenTextFile("C:\Program Files\Easyphp\www\songs.txt", ForWriting, True)

                        mlq = medialibrary.runqueryarray("type = 0")

                        for each track in mlq
                        MyFile.WriteLine(track.ATFString(track.artist + ";" + track.album + ";%tracknumber% " + track.title +";%bitrate%;%lengthf%;%year%;%genre%"))


                        in fact I wont use it regularly but something like 2 times in a week.

                        I have a basic knowledge in C++ (and zero experience in plugin writing) so I think you'll tell me that's it's impossible for me to rewrite it in C


                        • #42
                          i reverted to "%artist%;%album%;%tracknumber%;%title%;%bitrate%;%lengthf%;%year%;%genre%"

                          you track.Artist gives me a lots of tag reading failure or something like that AND a chaotic sorting !


                          • #43
                            That line should actually look like this

                            MyFile.WriteLine(track.artist + ";" + track.album + track.ATFString(";%tracknumber%;") + track.title + track.ATFString(";%bitrate%;%lengthf%;%year%;%genre%"))

                            But I see where the problem is, its actually something Ive been meaning to fix. The ATFString call should try the media library first and then try winamp itself.

                            The reason being that winamp will attempt to read the actual .mp3 file, especially for the 'lengthf' and 'bitrate' etc tags. I will cache more info from a media library query, and speed up the 'ATFString' call, and hopefully that will improve things.

                            If you remove the ATFString calls, and just use track.title, track.filename etc, you will notice that it doesnt take too long at all. ATFString() calls to stuff only in the media library (playcount, rating, tracknumber etc should be ok)

                            [edit] the reason for the tag reading failure etc is because you are putting track.artist inside the call to ATFString. look at my example above for how it should be.
                            Music Plugins


                            • #44
                              ok i'll try this tomorrow, it's near 4am here


                              • #45
                                id like to make a script that enqueues all of an album.. or inserts an album... i know nothing about computers(well.. i dont know much)

                                i just edited the included scripts.. but when i try, it doesnt include the song i picked(so it enqueus/inserts the album only without the original track clicked...

                                i guess the ideal script for me would insert one of dros separator things(or just a normal separator thats just ------------- or whatever) and then the album INCLUDING the song i clicked, and then another separator...

                                would this be somehow possible

                                is it possible to make a script based on other plugins(jtfe queue album) or to make it somehow 'enqueue/insert and play album?'

                                though at the moment.. my biggest problem, is it doesnt include the song i used the script on when it inserts/enqueues album/artist
                                There is no reset button on life... but the graphics kick ass