Page 1 of 4

UPNP client script 0.5 [MM3]

Posted: Mon Dec 17, 2007 7:24 pm
by botijo
In order to keep this easy to find, this first post will always link to two places:
Latest version of the script (v0.5)
Webpage explaining the actual problems I am facing

====== ORIGINAL POST ==============
Hi, everybody,
I know people have been ansioux about this, so I created myself an UPNP browser. I have tested it against the "Intel AV Media Server", so I know it can work. Does it work on other servers? Will you care to try for me?

Code: Select all

See a later post for the code
As you can see, at this moment, this is ugly, does need to be called, does not clean up when updating, is at the wrong location, shows message boxes... But hey, it really creates a node and creates a list with whatever the server thought it might be.
Just give it a shot, and if you know better ways to do this, please tell me, or improve the code yourself.

Before anyone asks, my priorities these days are (in order of preference):
1) Take a good break and enjoy the rain outside. Do XMas shopping.
2) See another way to use Nodes: whenever you click on a Node, ask the server
3) See how to add extra information, like Album, Tracklength, etc
4) Reuse of master node "UPNP servers"
5) Use of Timer to search for new servers, delete the older ones

Posted: Mon Dec 17, 2007 11:28 pm
by Peke
Great start, I'm impressed.
Few suggestions to ease you search and work:
- Look at MagicNode Script on how to use OnClick when browsing nodes and how to use Menu
- Look at ScrobblerDJ Script to see how to use Timer Events and how to manipulate selected node for setup and how to make Settings Sheet
- Use as much as possible SDB.ProcessMessages so that other scripts and MM UI is not locked while executing Script
- Make Configurable behavior using OnStartup/OnShutdown
- Last, but you should do it first. Enjoy the holidays.

THX for this.

Posted: Wed Dec 19, 2007 2:32 pm
by botijo
Here I post my second version of the script. I removed the MsgBoxes and I tried to clean up a little bit of code. This made me use of .NET COM objects, so you also need .NET installed in your computer.
Possibly, this will not work with Windows 98SE or similar.

By the way, I can only test the script on a Windows XP SP2 machine and Intel AV server.

Code: Select all

There is updated code available in a later post.
Thanks for pointing me to the right direction.
I tried the SDB.ProcessMessages without much success, as the main method for searching for devices is blocking (by the way, it takes about 5 seconds in my computer!). Any good resource for threads? Or should I avoid them? The idea is to have a loop with SDB.ProcessMessages until the blocking method finishes.

Posted: Wed Dec 19, 2007 2:57 pm
by Teknojnky
I don't really know if it matters or if one way (or both) is better...

but I normally put the the SDB.ProcessMessages at the end of the section of a loop, just before the loop ends.

To me, this should allow the processing of messages that were previously blocked.

for example:

Code: Select all

   For Each Device in Devices 
      'Various MM stuff 
'      SDB.ProcessMessages 
      ' Try to discard repeated devices 
      DeviceUDN = Device.UniqueDeviceName 
      For Each DeviceInList in UPNP_Devices 
         if DeviceUDN = DeviceInList.CustomData then 
         end if 
'      SDB.ProcessMessages 
      'If the device has still to be added, then search for ContentDirectory first 
      if DoAddDevice Then 
         set DeviceNode = SDB.MainTree.CreateNode 
         DeviceNode.Caption = Device.FriendlyName 
         DeviceNode.CustomData = DeviceUDN 
         ' Try to find the ContentDirectory service, and if so, fill in the hierarchy 
         For Each Service in Device.Services 
            if Service.Id = "urn:schemas-upnp-org:service:ContentDirectory" then 
               DeviceNode.CustomObject = Service 
               DeviceNode.CustomNodeId = 1 
               DeviceNode.IconIndex = 27 'Network Resources 
               SDB.MainTree.AddNode Node,DeviceNode,3 
               UPNP_FillChildNodes Service,"0",DeviceNode 
            end if 
      End If 
      Progress.Value=Progress.Value + 1 
Perhaps one of the team can better explain when/where to best use SDB.ProcessMessages if the above is not optimal.

Version [0.3]

Posted: Thu Dec 20, 2007 12:11 pm
by botijo
Hi, everyone,
it has been a miserable day today: rain in the morning, rain in the afternoon. So I spent some time fixing the issues I know with the script:
a) It works with TwonkyMedia server now
b) Uses debugview commands for logs
c) More fields are retrieved from the XML: Tracknumber, etc
d) Made autoscan every ten minutes OR re-opening the UPNP Node

Issues to be resolved:
a) What should I do with Album Artist? Neither Intel AV server or TwonkyMedia gives out that info.
b) Related to (a), what about Album Art? First I have to decide what is the album.
c) Add a configuration pane in the options, e.g. for autoscan time

I hope you enjoy this. If your server does not work, please send me a logfile created by debugview (that is a MS program), and I will have a look. It might be something easy as different service naming.

Code: Select all

Newer code in a later post

Upnp streaming

Posted: Thu Dec 20, 2007 4:43 pm
by OlivesInNZ
Hi all,
I'm not nearly as script literate as you all, but have a upnp capable server (Olive Musica) and would like to be able to stream music from other storage with media monkey to it - so i can use ScrobblerDJ!!
Would someone be able to give me a few more details on how to implement botjo's script please?

Posted: Thu Dec 20, 2007 7:42 pm
by botijo
Hi, Olives,
it is not like I am the best person to script! Ok, so let's go through the easy way (I suppose you have MM3 installed like I do - take a look in the Beta forum if you have not done so):
1) Download Installation Package
2) Double click on it and MM3 should ask to install the script.
3) Restart MediaMonkey
4) Wait and see if the UPNP Servers node has your device. If so, you are finished and everything worked as expected.

Because of many timeouts in the MS implementation of UPNP, it might take some seconds to find all your devices. To me, it takes less than 10 seconds.

If there is no node under "UPNP Servers", please download DebugView. This programs catches debug information given by every program in your computer. I am interested only in the ones that start with "MM/UPNP". If you cand send me those lines, I might try to get to the bottom of your trouble. Please try to expand/collapse/double click the "UPNP Servers" Node.

If you find any messagebox in MM, please report them too. Thanks for testing the script.

Posted: Thu Dec 20, 2007 8:03 pm
by Peke
I have nothing to add to your comment, I personally add Process Messages where ever I find that something freezes MM both Before and After freeze.
MM may become chunky but it will not freeze.

To cut execution of timed events you can try to make them on demand by using Explicit Public dims and set them as needed or even control timer values or skip over and not execute slow parts of script.


Posted: Sun Dec 30, 2007 2:13 pm
by OlivesInNZ
Hi Botijo,
MM has a node with my device, but can't see the library of songs on it or see the MM library from the device. I imagine there may be settings on even possibly firmware on the Olive end which i need to change, I will keep tinkering but wanted to let you know the discovery went just fine.

Problems with the script

Posted: Tue Jan 01, 2008 9:18 am
by KoMa666
Hi Botijo,

first of all: A great script!! This is a feature that I misses most in MM3.

But here are a couple of bugs/problems:

1. In Windows XP it seems that you have to install "UPNP User Interface ..." (I don't know how it is exactly named in the englisch WinXP) for the script to work.

2. In Windows Vista with activated UAC you have to start MM with admin privileges (right click, ...) otherwise the script would not install (at least if MM is installed on C:)

3. (I use a german Vista/XP):
I get an UBound - Exception in Line 45, Column 3. I found out that it is the function UPNP_Seconds2Longint (TimeString). There seems to be a missing "E" in fram_E_split in

Code: Select all

select case UBound(framsplit)
4. There seems to be a bug in the AlbumArt. When using the WebBrowser of TwonkyMedia 4.4.3 an album cover is being displayed. Every song with which I am testing has to arts (both Cover (front), one embedded and one linked from the directory).

Code: Select all

If Not(albumArtURI="") Then
	Set AAList = NewSong.AlbumArt
	if AAList.Count = 0 Then	'Do not add any if it already exists
		Set AA = AAList.AddNew
		AA.PicurePath = albumArtURI
		AA.ItemStorage = 1  ' External, as we do not want to update any DB
		AA.ItemType = 3 	' Cover
	End If
End If
I get an error -2147418113 in the line "Set AA = AAList.AddNew". If I comment anything out within this if, I can play the songs ...

5. Then I have another question: After a song has been played, this song is beeing removed from the playlist instead of jumping to the next song. It would be great if the played songs are still in the playlist for an endless repeat.


Posted: Wed Jan 02, 2008 11:25 am
by Kos
Is it possible to make it work with WLAN and/or a NAS? (Check my set-up).


Posted: Wed Jan 02, 2008 1:48 pm
by botijo

Thanks for testing. This is indeed useful to know about problems and the like. Let me answer some of the things I know of:

1. You are right indeed. The script needs that Windows component. I will have a look at the right name.
Update: I found that I have installed following component
Add or Remove Programs > Windows Components > Networking Services > UPnP user interface
I am not 100% you need this, I might try to remove it and see what happens.

2. I do not have Vista, so I do not know the particularities about this. If this is an install thing, I would say it might be common for every script with the new installer. I know Trixmoto has some of his/her scripts with the new installer system, so you can try those and see. MonkeyRox is a fine example.

3. I did some tests here, but unfortunately, I did not have any server/media that was being reported with frames, so I did not test that part. Thanks for flagging the spelling mistake.

4. Similar to (3), I did not test the feature. I have replicated the problem, so I am working on this. I have no clue why MM is reporting a catastrophic error, but I will try as many things as I can think of.

5. This looks unrelated to the script, as it does not manage playlists at all. Can you check MM options wrt keeping already played songs? My copy of MM is keeping track of everything in the list.

The script is based on Windows functionality. If you can see your device under Windows XP / Network shares / Show UPNP devices, then you should be able to see this in this script. The only problem I can see is that by default Windows limits the UPNP search commands with a TTL (Time To Live) of 1, meaning only one hop is allowed. I am working with MM and the server on the same machine, so I cannot test this. The best thing you can do is test and see. It might or might not work.

It is good to see that your Olive device can be seen. If I have some time, I will rewritte the log commands so that you can send me a log and I can see what is happening.

I have not been working on the project because I was far away from computer this last week. Expect some work on the following days.

Posted: Wed Jan 02, 2008 5:32 pm
by Miki
Just to say, i was having the same error as Koma666 - Line 45 C3.

once i changed "framsplit" to "framesplit" it worked perfect.

Great script :)

Cheers, Mike.

Posted: Thu Jan 03, 2008 1:38 am
by irshjet35
I am interested in this script to see if this will work with my xbox360 like WMP. I am not sure what I am supposed to save the file as since the install package doesnt work for me.

Posted: Thu Jan 03, 2008 3:24 am
by botijo
Hi, irshjet35,
If I understand correctly, you are using the Windows Media Player as the UPNP server (that is where all the music is), and the Xbox360 as the UPNP client. The script makes MM as a UPNP client, not a server, so if I understand correctly, MM will not replace your Windows Media Player as a server for the time being.
I had a look in the UPNP functions provided by Windows, and unfortunately, you cannot do the server thing as easy as the client thing - there is no VBScript support there. You know, the info is out there in the MSDN, it is a matter of piecing everything together. If you know a little bit more of C++ than me, you might be creating a UPNP server in no time.
About installation packages: as MM has hit the v3 Milestone, I suggest you to upgrade to MM3. Installation packages only work on MM3.