Lyric Timer 4.0 - Updated 03/08/2014

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Lyric Timer 4.0 - Updated 03/08/2014

Post by trixmoto »

This script reads the lyrics tag for the playing song and allows you to easily add basic timestamps. It highlights the currently playing line to make it easy to see progress so far and adjust times accordingly. Displays in a dockable panel which updates with the currently playing track. Loop feature included to ease perfecting timestamps. Is now a full editor with options to add, edit and delete the lyric lines as well. Lyrics are also imported from EvilLyrics automatically.

This is useful also if you which to display your lyrics in MM using my Inline Lyrics script.

As always, there is an installation package available on my website, and the code can be found below...

Code: Select all

'
' MediaMonkey Script
'
' NAME: LyricTimer 4.0
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 03/08/2014
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini 
'          Don't forget to remove comments (') and set the order appropriately
'
' Thanks to Begges for his EvilTagger script which helped with importing from EvilLyrics
'
' FIXES: Updated for MM4 with new installation package
'        Updated output to be HTML5 and moved to %temp%
'        Fixed loop option by switching off crossfade
'        Added option to auto-scroll down the page
'
' [LyricTimer]
' FileName=LyricTimer.vbs
' ProcName=LyricTimer
' Order=17
' DisplayName=Lyric Timer
' Description=Add timings to lyrics
' Language=VBScript
' ScriptType=0
'

Option Explicit
Public styleOn

Dim OddColour : OddColour = "#FFFFFF"		'white
Dim EvenColour : EvenColour = "#EFEFEF"		'silver
Dim TextColour : TextColour = "#000000"		'black
Dim HighlightColour : HighlightColour = "#FFFF77"	'yellow
Dim EvilLyrics : EvilLyrics = "C:\Program Files\EvilLyrics\lyrics\" 'leave blank if you don't want this feature
Dim RecheckSecs : RecheckSecs = 5 'number of seconds before rechecking EvilLyrics
Dim AutoScroll : AutoScroll = True 'scroll window so that current line stays in view

Sub LyricTimer
  Dim Form : Set Form = SDB.Objects("LyricTimer")
  If Form Is Nothing Then
    Set Form = SDB.UI.NewDockablePersistentPanel("LyricPanel") 
    If Form.IsNew Then
      Form.DockedTo = 2
      Form.Common.Width = 250
    End If
    Form.Caption = "Lyric Timer"
  
    Dim Head : Set Head = SDB.UI.NewPanel(Form)
    Head.Common.Align = 1
    Head.Common.Height = 25
    
    Dim Btn1 : Set Btn1 = SDB.UI.NewButton(Head)
    Btn1.Caption = "Revert back"
    Btn1.Common.Height = 25
    Btn1.Common.Width = 100
    Btn1.Common.Left = 0
    Btn1.UseScript = Script.ScriptPath
    Btn1.OnClickFunc = "BackClick"
  
    Dim Btn2 : Set Btn2 = SDB.UI.NewButton(Head)
    Btn2.Caption = "Save changes"
    Btn2.Common.Height = 25
    Btn2.Common.Width = 100
    Btn2.Common.Left = 100
    Btn2.UseScript = Script.ScriptPath
    Btn2.OnClickFunc = "SaveClick"
  
    Dim Btn3 : Set Btn3 = SDB.UI.NewButton(Head)
    Btn3.Caption = "Loop: No"
    Btn3.Common.ControlName = "Btn3"
    Btn3.Common.Height = 25
    Btn3.Common.Width = 100
    Btn3.Common.Left = 200
    Btn3.UseScript = Script.ScriptPath
    Btn3.OnClickFunc = "LoopClick"

    Dim WB : Set WB = SDB.UI.NewActiveX(Form, "Shell.Explorer") 
    WB.Common.Align = 5
    WB.Common.ControlName = "WB"
    WB.Interf.Navigate "about:"
    SDB.Objects("LyricWB") = WB.Interf
    SDB.Objects("LyricDoc") = WB.Interf.Document
  Else
    If Form.Common.Visible Then
      Form.Common.Visible = False
      Exit Sub
    Else
      Dim WB_Interf : Set WB_Interf = SDB.Objects("LyricWB")
      Call WB_Interf.Navigate("about:")
    End If
  End If

  Dim vars : Set vars = CreateObject("Scripting.Dictionary")
  vars.Item("classname") = "dark"
  vars.Item("curr") = 0
  vars.Item("isong") = -1  
  vars.Item("trax") = 0

  Form.Common.Visible = True
  Set SDB.Objects("LyricTimer") = Form
  Set SDB.Objects("LyricData") = Nothing
  Set SDB.Objects("LyricVars") = vars
  
  Dim Tmr : Set Tmr = SDB.CreateTimer(100)
  Call Script.RegisterEvent(Tmr,"OnTimer","Update")
End Sub 

Sub Update(Timer)
  'update track list
  Dim vars : Set vars = SDB.Objects("LyricVars")
  Dim song : Set song = SDB.Player.CurrentSong
  If song Is Nothing Then
    If Not (vars.Item("classname") = "nosong") Then
      vars.Item("classname") = "nosong"
      vars.Item("curr") = 0
      vars.Item("isong") = -1      
      vars.Item("trax") = 0      
      Set SDB.Objects("LyricData") = Nothing
      Set SDB.Objects("LyricVars") = vars
      Call writedocument()
    End If
  Else
    If Not (song.ID = Int(vars.Item("isong"))) Then
      vars.Item("classname") = "dark"
      vars.Item("curr") = 0      
      vars.Item("isong") = song.ID
      vars.Item("trax") = extractlyrics()
      If SDB.Player.isCrossfade Then
        SDB.Player.isCrossfade = False
        vars.Item("crossfade") = 1
      Else
        If Not (vars.Exists("crossfade")) Then
          vars.Item("crossfade") = 0
        End If
      End If      
      Set SDB.Objects("LyricVars") = vars
      Call writedocument()
    Else
      Dim Data : Set Data = SDB.Objects("LyricData")
      If Not (Data Is Nothing) Then
        If Not (Data.Item("rewrite") = "") Then
          If Data.Item("rewrite") = "insert" Then
            vars.Item("trax") = Int(vars.Item("trax"))+1
          Else
            vars.Item("trax") = Int(vars.Item("trax"))-1
          End If
          Set SDB.Objects("LyricVars") = vars
          Call writedocument()
          Data.Item("rewrite") = ""
          Set SDB.Objects("LyricData") = Data
        End If
      End If
    End If
  End If
  
  'update track highlight
  If Int(vars.Item("trax")) > 0 Then
    Dim doc : Set doc = SDB.Objects("LyricDoc")
    If Not (doc Is Nothing) Then
      Dim row : Set row = Nothing
      Dim newcurr : newcurr = getcurr()
      Dim curr : curr = Int(vars.Item("curr"))
      If newcurr = curr Then
        Set row = doc.getElementById("row"&curr)
        If Not (row Is Nothing) Then
          row.className = "highlight"
        End If  
      Else        
        If curr > 0 Then
          doc.getElementById("row"&curr).className = vars.Item("classname")
        End If
        Set row = doc.getElementById("row"&newcurr)
        If Not (row Is Nothing) Then
          vars.Item("classname") = row.className
          row.className = "highlight"
          vars.Item("curr") = newcurr
          Set SDB.Objects("LyricVars") = vars
        End If    
      End If
    End If
  End If
  
  'loop song
  Dim Form : Set Form = SDB.Objects("LyricTimer")
  If Not (Form Is Nothing) Then
    If Form.Common.Visible Then 
      If SDB.Player.CurrentSongLength > 0 Then
        Dim Btn : Set Btn = Form.Common.ChildControl("Btn3")
        If Btn.Caption = "Loop: Yes" Then   
          Dim diff : diff = SDB.Player.CurrentSong.StopTime - SDB.Player.PlaybackTime
          If diff < 5000 Then
            SDB.Player.PlaybackTime = SDB.Player.CurrentSong.StartTime
          End If
        End If
      End If
    Else 'stop when hidden
      Call Script.UnregisterAllEvents()
      If Int(vars.Item("crossfade")) = 1 Then
        SDB.Player.isCrossfade = True
      End If
    End If
  Else 
    Call Script.UnregisterAllEvents()
    If Int(vars.Item("crossfade")) = 1 Then
      SDB.Player.isCrossfade = True
    End If    
  End If
End Sub

Function getcurr()
  getcurr = 1
  Dim Data : Set Data = SDB.Objects("LyricData")
  Do While getcurr < 100
    Dim indx : indx = Data.Item("time"&(getcurr+1))
    If Not (indx = "") Then
      If SDB.Player.PlaybackTime >= CLng(indx) Then
        getcurr = getcurr+1
      Else
        Exit Do
      End If
    Else
      Exit Do
    End If
  Loop
End Function

Function settime(lng)
  Dim min,sec,hun,tint
  tint = lng\60000
  If tint < 10 Then 
    min = "0"&tint
  Else
    min = ""&tint
  End If 
  lng = lng - (tint*60000)
  tint = lng\1000
  If tint < 10 Then
    sec = "0"&tint
  Else
    sec = ""&tint
  End If
  lng = lng - (tint*1000)  
  tint = lng\10
  If tint < 10 Then
    hun = "0"&tint
  Else
    hun = ""&tint
  End If
  lng = lng - (tint*10)
  settime = "["&min&":"&sec&"."&hun&"]"
End Function

Function gettime(txt)
  Dim min,sec,hun,temp
  If Len(txt) = 8 Then
    temp = Mid(txt,1,2)
    If isNumeric(temp) Then min = Clng(temp)
    temp = Mid(txt,4,2)
    If isNumeric(temp) Then sec = Clng(temp)
    temp = Mid(txt,7,2)
    If isNumeric(temp) Then hun = Clng(temp)  
  End If
  gettime = min*60000 + sec*1000 + hun*10
End Function

Function simplify(txt)
  Dim a : a = InStr(txt,"<")
  If a = 0 Then
    simplify = txt
    Exit Function
  End If
  Dim b : b = InStr(txt,">")
  If b = 0 Then b = a
  Dim l : l = Len(txt)
  Dim c : c = Mid(txt,1,a-1)
  Dim d : d = Mid(txt,b+1,l-b)
  txt = c&d
  a = InStr(txt,"<")
  If a > 0 Then txt = simplify(txt)
  simplify = txt
End Function

Function MapXML(original) 
  Dim hold : hold = original
  hold = Replace(hold,"&","&") 
  hold = Replace(hold," ","&nbsp;")
  hold = Replace(hold,"<","<") 
  hold = Replace(hold,">",">") 
  Dim i : i = 1 
  While i<=Len(hold) 
    If (AscW(Mid(hold, i, 1))>127) Then 
      hold = Mid(hold, 1, i-1)+"&#"+CStr(AscW(Mid(hold, i, 1)))+";"+Mid(hold, i+1) 
    End If 
    i = i+1 
  Wend 
  MapXML = hold 
End Function 

Function Style() 
  styleOn = Not styleOn 
  If styleOn Then 
    Style = " class=""dark""" 
  Else 
    Style = "" 
  End If 
End Function 

Function extractlyrics()
  Dim Data : Set Data = CreateObject("Scripting.Dictionary")
  Dim song : Set song = SDB.Player.CurrentSong
  Dim lrc : lrc = song.Lyrics
  Dim trax : trax = 0
  
  'import from EvilLyrics
  If (lrc = "") And (EvilLyrics <> "") Then
    If Not (Right(EvilLyrics,1) = "\") Then
      EvilLyrics = EvilLyrics&"\"
    End If
    Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
    Dim cap : cap = UCase(Left(song.ArtistName,1))
    If InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",cap) = 0 Then
      cap = "_"
    End If
    Dim art : art = correctfilename(song.ArtistName)
    Dim tit : tit = correctfilename(song.Title)
    cap = EvilLyrics&cap&"\"&art&" - "&tit&".txt"
    If fso.FileExists(cap) Then
      Dim fil : Set fil = fso.OpenTextFile(cap, 1, False)
      Do While Not fil.AtEndOfStream
        If lrc = "" Then
          lrc = fil.ReadLine
        Else
          lrc = lrc&VbCrLf&fil.ReadLine
        End If
      Loop
    Else
      Dim Tmr : Set Tmr = SDB.CreateTimer(RecheckSecs*1000)
      Call Script.RegisterEvent(Tmr,"OnTimer","Recheck")
    End If
  End If
  
  'read lyrics
  If lrc <> "" Then 
    Dim ina : ina = split(lrc,VbCrLf)
    Dim inp : inp = 0
    Dim str,pos,cur,txt
  
    If Left(ina(inp),4) = "[ti:" Then
      str = Mid(ina(inp),5,Len(ina(inp))-5)
      inp = inp+1
    Else
      str = song.Title
    End If
    Data.Add "title", str
  
    If Left(ina(inp),4) = "[ar:" Then
      str = Mid(ina(inp),5,Len(ina(inp))-5)
      inp = inp+1
    Else
      str = song.ArtistName
    End If
    Data.Add "artist", str
  
    If Left(ina(inp),4) = "[au:" Then
      str = Mid(ina(inp),5,Len(ina(inp))-5)
      inp = inp+1
    Else
      str = song.Author
    End If
    Data.Add "author", str
  
    If Left(ina(inp),4) = "[al:" Then
      str = Mid(ina(inp),5,Len(ina(inp))-5)
      inp = inp+1
    Else
      str = song.AlbumName
    End If
    Data.Add "album", str

    If Left(ina(inp),4) = "[ve:" Then
      str = Mid(ina(inp),5,Len(ina(inp))-5)
      inp = inp+1
    Else
      str = "1.0"
    End If
    Data.Add "version", str
  
    For pos = inp To UBound(ina)
      trax = pos-inp+1
      If Len(ina(pos)) < 10 Then
        Data.Add "time"&trax, "0"
        Data.Add "line"&trax, ina(pos)
      Else
        If (Left(ina(pos),1) = "[") And (Mid(ina(pos),10,1) = "]") Then
          str = gettime(Mid(ina(pos),2,8))
          Data.Add "time"&trax, str
          str = Mid(ina(pos),11)
          Data.Add "line"&trax, str
        Else
          Data.Add "time"&trax, "0"
          Data.Add "line"&trax, ina(pos)
        End If
      End If
    Next
  End If
  
  Set SDB.Objects("LyricData") = Data
  extractlyrics = trax
End Function

Function correctfilename(str)
  Dim i,cap
  For i = 1 To Len(str)
    cap = Mid(str,i,1)
    If InStr("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. ",UCase(cap)) = 0 Then
      cap = "_"
    End If
    correctfilename = correctfilename&cap
  Next
End Function

Sub Recheck(Timer)
  Call Script.UnregisterEvents(Timer)
  Dim vars : Set vars = SDB.Objects("LyricVars")
  vars.Item("isong") = -1
  Set SDB.Objects("LyricVars") = vars
End Sub

Sub writedocument()
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim loc : loc = SDB.TemporaryFolder&"LyricTimer.htm"
  Dim doc : Set doc = fso.CreateTextFile(loc,True)
  Dim Data : Set Data = SDB.Objects("LyricData")
  Dim vars : Set vars = SDB.Objects("LyricVars")
  Dim trax : trax = Int(vars.Item("trax"))
  Dim wb : Set wb = SDB.Objects("LyricWB")
  Call wb.Navigate("about:")
  styleOn = False        
  doc.WriteLine "<!doctype html>" 
  doc.WriteLine "<html>" 
  doc.WriteLine "  <head>"  
  doc.WriteLine "    <title>"&SDB.Localize("Lyric Timer")&"</title>" 
  doc.WriteLine "    <style type=""text/css"">" 
  doc.WriteLine "      body{font-family:'Verdana',sans-serif; background-color:"&OddColour&"; font-size:9pt; color:"&TextColour&";}" 
  doc.WriteLine "      p{font-family:'Verdana',sans-serif; font-size:8pt; color:"&TextColour&";}" 
  doc.WriteLine "      th{font-family:'Verdana',sans-serif; font-size:9pt; font-weight:bold; color:"&TextColour&"; border-color:"&TextColour&"; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:3px;}" 
  doc.WriteLine "      td{font-family:'Verdana',sans-serif; font-size:8pt; color:"&TextColour&"; border-color:"&TextColour&"; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:1px;}" 
  doc.WriteLine "      tr.highlight{background-color:"&HighlightColour&"}" 
  doc.WriteLine "      tr.dark{background-color:"&EvenColour&"}" 
  doc.WriteLine "      tr.aleft th{text-align:left}" 
  doc.WriteLine "    </style>"   
  doc.WriteLine "    <script type=""text/javascript"">"  
  If AutoScroll Then
    doc.WriteLine "      function scrollpage() {"
    doc.WriteLine "        var col = document.getElementsByClassName(""highlight"");"
    doc.WriteLine "        if(col.length==1) {"
    doc.WriteLine "          var el = col[0];"
    doc.WriteLine "          var topOfPage = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;"
    doc.WriteLine "          var heightOfPage = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;"
    doc.WriteLine "          var elY = 0;"
    doc.WriteLine "          for(var p=el; p&&p.tagName!='BODY'; p=p.offsetParent) {"
    doc.WriteLine "            elY += p.offsetTop;"
    doc.WriteLine "          }"
    doc.WriteLine "          var elH = el.offsetHeight;"
    doc.WriteLine "          if ((topOfPage + heightOfPage) < (elY + elH)) {"
    doc.WriteLine "            el.scrollIntoView(false);"
    doc.WriteLine "          }"
    doc.WriteLine "          else if (elY < topOfPage) {"
    doc.WriteLine "            el.scrollIntoView(true);"
    doc.WriteLine "          }"
    doc.WriteLine "        }"
    doc.WriteLine "        setTimeout(""scrollpage();"",1000);"
    doc.WriteLine "      }"
    doc.WriteLine "      setTimeout(""scrollpage();"",1000);"
  End If
  If (trax < 1) And (EvilLyrics <> "") Then
    doc.WriteLine "      var cursec = "&RecheckSecs&";"
    doc.WriteLine "      function countdown() {"
    doc.WriteLine "        cursec--;"
    doc.WriteLine "        document.getElementById(""secs"").innerHTML = cursec;"    
    doc.WriteLine "        if ( cursec > 0 ) {"
    doc.WriteLine "          setTimeout(""countdown();"",1000);"
    doc.WriteLine "        }"    
    doc.WriteLine "      }"
    doc.WriteLine "      setTimeout(""countdown();"",1000);"
  End If          
  doc.WriteLine "    </script>"  
  doc.WriteLine "    <script type=""text/vbscript"">"
  doc.WriteLine "      Dim SDB : Set SDB = CreateObject(""SongsDB.SDBApplication"")"  
  doc.WriteLIne "      Dim trax : trax = "&trax
  doc.WriteLine "      Function gotopos(i)"  
  doc.WriteLine "        Dim Data : Set Data = SDB.Objects(""LyricData"")"
  doc.WriteLine "        Data.Item(""time""&i) = SDB.Player.PlaybackTime"
  doc.WriteLine "        document.getElementById(""span""&i).innerHTML = settime(Data.Item(""time""&i))"
  doc.WriteLine "        SDB.Objects(""LyricsData"") = Data"
  doc.WriteLine "      End Function"
  doc.WriteLine "      Function settime(lng)"
  doc.WriteLine "        Dim min,sec,hun,tint"
  doc.WriteLine "        tint = lng\60000"
  doc.WriteLine "        If tint < 10 Then "
  doc.WriteLine "          min = ""0""&tint"
  doc.WriteLine "        Else"
  doc.WriteLine "          min = """"&tint"
  doc.WriteLine "        End If "
  doc.WriteLine "        lng = lng - (tint*60000)"
  doc.WriteLine "        tint = lng\1000"
  doc.WriteLine "        If tint < 10 Then"
  doc.WriteLine "          sec = ""0""&tint"
  doc.WriteLine "        Else"
  doc.WriteLine "          sec = """"&tint"
  doc.WriteLine "        End If"
  doc.WriteLine "        lng = lng - (tint*1000)"
  doc.WriteLine "        tint = lng\10"
  doc.WriteLine "        If tint < 10 Then"
  doc.WriteLine "          hun = ""0""&tint"
  doc.WriteLine "        Else"
  doc.WriteLine "          hun = """"&tint"
  doc.WriteLine "        End If"
  doc.WriteLine "        lng = lng - (tint*10)"
  doc.WriteLine "        settime = ""[""&min&"":""&sec&"".""&hun&""]"""
  doc.WriteLine "      End Function"
  doc.WriteLine "      Function addline(i)"  
  doc.WriteLine "        Dim Data : Set Data = SDB.Objects(""LyricData"")"
  doc.WriteLine "        For j = trax To i+1 Step -1"
  doc.WriteLine "          Data.Item(""time""&(j+1)) = Data.Item(""time""&j)"
  doc.WriteLine "          Data.Item(""line""&(j+1)) = Data.Item(""line""&j)"
  doc.WriteLine "        Next"
  doc.WriteLine "        Data.Item(""time""&(i+1)) = 0"
  doc.WriteLine "        Data.Item(""line""&(i+1)) = """""
  doc.WriteLine "        Data.Item(""rewrite"") = ""insert"""
  doc.WriteLine "        SDB.Objects(""LyricsData"") = Data"
  doc.WriteLine "      End Function"
  doc.WriteLine "      Function editline(i)"  
  doc.WriteLine "        Dim Data : Set Data = SDB.Objects(""LyricData"")"
  doc.WriteLine "        Dim str : str = InputBox(""Line:"",""Lyric Timer"",Data.Item(""line""&i))"
  doc.WriteLine "        Data.Item(""line""&i) = str"
  doc.WriteLine "        document.getElementById(""line""&i).innerHTML = simplify(str)"
  doc.WriteLine "        SDB.Objects(""LyricsData"") = Data"
  doc.WriteLine "      End Function"  
  doc.WriteLine "      Function deleteline(i)"  
  doc.WriteLine "        Dim Data : Set Data = SDB.Objects(""LyricData"")"
  doc.WriteLine "        For j = i To trax-1"
  doc.WriteLine "          Data.Item(""time""&j) = Data.Item(""time""&(j+1))"
  doc.WriteLine "          Data.Item(""line""&j) = Data.Item(""line""&(j+1))"
  doc.WriteLine "        Next"
  doc.WriteLine "        Data.Item(""time""&trax) = """""
  doc.WriteLine "        Data.Item(""line""&trax) = """""
  doc.WriteLine "        Data.Item(""rewrite"") = ""delete"""
  doc.WriteLine "        SDB.Objects(""LyricsData"") = Data"
  doc.WriteLine "      End Function"  
  doc.WriteLine "      Function simplify(txt)"
  doc.WriteLine "        Dim a : a = InStr(txt,""<"")"
  doc.WriteLine "        If a = 0 Then"
  doc.WriteLine "          simplify = txt"
  doc.WriteLine "          Exit Function"
  doc.WriteLine "        End If"
  doc.WriteLine "        Dim b : b = InStr(txt,"">"")"
  doc.WriteLine "        If b = 0 Then b = a"
  doc.WriteLine "        Dim l : l = Len(txt)"
  doc.WriteLine "        Dim c : c = Mid(txt,1,a-1)"
  doc.WriteLine "        Dim d : d = Mid(txt,b+1,l-b)"
  doc.WriteLine "        txt = c&d"
  doc.WriteLine "        a = InStr(txt,""<"")"
  doc.WriteLine "        If a > 0 Then txt = simplify(txt)"
  doc.WriteLine "        simplify = txt"
  doc.WriteLine "      End Function"
  doc.WriteLine "    </script>"
  doc.WriteLine "  </head>"   
  doc.WriteLine "  <body>"  
  doc.WriteLine "    <table border=""0"" cellspacing=""0"" cellpadding=""4"" width=""100%"">"  
  doc.WriteLine "      <tr class=""aleft"">" 
  doc.WriteLine "        <th>&nbsp;</th>" 
  doc.WriteLine "        <th>"&SDB.Localize("Timestamp")&"</th>" 
  doc.WriteLine "        <th>"&SDB.Localize("Line")&"</th>"  
  doc.WriteLine "        <th><a href=""vbscript:addline(0)"">Add first</a></th>"
  doc.WriteLine "      </tr>"  
  If trax > 0 Then  
    Dim i,line
    For i = 1 To trax 
      line = simplify(Data.Item("line"&i))
      If line = "" Then line = " "
      doc.WriteLine "      <tr id=""row"&i&""""&Style()&">"
      doc.WriteLine "        <td nowrap><a href=""vbscript:gotopos("&i&")"">Line "&i&"</a></td>"
      doc.WriteLine "        <td nowrap><span id=""span"&i&""">"&MapXML(settime(Data.Item("time"&i)))&"</span></td>"
      doc.WriteLine "        <td><span id=""line"&i&""">"&MapXML(line)&"</span></td>"            
      doc.WriteLine "        <td nowrap><a href=""vbscript:addline("&i&")"">Add</a> <a href=""vbscript:editline("&i&")"">Edit</a> <a href=""vbscript:deleteline("&i&")"">Del</a></td>" 
      doc.WriteLine "      </tr>" 
    Next  
  Else
    doc.WriteLine "      <tr id=""row1"""&Style()&">"
    doc.WriteLine "        <th colspan=""4"">There are no lyrics available for this song.</th>"  
    doc.WriteLine "      </tr>"
    If Not (EvilLyrics = "") Then
      doc.WriteLine "      <tr id=""row2"""&Style()&">"
      doc.WriteLine "        <td colspan=""4""><p align=""center"">Rechecking EvilLyrics in <span id=""secs"">"&RecheckSecs&"</span> seconds.</p></td>"
      doc.WriteLine "      </tr>"    
    End If
  End If
  doc.WriteLine "    </table>"
  doc.WriteLine "  </body>" 
  doc.WriteLine "</html>" 
  Call doc.Close
  Call wb.Navigate(loc)
End Sub

Sub BackClick (ClickedBtn)
  Dim res : res = SDB.MessageBox("Are you sure you wish to undo your changes?",mtConfirmation,Array(mbOk,MbCancel))
  If res = 1 Then
    Dim vars : Set vars = SDB.Objects("LyricVars")
    vars.Item("isong") = -1
    Set SDB.Objects("LyricVars") = vars
  End If
End Sub

Sub SaveClick (ClickedBtn)
  Dim res : res = SDB.MessageBox("Are you sure you wish to save your changes?",mtConfirmation,Array(mbOk,mbCancel))
  If res = 1 Then
    Dim Data : Set Data = SDB.Objects("LyricData")
    Dim str : str = ""
    Dim pos : pos = 1
  
    If Data.Item("title") <> "" Then 
      str = str&"[ti:"&Data.Item("title")&"]"&VbCrLf
    End If    
    If Data.Item("artist") <> "" Then 
      str = str&"[ar:"&Data.Item("artist")&"]"&VbCrLf
    End If    
    If Data.Item("author") <> "" Then 
      str = str&"[au:"&Data.Item("author")&"]"&VbCrLf
    End If    
    If Data.Item("album") <> "" Then 
      str = str&"[al:"&Data.Item("album")&"]"&VbCrLf
    End If
    If Data.Item("version") <> "" Then 
      str = str&"[ve:"&Data.Item("version")&"]"&VbCrLf
    End If
    
    Do While Not (Data.Item("time"&pos) = "")
      Dim lng : lng = Clng(Data.Item("time"&pos))
      If Right(str,2) <> VbCrLf Then
        str = str&VbCrLf
      End If
      str = str&settime(lng)
      str = str&Data.Item("line"&pos)
      pos = pos+1
    Loop
    
    Dim song : Set song = SDB.Player.CurrentSong
    song.Lyrics = str
    Call song.UpdateDB
  End If
End Sub

Sub LoopClick (ClickedBtn)
  If ClickedBtn.Caption = "Loop: Yes" Then
    ClickedBtn.Caption = "Loop: No"
  Else
    ClickedBtn.Caption = "Loop: Yes"
  End If
End Sub

Sub out(txt)
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim logf : Set logf = fso.OpenTextFile(SDB.TemporaryFolder&"LyricTimer.log",8,True)
  Call logf.WriteLine(txt)
  Call logf.Close
End Sub

Sub OnInstall
  Dim inip : inip = SDB.ScriptsPath&"Scripts.ini"
  Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
  If Not (inif Is Nothing) Then
    inif.StringValue("LyricTimer","Filename") = "LyricTimer.vbs"
    inif.StringValue("LyricTimer","Procname") = "LyricTimer"
    inif.StringValue("LyricTimer","Order") = "17"
    inif.StringValue("LyricTimer","DisplayName") = "Lyric Timer"
    inif.StringValue("LyricTimer","Description") = "Add timings to lyrics"
    inif.StringValue("LyricTimer","Language") = "VBScript"
    inif.StringValue("LyricTimer","ScriptType") = "0"
    SDB.RefreshScriptItems
  End If
End Sub
Last edited by trixmoto on Sun Dec 02, 2007 6:22 pm, edited 2 times in total.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

LyricTimer.vbs

Code: Select all

NEW CODE BELOW
Last edited by trixmoto on Tue Mar 07, 2006 11:55 am, edited 1 time in total.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

LyricTimer2.vbs

Code: Select all

NEW CODE BELOW
Last edited by trixmoto on Tue Mar 07, 2006 11:55 am, edited 1 time in total.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Post by psyXonova »

Cool, well done mate....
:lol:
Wallstreetwalker-unlogged

lyrics

Post by Wallstreetwalker-unlogged »

hey trix,

i got the installer from your beatiful new site :lol:
but i get an error

on starting (translated from dutch) i get
rule 17
sign 5
error: activeX- 'part' can't make object
-SongsDB.SDBApplication
code 0
url about:blank

i press enter and i get the GUI but when clicking on line 1, line 2 or so i get
line 20
sign 7
error: object required 'SDB'
code 0
url about:blank
:-?


any suggestions ?, also i can't find an installer for your inline lyrics on the website :o , but i'll search better later :roll:

thanks !
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

This is a security issue. Because the script is connecting directly to MM you need to have a few security settings relaxed. In Internet Explorer, for your local settings you need to enable "Initialise and script ActiveX controls not marked as safe". Or possibly your antivirus-type software (ie. Norton) is blocking the action.

InlineLyrics is under "Scripts, On Play" on my website.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Guest

Post by Guest »

Hello,

I'm trying this out for the first time as I have a few text lyrics for tracks. The hope is to then try out your Inline lyrics script, as it's exactly what I'd prefer to do, in MM, as well.

But I'm having a few problems at the first hurdle.

Like the previous poster, I was getting the security issue. Enabling in the Local zone, still had the problem, though.

So I (briefly) enabled the settings in the Internet zone. Which worked as far as the initial running of the script went. But when I clicked on the 'getpos#' link, the following error was returned:

Line: 20
Char: 7
Error: Object required: 'data'
Code: 0
URL: about:blank

Any ideas?

Can I also check with you on usage - presumably I click on the links to mark the timing of each line.

Got to get that far first, though.

Thanks, Trixmoto.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

Yes, when you click on the link it will set that line's timestamp to be the current time.

I don't know why the data object could not be found. My initial thought would be security again as it is stored in MM so if the script is being refused access then it would not be able to find it.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Guest

Post by Guest »

I have line 20 in LyricTimer2.vbs as:

i = SDB.Player.CurrentSong.ID

It strikes me that the script isn't seeing the player and/or cannot connect to the player's counter. So the counter variables aren't running in the script for me - witnessed by the fact that the individual time counters on each line always show as [00:00.00]

I don't think it's a security issue. I've enabled everything I can, as a test, but the 'data' error persists.

I'm pre-supposing that the counters on each line should be visibly ticking over until I stop it with the link - and then the script loops to the next count etc.

Is there anything I can do? Or am I just unlucky? :(

Btw Thanks for replying.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

When you are clicking on a link on the form you are running a vbscript function within the webpage being displayed. You need to right click hit "view source" and check out that line 20.

It appears that this is happening for me too, although it hasn't before. Presumably this is due to something that has changed with the beta release. Can a developer comment?
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Guest

Post by Guest »

Trix,

I'm no expert on these things, but I'll offer as much support as I can.

When I viewed the source in the browser form, line 20 showed as:

data.Item("time"&i) = SDB.Player.PlaybackTime

NB Indent included.

Does that help? I have the whole output saved to a text file, if you'd like it posted.

One other bit of info:

When I close MM (after closing your script), I get the following COM Server Warning:

"There are still active COM objects in this application. One or more clients may have references to these objects, so manually closing this application may cause those client application(s) to fail."

I don't know whether that's relevant.

I also have a query as to why I have to enable script execution with ActiveX for the Internet zone (which suggests the browser element is operating as an external URL), rather than the Local zone which would be safer.

Any comments highly appreciated.
Guest

Post by Guest »

Sorry, but the indent disappeared when I submitted the post!
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

The actual source is not really relevant. The problem is that the "data" object is not being properly extracted from MM. Either that or it's not being put there in the first place. I have installed an old version of MM and this script works, however on the latest beta it doesn't. It is obviously something that the developers have changed (probably improved!) to the ActiveX component. I will fix this soon and post an update.

I don't have any control over how the web component functions so I cannot change it's security zone. All I can do is use what's available to me! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Guest

Post by Guest »

Appreciated, Trix. :)

Maybe something's been uncovered here?

For Info: I'm currently using 2.5.2 RC1 (though I haven't had a lot of time recently to give it a good workout).

Looking forward to the update.

Thanks again.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

All new and improved (version 2.0)! 8)

This is now a dockable panel which will refresh with the track that is playing. There is a loop function, save and revert. Timestamp error handling has been vastly improved too!

N.B. Installer on my website already! :)

:o NEW CODE BELOW :o
Last edited by trixmoto on Mon Mar 20, 2006 11:32 am, edited 1 time in total.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Post Reply