Help - Search - Members - Calendar
Full Version: FooSQ proxy script for Squeezebox
Hydrogenaudio Forums > Hosted Forums > foobar2000 > 3rd Party Plugins - (fb2k)
marae
It's for using directly a Squeezebox with Foobar . Gapless . Enjoy

CODE

[font=Courier New];============================== Start of FooSQ AutoIt script ==================================

; Author Marae; May 2008 - FooSQ

; FooSQ grab infos from Foobar windows title with an AutoIT script, then send "cli" command to SqueezeCenter.
; It is not necessary to wait for any rescan inside SqueezeCenter.
; Just add a folder/playlist inside Foobar (no tags needed), then press play (gapless).

; The time needed with my settings for adding a song in Now Playing then bufferize it is 10 sec.
; If we guess the next song, and we enqueue it 10 sec. before the end of the current one, it's gapless.
; Then FooSQ determine normal transition (remaining time pass by 0) or skip.
; AMIP guess the next song

; This is a first release, so you may see some Autoit error messages or desynchro sometime.

; To install:
; 1.- Install autoit and compile this script( http://www.autoitscript.com/autoit3/downloads.shtml )
; 2.- Put %path%/%playback_time_remaining_seconds%/%ispaused%/ in Foobar pref. Display - Title Formating - Main windows title
; 3.- Install AMIP ( http://amip.tools-for.net/ds/dl.php?f=/files/amip_foobar_09.zip ), then restart Foobar.
;     in Foobar Pref, Tools, Amip, Enable Amip, enable File C:\nextsong.txt and put $next(%fn) in "Play" Field
; 4.- Start Foobar, play a song, verify you have "Full path file name/Remaining sec./?/" in windows title, and C:\nextsong.txt is the next song. Stop Foobar
; 5.- Start this compiled script

; Seekbar move, repeat song, click on a playing song, more then one squeezebox not implemented

; Cli ref : file:///C:/Program%20Files/SqueezeCenter/server/HTML/EN/html/docs/cli-api.html

; Tested with Autoit v3.2.10.0 - Foobar 0.9.4.4 - AMIP 2.63

;  - Freeware - ( Use / Modify at your own risk. No support: Sources provided )


; --------------------------------------- Code Start ---------------------------------------
; AMIP file
$m_amip = "C:\nextsong.txt"

;slimserver ip & port
$m_ip = "127.0.0.1"
$m_port = 9090

; Start The TCP Services
TCPStartUp()

;Attempt to connect to SC
$m_tcp = TCPConnect($m_ip,$m_port)

If @error Then
    MsgBox(0, "FooSQ", "SqueezeCenter not responding")
    Exit
EndIf

; Match windows title substring
Opt("WinTitleMatchMode", 2)

; Title somewhere in title bar
$m_foo = "foobar2000"

; length of title while foobar is stopped
$m_lts = 19

; Status variables:

;File name played
$m_f = ""
;Remaining time
$m_r = "0"
; Status: 0 -> stop; 1 -> playing; 2 -> paused
$m_s = "0"
; Is paused: ? -> playing; 1 -> paused
$m_p = "?"
; Transition: 0 -> normal (not skipped)
$m_t = ""
; Length of windows title
$m_l = "0"
; Next file name for gapless
$m_n = ""
; Next file name already enqueued -> 1
$m_ne = ""
; in foobar preference : 1 -> yes, put loop idle
$m_pref = ""

; New status variable after song transition
; new file name
$m_fn = ""
; windows title new lenght
$m_ln = "0"

; loop timer . reduce if shuffled songs start too early
$m_lt=229

; get foobar windows title
$m_title = WinGetTitle($m_foo, "")

If $m_title = "0" Then
    MsgBox(0, "FooSQ", "Please start Foobar")
    Exit
EndIf

; clear playing now
TCPSend($m_tcp,"playlist clear" & @CRLF)

While 1
    
    $m_title = WinGetTitle($m_foo, "")
    If StringRegExp ( $m_title, $m_foo ) <> 1 Then
    ; no foobar anymore ?
        Exit
    EndIf
    
    If StringRegExp ( $m_title, "Preferences" ) Then
    ; we are in foobar pref, put the loop idle
        if $m_pref = "" Then
            MsgBox(0, "FooSQ", "Staying in Foobar Preferences a while may desynchronize FooSQ. Do a Foobar Stop/Play when finished")
        Endif
        $m_pref = "1"
    Else
        $m_pref = ""
    EndIf
    
    If $m_pref = "" Then
        
        $m_ln = StringLen($m_title)
    
        if $m_ln <> $m_lts    Then
        ; find new infos after transition
            $a_tn = StringSplit($m_title, "/")
            $m_fn = $a_tn[1]
            $m_r = $a_tn[2]
            $m_p = $a_tn[3]
        EndIf
    
        Select
    ; go to stop and clear now playing
        Case $m_ln = $m_lts AND $m_s <> "0"
                $m_s = "0"
                TCPSend($m_tcp,"stop" & @CRLF & "playlist clear" & @CRLF)
                  
    ; from stop to start    
        Case $m_ln <> $m_lts AND $m_s = "0"
                $m_s = "1"
                $m_f = $m_fn
            ; SC needs / and %20 for space
                $m_sq = StringReplace(StringReplace($m_fn, "\", "/"), " ", "%20")
                TCPSend($m_tcp, "playlist play " & $m_sq & @CRLF)
                
    ; song change / pause while playing        
        Case $m_ln <> $m_lts AND $m_s = "1"
            ; goto pause
                if $m_p = "1" Then
                   $m_s = "2"
                   TCPSend($m_tcp,"pause 1" & @CRLF)
               Else
                ;
                    if $m_f <> $m_fn Then
                        $m_sq = StringReplace(StringReplace($m_fn, "\", "/"), " ", "%20")
                        if     $m_t = "0" Then
                            if $m_fn <> $m_n Then
                             ; normal transition, not next song
                              TCPSend($m_tcp,"playlist play " & $m_sq & @CRLF)
                            Endif  
                        Else
                        ; next song after skip, random button or click on another song
                            TCPSend($m_tcp,"playlist play " & $m_sq & @CRLF)
                        Endif
                        $m_t = ""
                        $m_ne = ""
                    Else
                        if $m_r = "11" OR $m_r = "10" Then
                        ; enqueue next song ( when remain 11 or 10 sec if title is late)
                            if $m_ne = "" Then
                                $m_amips = FileOpen($m_amip, 0)
                                If $m_amips = -1 Then
                                    MsgBox(0, "FooSQ", "AMIP next song file not found")
                                    Exit
                                EndIf
                                $m_n = FileReadLine($m_amip)
                                FileClose($m_amip)
                                $m_sq = StringReplace(StringReplace($m_n, "\", "/"), " ", "%20")
                                TCPSend($m_tcp,"playlist insert " & $m_sq & @CRLF)
                                $m_ne = "1"
                            Endif    
                        Endif    
                        if $m_r = "0" OR $m_r = "1" Then
                        ;remaining time pass by 0 (or 1 if title is late)
                           $m_t = "0"
                        Endif
                    Endif
                    $m_f = $m_fn    
                EndIf
    ; continue after pause    
        Case $m_ln <> $m_lts AND $m_s = "2"
                if $m_p = "?" Then
                    $m_s = "1"
                    TCPSend($m_tcp, "pause 0" & @CRLF)
                EndIf
        
        EndSelect
    Endif
    sleep($m_lt)
WEnd
Exit
; ============================================= End of script =====================================[/font]
Chipicui
Thanks a lot!
But... excuse my complete ignorance... I already (sometimes) use foobar with squeezebox just connecting to http://192.168....:port , so... what's different with this script?
Is it faster?... what are it's benefits compared to a normal connection?

Thanks smile.gif
marae
QUOTE(Chipicui @ May 20 2008, 06:18) *

Thanks a lot!
But... excuse my complete ignorance... I already (sometimes) use foobar with squeezebox just connecting to http://192.168....:port , so... what's different with this script?
Is it faster?... what are it's benefits compared to a normal connection?

Thanks smile.gif


You are talking about MP3 streaming. FooSQ is lossless with lossless files.
Flac are decoded to wav inside the SBox, APE, ALAC etc. in SCenter.
Chipicui
Oh...thanks!
My bad...
... you were talking about squeezebox while I was thinking about squeezecenter
Now I understand it... Thanks
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.