MonkeySqueeze Development V3.0.2.

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

Re: MonkeySqueeze Development

Postby Gingernut63 » Fri Sep 02, 2011 5:27 pm

@Katteman

Thank you for your reply. Fantastic that you have communications up and running with a NAS Squeezebox Server, it will be very useful for some our users. However I'll have to get you to expand your instructions please as I need a little more detail to fully understand them.

Wow 15 seconds is a lot of lag time, could you please answer the following questions. The info is handy in building a understanding of the issue:
- 1. Is it 15 seconds for FLAC files or for mp3s as well?
- 2. Did the lag increase when using the NAS Squeezebox Server?
- 3. What processor does your computer use?
- 4. Do you have a large network?
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: viewtopic.php?f=2&t=59515
MonkeySqueeze Development: viewtopic.php?f=19&t=59907
MediaMonkey user since 2005
Gingernut63
 
Posts: 188
Joined: Thu Jul 14, 2011 4:13 am

Re: MonkeySqueeze Development

Postby booblers » Fri Sep 02, 2011 6:56 pm

deleting my posts since forum moderators see fit to delete honest posts. just helping to make their job easier. nothing to see here.
Last edited by booblers on Mon Jan 09, 2012 11:08 pm, edited 1 time in total.
booblers
 
Posts: 97
Joined: Sat Sep 27, 2008 6:57 pm

Re: MonkeySqueeze Development

Postby Gingernut63 » Fri Sep 02, 2011 7:37 pm

@booblers

Thanks for the info. Clarifies and answers info, questions and suppositions from previous posts.

I may be wrong but Squeezebox Server may use playlist queuing when interfacing with iTunes, don't know how well it works but it is an official part of the package so the results must be ok.

You may not have seen one of the previous posts where I suggested using the track countdown time in Squeezebox Server to pause the track in MediaMonkey, but as you say this is a just a workaround addressing the symptom and not the main issue. My preferred idea was to use a sync function like the one in Squeezebox Server which from the help files is a little hit and miss with software players. Do you think a true sync plugin would achieve or better the results of the Squeezebox Server sync function?

What direction do you think MonkeySqueeze should take, true sync or playlist queuing?

Thanks again for your suggestions, always good to get input from experienced code writers.
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: viewtopic.php?f=2&t=59515
MonkeySqueeze Development: viewtopic.php?f=19&t=59907
MediaMonkey user since 2005
Gingernut63
 
Posts: 188
Joined: Thu Jul 14, 2011 4:13 am

Re: MonkeySqueeze Development

Postby Katteman » Sat Sep 03, 2011 4:40 pm

I timed the lag for two tracks of 3:00 minutes. One MP3 and one flac. For MP3 the lag was 7 seconds, for flac it was 9 seconds.
Perhaps the 15 seconds was once while I was trying to get things working.
I am only using the NAS SqueezeCenter now. The NAS is a Synology 207+ with a 500MHz Marvell CPU and 128 MB memory, that's why I stick to the modest SqueezeCenter 7.3.3.

I noticed now an unexpected behaviour. When I play a new track while MediaMonkey and Squeezebox are already playing, then MediaMonkey starts the new track, but squeezebox only stops the current track. When I toggle MonkeySqueeze off and on using the menu icon the new track starts playing on the squeezebox. Then suddenly, after switching off and on several times, it starts working. Stopping the current track and then starting the new track. Strange!!

I am using two laptops at home. One is a Sony VAIO F11 with an Intel i5 M520 @ 2.4 GHz and using 5 MHz WiFi :D . The other one is a small MSI, which I use to maintain and control my music library, with an AMD E350 CPU, using a fixed ethernet cable. Including the NAS and the Queezebox Duet that's my whole network.
For both PC's the time lags are identical, 7 sec for MP3 and 9 sec for flac.

I will try to explain the changes to the script.
My music library is in the directory "music" on the NAS volume "volume1".
I mapped the NAS directory "//DISKSTATION1/music" to drive "Y:". So MediaMonkey finds a music file, for instance "Y:\MP3\example.mp3".
The NAS SqueezeCenter has its base at "/volume1/music". This value can be found in the QueezeCenter settings, on the tab "Basic Settings" as the value of "Music Folder".
This value is identical to drive "Y:", so the example file is found on the NAS as "/volume1/music/MP3/example.mp3".
The two lines I added after getting the filename "TrackPath" are:

TrackPath = Replace(TrackPath,"\","/")
TrackPath = Replace(TrackPath,"Y:","/volume1/music")

It is added in the subroutines "Event_OnPlay", "SyncToggle" and "Event_OnSeek".
The values "Y:" and "/volume1/music" depend on your NAS setup. Y: is the library path as seen by MediaMonkey, /volume/music is the library path as seen by SqueezeCenter.
In OrangeCD you have to enter them in the Squeezebox setup menu.

I hope this will be of help for you and other users who want to try it.

Katteman
Katteman
 
Posts: 9
Joined: Fri Sep 02, 2011 2:09 pm

Re: MonkeySqueeze Development

Postby Gingernut63 » Sat Sep 03, 2011 5:10 pm

@Katteman

Thanks for the reply.

Have a better understanding of what you have done. I would like to integrate your settings into MonkeySqueeze to give people the option of using a PC Squeezebox Server or the NAS version.

Thank you for the network details. Good to see the lag is less than suspected but it's still not acceptable. I know what I would like to do to get rid of the lag, I just don't have the programming ability at this stage. Would love someone with the expertise to have a go though, if only I could offer large amounts of cash or maybe gold, maybe a I could offer a shirt with "I'm a MonkeySqueezer" on it :lol: .

Will investigate your play issue and get back at a later stage. I have noticed a similar issue myself but it happens very rarely. One thought, find the following line and change the value from 1 to 2 or even more. See if that makes a difference.

slimRequest(formatCommand("""time"", """ + CStr(SDB.Player.PlaybackTime*0.001 + 1) + """")) 'added 1 second to try to make up for net and lookup lag

I'll keep you posted.
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: viewtopic.php?f=2&t=59515
MonkeySqueeze Development: viewtopic.php?f=19&t=59907
MediaMonkey user since 2005
Gingernut63
 
Posts: 188
Joined: Thu Jul 14, 2011 4:13 am

Re: MonkeySqueeze Development

Postby Gingernut63 » Sat Sep 03, 2011 5:37 pm

@Katteman

Just a thought, your changes might have an effect on the play issue. Try running the unmodified beta with the C:\ SqueezeServer, do you get the same issue?
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: viewtopic.php?f=2&t=59515
MonkeySqueeze Development: viewtopic.php?f=19&t=59907
MediaMonkey user since 2005
Gingernut63
 
Posts: 188
Joined: Thu Jul 14, 2011 4:13 am

Re: MonkeySqueeze Development

Postby Katteman » Sun Sep 04, 2011 4:37 pm

I'll try the suggestions and will report it.
I had a first view on all the Squeezebox commands, but it is a bit overwhelming.
Also the script has some functions that are at the moment not clear to me, for instance SyncToggle and ManualTrackChange.
I will try to find out what's happening.

One remark: The logme routine is very useful, but the default (script) directory is not accessable for writing in Windows 7. I changed it to a writeable location, but another option is to change the rights for the script directory. That makes is easier to modify the scripts.

Greetings,
Katteman
Katteman
 
Posts: 9
Joined: Fri Sep 02, 2011 2:09 pm

Re: MonkeySqueeze Development

Postby Gingernut63 » Sun Sep 04, 2011 5:28 pm

@Katteman

For a better understanding of SnycToggle read all of booblers posts in this forum. For original coding ideas, read posts on the following forum:

viewtopic.php?f=2&t=21124&hilit=MM+and+Squeezebox

I have a ReadyNAS Duo running Squeezebox Server and alas your suggestions don't work with my setup :( . After doing a bit of research there appears to be some differences between the Synology and ReadyNAS versions of Squeezebox Server which might make all the difference. However I would love to be proven wrong.
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: viewtopic.php?f=2&t=59515
MonkeySqueeze Development: viewtopic.php?f=19&t=59907
MediaMonkey user since 2005
Gingernut63
 
Posts: 188
Joined: Thu Jul 14, 2011 4:13 am

Re: MonkeySqueeze Development

Postby Katteman » Mon Sep 05, 2011 5:26 am

I tried your suggestions.
The PC-based SqueezeCenter behaves better than the NAS version. From the beginning playing a new track stops the current track and starts playing the new track.
The NAS version stops playing the current track, but starts the new track only after toggling MonkeySqueeze off and on. After trying several tracks the normal behaviour appears: stop current, play new.
Also after starting a new track the time bar on the Duet controller becomes visible showing 4 seconds, then returns to zero and starts playing. This all takes about 7 to 8 seconds as I said earlier.
The PC-based SqueezeCenter starts playing with a time lag of 2 to 3 seconds and the time bar on the controller does not jump back to zero.
It seems to me that the delay of the NAS-based server is caused by the less powerful environment.

From your reply it also seems that the NAS-versions are also different. I use the version that is released by Synology, so I don't know what modifications are introduced (if any).
Is the readyNAS version also provided by the manufacturer or are you using the Logitech releases?
The OrangeCD solution for playback using the Squeezebox will not work if you cannot provide the difference in library filenames between the PC and the NAS.
I wonder if it is possible to show the filename that the server is using when playing a track. Then you would see the difference between the filename for Mediamonkey and the filename in the NAS.

Greetings,
Katteman

PS. If the NAS is using Linux, as most do, the file name and path are case sensitive! And in my case any character outside the 7-bit ASCII range is also not accepted by SqueezeCenter. Might that be the problem?
Katteman
 
Posts: 9
Joined: Fri Sep 02, 2011 2:09 pm

Re: MonkeySqueeze Development

Postby Gingernut63 » Mon Sep 05, 2011 6:11 am

@Katteman

The slower the processor and the more demand placed on a system, the greater the lag as it takes longer to buffer the track before each play. The extra calculations from windows to Linux will also slow things as well.

The version used on the ReadyNAS is the official Squeezebox release. Yes you are correct my ReadyNAS DUO is using Linux. My PC Squeezebox Server doesn't use a music database at all, it's looking at an empty folder and MediaMonkey and MonkeySqueeze work just fine with this arrangement because all the programs are running in Win7. On the other system I'll double check the case and the format used for the filename and compare to the 7-Bit ASCII range as suggested. Always suspected that the Linux-sparc side might be causing the problem but couldn't narrow it down from there.
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: viewtopic.php?f=2&t=59515
MonkeySqueeze Development: viewtopic.php?f=19&t=59907
MediaMonkey user since 2005
Gingernut63
 
Posts: 188
Joined: Thu Jul 14, 2011 4:13 am

Re: MonkeySqueeze Development

Postby Gingernut63 » Mon Sep 05, 2011 8:00 am

@Katteman

Success! :D Your first line was causing the problem for me. After a while I looked at the first line and thought it was unnecessary as the new destination with correct format is specified in the second line.
Code: Select all
TrackPath = Replace(TrackPath,"\","/")
As soon as I removed it and just ran with the following line, music started to play on the NAS Squeezebox Server and devices.
Code: Select all
TrackPath = Replace(TrackPath,"X:\Music","/media/Music")


Can you run without the first line on your setup? If I'm to add this to the settings page and modify the script it needs to be standardised across all NAS drives if possible. Can't have too many variations.
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: viewtopic.php?f=2&t=59515
MonkeySqueeze Development: viewtopic.php?f=19&t=59907
MediaMonkey user since 2005
Gingernut63
 
Posts: 188
Joined: Thu Jul 14, 2011 4:13 am

Re: MonkeySqueeze Development

Postby Katteman » Mon Sep 05, 2011 2:28 pm

The main reason for me to use the NAS-based SqueezeCenter is that I sometimes use the Duet controller to play music from the library with 16000 tracks and sometimes a PC program to select music from my total amount of music tracks. SqueezeCenter on the NAS manages only a small selection of my music and still finding a track with the controller is awkward.
My NAS-based server has only access to files on the NAS, so all music tracks need to be on the NAS also. When I select a track on a local hard disk the NAS server is not able to play that track (checked).
The storage volume on the NAS is called "volume1", my music is stored in the directory "music" and the library for the SqueezeCenter is located in the sub-directory "MP3".
So the SqueezeCenter setting for "Music Folder" is "/volume1/music/MP3", the setting for "Playlists Folder" is "/volume1/music/Playlists".

A file inside my library is, for example "\volume1\music\MP3\Pop\A\Angels - Wow wow wee.flac"
MediaMonkey sends this file as "Y:\MP3\Pop\A\Angels - Wow wow wee.flac"

A file outside the library is "/volume1/music/Classical/Vivaldi/Le Quattro Stagioni - Janine Jansen/10 - L'Inverno- 1. Allegro non molto.flac"
MediaMonkey sends it as "Y:\Classical\Vivaldi\Le Quattro Stagioni - Janine Jansen\10 - L'Inverno- 1. Allegro non molto.flac"

I checked the file names with the "logme" subroutine.

I tried the script without the change from "\" to "/", but then no track was played. That makes sense because the NAS uses a Linux-style path. On the other hand, the spaces in the path cause no problem, where Linux accepts no spaces.
I suppose some windows-style elements are solved by the server - the spaces - while other elements - the backslashes - are not. And also that it depends on the version and/or implementation.

I also use playlists, because they allow me to select music outside the library. These playlists are in Windows-style format, relative to the "music" directory, so the above mentioned tracks are entered as:
..\MP3\Pop\A\Angels - Wow wow wee.flac
..\Classical\Vivaldi\Le Quattro Stagioni - Janine Jansen\10 - L'Inverno- 1. Allegro non molto.flac
This works in Windows, but also in SqueezeCenter, so here the backslashes cause no problem!! Again I think that the playlist scanner solves the problem.

If there are too many differences between all versions of NAS's and Squeezebox Servers it becomes very difficult to find a solution that works on all machines. The intersection of Squeezebox users and MediaMonkey users is probably larger than two. :wink:

Another thought: In OrangeCD all additional tracks are added to the playlist, so there is no problem with premature ending, but OrangeCD does not play the track locally when the tracks are sent to the SqueezeCenter. MediaMonkey is playing the tracks locally and sends the filename also to the SqueezeCenter, so when the next track starts, the currently playing track on the squeezebox is terminated and the next track starts.
So it is a different approach, perhaps some ideas might surface when contemplating these two methods.

Greetz, Katteman
Katteman
 
Posts: 9
Joined: Fri Sep 02, 2011 2:09 pm

Re: MonkeySqueeze Development

Postby Gingernut63 » Mon Sep 05, 2011 3:57 pm

@Katteman

Good post!

The main difference in file handling between the systems is that Logitech write the Squeezebox Server addon for ReadyNAS and Synology write their own. Obviously there is a different approach by both parties to file addressing for whatever reason, which is a shame. Life wasn't meant to be easy so they say. As a side note Synology have released newer versions of Squeezebox Server, have you tried those yet? What if.....

However all is not lost. At the very least your efforts will be rewarded with instructions in the user guide on how to mod the script for NAS drives. I still believe I can provide inputs on the settings page for ReadyNAS and Synology Drives and hopefully they may work for the majority of other NAS drives running Squeezebox Server on Linux. When the beta is released it would be good if we received feedback from the other users.

You posting of the how the file addressing works between the two systems will be very illuminating to the Squeezebox Server NAS users and other MonkeySqueezers.

Yes the premature ending issue has been discussed by booblers; send the next track so Squeezebox Server can start buffering, or me; monitor the track time on Squeezebox Server and delay play in MediaMonkey. If we want to fix the lag/buffer issue for good then as suggested by booblers and me; introduce a SqueezeBox Server synchronise function between MediaMonkey and the Squeezebox system. booblers also suggested playlist queuing but I personally favor synchronise.

Thanks for your efforts so far, they are much appreciated.
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: viewtopic.php?f=2&t=59515
MonkeySqueeze Development: viewtopic.php?f=19&t=59907
MediaMonkey user since 2005
Gingernut63
 
Posts: 188
Joined: Thu Jul 14, 2011 4:13 am

Re: MonkeySqueeze Development

Postby Katteman » Mon Sep 05, 2011 4:36 pm

I did use the newer versions of Squeezebox Server, but the NAS is not powerful enough for the all the new features. Synology also discourages the use of the later versions on a 207+, so I stick to the old SqueezeCenter.
Katteman
 
Posts: 9
Joined: Fri Sep 02, 2011 2:09 pm

Re: MonkeySqueeze Development - Beta 110917

Postby Gingernut63 » Sun Sep 11, 2011 7:50 pm

Latest Beta release V2.0.0.110917. (Mistake in the copy of this script has been found and rectified, sorry for any inconvenience)

The current version of the script is optimised for MediaMonkey 4 and above. It will run on MediaMonkey 3 but the options page will not display correctly.

The next official release is close. At this stage the most outstanding issue is the lag, however as there have been so many positive changes to this point, it is about time for an official release. MonkeySqueezers will find it very useful.

Release improvements:
1. MonkeySqueeze now communicates with NAS drives using Linux and running Squeezebox Server (Logitech Media Server)! :D Thanks goes to Katteman for the addressing code. At this stage only ReadyNAS and Synology drives have been tested and are known to work. Katteman and I need feedback from people with other drives to see if the settings need to be tweaked.

2. I have revised the options page again, including settings for addressing of NAS drives and rewriting some instructions and tooltips.

Known Issues:
1. Major: Lag or buffering between MediaMonkey and the Squeezebox system. Work ongoing with options being investigated. Always on the lookout for someone to assist with the issue.

2. Minor: There are two issues which can occur when re-enabling the connection. The music will not play on LMS the first time play is pressed or music plays on LMS when the enable button is pressed. In both cases stop the track and press play again to return to normal.

To use this version:
Copy the script to Notepad and save as MonkeySqueeze.vbs to one one of the following locations:
C:\Program Files\MediaMonkey\Scripts\Auto or C:\Program Files (x86)\MediaMonkey\Scripts\Auto

If you use this script please report any issues on this forum. Feedback is required so we can implement changes before any official release.

Code: Select all
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
' MonkeySqueeze V2-0-0-110917Beta
'
' ORIGINAL AUTHOR: Todd Nemeth/revel
' DATE STARTED: 26.09.2007
'
' ADDITIONAL AUTHORS: Baz, Big_Berny, Peke, trixmoto, debacle, mccstumble, Gingernut63, booblers, Katteman
' UPDATE DATE: XX.XX.20XX
'
' COMMENT:
'  - You will also need Logitech Media Server (Squeezebox Server) installed and running
'  - Optional: Install and run SqueezePlay or SoftSqueeze
'  - After installation the settings page for this script is located at Tools > Options > MonkeySqueeze
'
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Option Explicit
Public SqueezeBoxSocket
Public ManualTrackChange
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim onMonkeySqueezeIcon
Dim offMonkeySqueezeIcon


'**************************************************************
Sub OnStartup
   Dim ind, Mnu
   Dim UI : Set UI = SDB.UI
      
   onMonkeySqueezeIcon = SDB.RegisterIcon("Scripts\Auto\sbon.ico", 0)
   If onMonkeySqueezeIcon < 0 Then
      onMonkeySqueezeIcon = 74 'unlocked icon if it doesn't exist
   End If
   
   offMonkeySqueezeIcon = SDB.RegisterIcon("Scripts\Auto\sboff.ico", 0)
   If offMonkeySqueezeIcon < 0 Then
      offMonkeySqueezeIcon = 75 'locked icon if it doesn't exist
   End If
   
   Set Mnu = UI.AddMenuItem( UI.Menu_TbStandard, 0, 0)
   Mnu.Caption = "MonkeySqueeze"
   Mnu.UseScript = Script.ScriptPath
   Mnu.OnClickFunc = "SyncToggle"
   Mnu.IconIndex = onMonkeySqueezeIcon
   Mnu.Hint = "Enable/Disable MonkeySqueeze"
   
   Set SDB.Objects("MonkeySqueezeIcon") = Mnu      'save a reference to it so we can change the icon later.
   
   If SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = True Then
      Call registerEvents
      Mnu.IconIndex = onMonkeySqueezeIcon
   Else
      Mnu.IconIndex = offMonkeySqueezeIcon
   End If
   
   ind = SDB.UI.AddOptionSheet("MonkeySqueeze",Script.ScriptPath,"InitSheet","SaveSheet",-2)
   'InitSqueezeBox
   ManualTrackChange = True
   
End Sub

'**************************************************************
Sub InitSheet(Sheet)
   Dim Panel1, Panel2, Edit1, Panel3, Btn1, Edit2, Panel4, Edit3, Edit4, Edit5, Checkbox1, Checkbox2
   
   Set Panel1 = SDB.UI.NewGroupBox(Sheet)
   Panel1.Common.SetRect 10,10,450,75
   Panel1.Caption = "MonkeySqueeze v2.0.0.110917Beta"
   
   With SDB.UI.NewLabel(Panel1)
      .Common.SetRect 15,20,440,40
      .Caption = "This script allows MediaMonkey to play music on a Squeezebox System"& vbNewLine _
      & vbNewLine _
      & "Enable/Disable MonkeySqueeze on the toolbar main menu"
   End With
   
   Set Btn1 = SDB.UI.NewButton(Panel1)
   Btn1.Common.SetRect 360,40,65,25
   Btn1.Caption = "User Guide"
   Btn1.Common.Hint = "Click and then open MonkeySqueeze_UserGuide.pdf"
   Script.RegisterEvent Btn1, "OnClick", "UserGuide"
   
   Set Panel2 = SDB.UI.NewGroupBox(Sheet)
   Panel2.Common.SetRect 10,95,450,125
   Panel2.Caption = "Logitech Media Server IP Address and HTTP Port"
   
   With SDB.UI.NewLabel(Panel2)
      .Multiline = True
      .Common.SetRect 15,20,420,50
      .Caption = "Open the LMS (Squeezebox Server) Web Control page > Settings > Information tab and find the Server IP Address, e.g. 192.168.0.102 and enter below. The default HTTP Port number is 9000. See the user guide if you wish to change it"
   End With
   
   With SDB.UI.NewLabel(Panel2)
      .Common.SetRect 15,74,70,20
      .Caption = "IP Address:"
   End With
   
   Set Edit1 = SDB.UI.NewEdit(Panel2)
   Edit1.Common.ControlName = "SqueezeBoxIP"
   Edit1.Common.SetRect 75,70,95,25
   Edit1.Text = SDB.IniFile.StringValue("SqueezeBox","IP")
   If Edit1.Text = "" Then
      Edit1.Text = "XXX.XXX.XXX.XXX"
      SDB.IniFile.StringValue("SqueezeBox","IP") = "XXX.XXX.XXX.XXX"
   End If
   Edit1.Common.Hint = "Copy and paste the LMS IP Address here"
   
   With SDB.UI.NewLabel(Panel2)
      .Common.SetRect 215,74,70,20
      .Caption = "HTTP Port No:"
   End With
   
   Set Edit2 = SDB.UI.NewEdit(Panel2)
   Edit2.Common.ControlName = "SqueezeBoxPort"
   Edit2.Common.SetRect 287,70,40,25
   Edit2.Text = SDB.IniFile.StringValue("SqueezeBox","Port")
   If Edit2.Text = "" Then
      Edit2.Text = "9000"
      SDB.IniFile.StringValue("SqueezeBox","Port") = "9000"
   End If
   Edit2.Common.Hint = "HTTP port default is 9000. View the port number in LMS: Web Control page > Settings > Information tab. It can be changed, see user guide for more details"
   
   With SDB.UI.NewLabel(Panel2)
      .Common.SetRect 15,100,420,20
      .Caption = "Press OK and restart the music for the changes to take effect."
   End With
   
   Set Panel3 = SDB.UI.NewGroupBox(Sheet)
   Panel3.Common.SetRect 10,230,450,125
   Panel3.Caption = "Squeezebox Device MAC Address"
   
   With SDB.UI.NewLabel(Panel3)
      .Multiline = True
      .Common.SetRect 15,20,420,60
      .Caption = "The MAC address of the device (Touch, SqueezePlay, etc...) you wish to connect to. Open the LMS Web Control page > Settings page > Information tab and find the relevant device. Enter the MAC address below, e.g. z1:6d:4g:40:1f:32"
   End With
   
   With SDB.UI.NewLabel(Panel3)
      .Common.SetRect 15,74,70,20
      .Caption = "Device MAC Address:"
   End With
   
   Set Edit3 = SDB.UI.NewEdit(Panel3)
   Edit3.Common.ControlName = "SqueezeBoxMAC"
   Edit3.Common.SetRect 122,70,110,25
   Edit3.Text = SDB.IniFile.StringValue("SqueezeBox","MAC")
   If Edit3.Text = "" Then
      Edit3.Text = "xx:xx:xx:xx:xx:xx"
      SDB.IniFile.StringValue("SqueezeBox","MAC") = "xx:xx:xx:xx:xx:xx"
   End If
   Edit3.Common.Hint = "Copy and paste the MAC address here. Use lowercase text for maximum compatibility"
   
   With SDB.UI.NewLabel(Panel3)
      .Common.SetRect 15,100,420,20
      .Caption = "Press OK and restart the music for the changes to take effect."
   End With
   
   Set Panel4 = SDB.UI.NewGroupBox(Sheet)
   Panel4.Common.SetRect 10,365,450,165
   Panel4.Caption = "Logitech Media Server on a NAS using Linux"
   
   With SDB.UI.NewLabel(Panel4)
      .Multiline = True
      .Common.SetRect 15,20,420,60
      .Caption = "MonkeySqueeze communicates with LMS installed on a NAS however changes must be made to the format of the main music folder address. e.g. X:\Music to /media/Music"
   End With
   
   Set CheckBox1 = SDB.UI.NewCheckBox(Panel4)
   CheckBox1.Common.SetRect 60,53,260,20
   CheckBox1.Checked = SDB.IniFile.BoolValue("NAS","Enabled")
   CheckBox1.Common.ControlName = "EnableNAS"
   CheckBox1.Common.Hint = SDB.Localize("Select if using LMS on a Linux NAS device this includes Synology units. See user guide for more details")
   CheckBox1.Caption = SDB.Localize("Enable")
   Script.RegisterEvent CheckBox1.Common, "OnClick", "NASClick"
   
   Set CheckBox2 = SDB.UI.NewCheckBox(Panel4)
   CheckBox2.Common.SetRect 260,53,260,20
   CheckBox2.Checked = SDB.IniFile.BoolValue("Synology","Enabled")
   CheckBox2.Common.ControlName = "EnableSynology"
   CheckBox2.Common.Hint = SDB.Localize("Select if the NAS is made by Synology or if communications with LMS don't work")
   CheckBox2.Caption = SDB.Localize("Synology NAS")
   
   With SDB.UI.NewLabel(Panel4)
      .Common.SetRect 15,84,70,20
      .Caption = "MediaMonkey Music Folder:"
   End With
   
   Set Edit4 = SDB.UI.NewEdit(Panel4)
   Edit4.Common.ControlName = "MediaMonkeyMF"
   Edit4.Common.SetRect 150,80,160,25
   Edit4.Text = SDB.IniFile.StringValue("MediaMonkey","MF")
   If Edit4.Text = "" Then
      Edit4.Text = "X:\____\____"
      SDB.IniFile.StringValue("MediaMonkey","MF") = "X:\_____\_____"
   End If
   Edit4.Common.Hint = "Copy from MediaMonkey > File > Add/Rescan Folders or the Path column in the music details section"
   
   With SDB.UI.NewLabel(Panel4)
      .Common.SetRect 15,114,70,20
      .Caption = "Logitech Media Server Music Folder:"
   End With
   
   Set Edit5 = SDB.UI.NewEdit(Panel4)
   Edit5.Common.ControlName = "SqueezeboxMF"
   Edit5.Common.SetRect 190,110,180,25
   Edit5.Text = SDB.IniFile.StringValue("Squeezebox","MF")
   If Edit5.Text = "" Then
      Edit5.Text = "/_____/_____"
      SDB.IniFile.StringValue("SqueezeBox","MF") = "/_____/_____"
   End If
   Edit5.Common.Hint = "Copy and Paste from: LMS Web Page > Settings > Basic Settings tab > Music Folder"
   
   With SDB.UI.NewLabel(Panel4)
      .Common.SetRect 15,140,420,20
      .Caption = "Press OK and restart the music for the changes to take effect."
   End With
   
   CheckBox2.Common.Enabled = CheckBox1.Checked
   Edit4.Common.Enabled = CheckBox1.Checked
   Edit5.Common.Enabled = CheckBox1.Checked
   
End Sub
'**************************************************************
Sub NASClick(ChB)
   Dim ChB2, Edt4, Edt5
   
   Set ChB2 = ChB.Common.TopParent.Common.ChildControl("EnableSynology")
   Set Edt4 = ChB.Common.TopParent.Common.ChildControl("MediaMonkeyMF")
   Set Edt5 = ChB.Common.TopParent.Common.ChildControl("SqueezeboxMF")
   ChB2.Common.Enabled = ChB.Checked
   Edt4.Common.Enabled = ChB.Checked
   Edt5.Common.Enabled = ChB.Checked
End Sub
'**************************************************************
Sub SaveSheet(Sheet)
   SDB.IniFile.StringValue("SqueezeBox","IP") = Sheet.Common.ChildControl("SqueezeBoxIP").Text
   SDB.IniFile.StringValue("SqueezeBox","Port") = Sheet.Common.ChildControl("SqueezeBoxPort").Text
   SDB.IniFile.StringValue("SqueezeBox","MAC") = Sheet.Common.ChildControl("SqueezeBoxMAC").Text
   SDB.IniFile.BoolValue("NAS","Enabled") = Sheet.Common.ChildControl( "EnableNAS").Checked
   SDB.IniFile.BoolValue("Synology","Enabled") = Sheet.Common.ChildControl( "EnableSynology").Checked
   SDB.IniFile.StringValue("MediaMonkey","MF") = Sheet.Common.ChildControl("MediaMonkeyMF").Text
   SDB.IniFile.StringValue("Squeezebox","MF") = Sheet.Common.ChildControl("SqueezeboxMF").Text
End Sub
'**************************************************************
Sub UserGuide
   On Error Resume Next
   Dim OF, FolderToOpen
   
   Set OF = CreateObject("Shell.Application")
   FolderToOpen = sdb.ScriptsPath & "Auto\"
   OF.Explore FolderToOpen
   Set OF = Nothing
End Sub
'**************************************************************
'Sub InitSqueezeBox
   'On Error Resume Next
   'Set SqueezeBoxSocket = CreateObject("Socket.TCP")
   'SqueezeBoxSocket.DoTelnetEmulation = True
   'SqueezeBoxSocket.TelnetEmulation = "TTY"
   'SqueezeBoxSocket.Host = SDB.IniFile.StringValue("SqueezeBox","IP") & ":9090"
   'SqueezeBoxSocket.Open
'End Sub
'**************************************************************
Function SqueezeBoxMode
   On Error Resume Next
   SqueezeBoxMode = ""
   'SqueezeBoxSocket.SendLine "mode ?"
   'SqueezeBoxMode = SqueezeBoxSocket.GetLine
End Function
'**************************************************************
Sub Event_OnPlay
   Dim strRetVal, TrackPath
   
   TrackPath = CheckPath(SDB.Player.CurrentSong)
   If SDB.IniFile.BoolValue("Synology","Enabled") = True Then
      TrackPath = Replace(TrackPath,"\","/")
   End If
   If SDB.IniFile.BoolValue("NAS","Enabled") = True Then
      TrackPath = Replace(TrackPath,SDB.IniFile.StringValue("MediaMonkey","MF"),SDB.IniFile.StringValue("SqueezeBox","MF"))
   End If
   If ManualTrackChange = True Then
      slimRequest(formatCommand("""stop"""))
      slimRequest(formatCommand("""playlist"", ""play"", """ + perlEscape(TrackPath) + """"))
   Else
      slimRequest(formatCommand("""playlist"", ""add"", """ + perlEscape(TrackPath) + """"))
      ManualTrackChange = True
   End If
End Sub
'**************************************************************
Function SyncToggle( itm )
   Dim TrackPath, Mnu
   
   TrackPath = CheckPath(SDB.Player.CurrentSong)
   If SDB.IniFile.BoolValue("Synology","Enabled") = True Then
      TrackPath = Replace(TrackPath,"\","/")
   End If
   If SDB.IniFile.BoolValue("NAS","Enabled") = True Then
      TrackPath = Replace(TrackPath,SDB.IniFile.StringValue("MediaMonkey","MF"),SDB.IniFile.StringValue("SqueezeBox","MF"))
   End If
   If SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False Then
      SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = True
      Call registerEvents
      itm.IconIndex = SDB.RegisterIcon("Scripts\Auto\sbon.ico", 0)
      'slimRequest(formatCommand("""playlist"", ""play"", """ + perlEscape(TrackPath) + """"))
      slimRequest(formatCommand("""time"", """ + CStr(SDB.Player.PlaybackTime*0.001 + 1) + """"))      'added 1 second to try to make up for net and lookup lag
   Else
      Call unregisterEvents
      slimRequest(formatCommand("""stop"""))
      SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
      itm.IconIndex = SDB.RegisterIcon("Scripts\Auto\sboff.ico", 0)
   End If
End Function
'**************************************************************
Function CheckPath(SongValue)
   If Left(SongValue.Path,1) = "?" Then
      If SongValue.Cached Then
         CheckPath = SongValue.CachedPath
      Else
         CheckPath = SongValue.Path
      End If
   Else
      CheckPath = SongValue.Path
   End If
End Function
'**************************************************************
Sub Event_OnStop
   slimRequest(formatCommand("""stop"""))
End Sub
'**************************************************************
Sub Event_OnShutdown
   On Error Resume Next
   slimRequest(formatCommand("""stop"""))
End Sub
'**************************************************************
Sub Event_OnPause
   If SDB.Player.IsPaused Then
      slimRequest(formatCommand("""pause"""))
   Else
      slimRequest(formatCommand("""play"""))
   End If
End Sub
'**************************************************************
Sub Event_OnSeek
   Dim strRetVal, TrackPath
   
   strRetVal = SqueezeBoxMode
   TrackPath = CheckPath(SDB.Player.CurrentSong)
   If SDB.IniFile.BoolValue("Synology","Enabled") = True Then
      TrackPath = Replace(TrackPath,"\","/")
   End If
   If SDB.IniFile.BoolValue("NAS","Enabled") = True Then
      TrackPath = Replace(TrackPath,SDB.IniFile.StringValue("MediaMonkey","MF"),SDB.IniFile.StringValue("SqueezeBox","MF"))
   End If
   If InStr(1,strRetval,"mode stop") > 0 Then
      slimRequest(formatCommand("""playlist"", ""play"", """ + perlEscape(TrackPath) + """"))
   End If
   slimRequest(formatCommand("""time"", """ + CStr(SDB.Player.PlaybackTime*0.001) + """"))
End Sub
'**************************************************************
Function slimRequest(params)
   'slimRequest accepts pre-formatted parameter string, returns string of the response'
   'logme "  >> slimRequest: Begin with " + params
   Dim url, prog, objHTTP, str
   Dim cnt : cnt = 0
   
   url = "http://" + SDB.IniFile.StringValue("SqueezeBox","IP") + ":" + SDB.IniFile.StringValue("SqueezeBox","Port") + "/jsonrpc.js"
   'Dim prog : Set prog = SDB.Objects("LoadXMLBar")
   Set prog = SDB.Progress
   Set objHTTP = CreateObject("Microsoft.XMLHTTP")
   Call objHTTP.open("POST", url, True)
   objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
   objHTTP.setRequestHeader "X-Requested-With", "XMLHttpRequest"
   objHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1"
   objHTTP.send(params)
   
   While (objHTTP.readyState < 4) And (cnt < 300)
      Call SDB.Tools.Sleep(100)
      SDB.ProcessMessages
      cnt = cnt+1
      If prog.Terminate Then
         cnt = 300
      End If
   Wend
   If objHTTP.readyState < 4 Then
      Set slimRequest = Nothing
   Else
      str = objHTTP.responseText
      slimRequest = str
   End If
End Function
'*************************************************************
'This is is a JSON RPC call - We're directly calling functions in the Slim::Request module in Perl. See here:
'http://svn.slimdevices.com/repos/slim/7.5/trunk/server/Slim/Control/Request.pm
'the addDispatch section tells you how to use the commands and what the RPC module is looking for in terms of formatting
Function formatCommand(str1)
   Dim str2
   
   str2 = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("SqueezeBox","MAC") + """,[" + str1 + "]]}"
   formatCommand = str2
End Function
'*************************************************************
'borrowed from a teknojunky - if you want the popups add them to this and then just call logme
Sub logme(msg)
   Dim fso, logf
   On Error Resume Next
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set logf = fso.OpenTextFile(Script.ScriptPath&".log",ForAppending,True)
   logf.WriteLine Now() & ": " & msg
   Set fso = Nothing
   Set logf = Nothing
End Sub
'*************************************************************
'Perl is taking the JSON strings directly into variables - "\" is a special character in perl to escape the following string
'wherever we have a "\" we need it to be "\\" in anything that goes to Perl (ie: anything that goes to Squeezebox)
Function perlEscape(str1)
   str1 = Replace(str1, "\", "\\")
   perlEscape = str1
End Function
'*************************************************************
Sub registerEvents
   Call Script.RegisterEvent(SDB,"OnPlay","Event_OnPlay")
   Call Script.RegisterEvent(SDB,"OnPause","Event_OnPause")
   Call Script.RegisterEvent(SDB,"OnStop","Event_OnStop")
   Call Script.RegisterEvent(SDB,"OnSeek","Event_OnSeek")
End Sub
'*************************************************************
Sub unregisterEvents
   Script.UnregisterEvents SDB
End Sub
'*************************************************************
'These are what the full JSON strings look like that need to be sent to slimRequest()
'formatRequest() fills in the first part and all you have to do is pick the RPC commands from http://svn.slimdevices.com/repos/slim/7.5/trunk/server/Slim/Control/Request.pm

'Note: there are cleaner ways of doing this - but this is quick and dirty. It just means that you have to use a lot of """ and etc in vbscript.
'This entire script is much easier to write in jscript but I don't know jscript at all so, shrug.

'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["status","-",1,"tags:cgABbehldiqtyrSuoKLN"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["status","-",1,"tags:uB"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["playlist","index",28]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["pause"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",[""playlist"", ""play"", ""D:\\MP3\\filename.mp3""]]}


'You can do ANYTHING you can do from the web interface via this RPC engine because you are directly calling the methods in Perl
'so you could add whole playlists and etc see the docs. Sky's the limit.
MonkeySqueeze – Squeezing music into your life!
https://twitter.com/#!/MonkeySqueeze1
MonkeySqueeze Support: viewtopic.php?f=2&t=59515
MonkeySqueeze Development: viewtopic.php?f=19&t=59907
MediaMonkey user since 2005
Gingernut63
 
Posts: 188
Joined: Thu Jul 14, 2011 4:13 am

PreviousNext

Return to Addons developer forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron