NowPlaying.vbs / NowPlayingConf.vbs (Updated 01/23/2006)

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: NowPlaying.vbs / NowPlayingConf.vbs (Updated 01/23/2006)

Re: NowPlaying.vbs / NowPlayingConf.vbs (Updated 01/23/2006)

by HELOX » Thu Jan 06, 2011 10:00 am

Sorry for that, I was hopeing for more usefull replys this way :S

Re: NowPlaying.vbs / NowPlayingConf.vbs (Updated 01/23/2006)

by Vyper » Thu Jan 06, 2011 7:25 am

HELOX wrote:People reading this could find this interessting or might be able to help Here
You need to stop replying to several threads with the same response. :-?

Re: NowPlaying.vbs / NowPlayingConf.vbs (Updated 01/23/2006)

by HELOX » Thu Jan 06, 2011 5:38 am

People reading this could find this interessting or might be able to help Here

Works with MM3

by popper » Mon Nov 05, 2007 4:24 pm

I can confirm that this script is working with MM3. Or at least the "manual part" of it, i am not using the graphical config part of it. No special actions are necessary to make it work.

The 'OK' button is not visable

by kristoffer_1 » Wed May 24, 2006 7:30 am

..and no textfile is written..

by margu » Mon Jan 23, 2006 1:03 pm

NowPlaying.vbs (V. 1.4.0)
NowPlaying2.vbs (V. 1.4.0)
NowPlayingConf.vbs (V. 0.4.2)


Added: Show AlbumArtist in line 2 if it isn't the TrackArtist, except if AlbumArtist is Various, Various Artists or VA
Fixed: If Album shouldn't be shown there is a blank line instead


NowPlaying.vbs

Code: Select all

'
' MediaMonkey Script
'
' NAME: NowPlaying 1.4.0
'       NowPlaying.vbs + NowPlaying2.vbs
'
' AUTHOR: margu
' DATE : (01/23/2006 18:28)
'
' DESCRIPTION: This script will collect the Title and Artist information from
'              current playing track and save them to a textfile in MM "My Music"
'              defined folder.
'              Beside the above info it will also get the rating of the song,
'              the Album Name, the status of MM-player (paused or stopped) and
'              the MM-version and write it to this file either.
'              Another additional function is the possibility to get all this
'              information copied to clipboard for further use.
'
'              For detailed features take also a look at the history.
'
'              I don't wanted to use AMIP because it is too overwhelmed for my
'              needs and I only need this textfile to integrate in the
'              signature of my mail program.
'              For now the textfile won't be deleted after MM is closed, because
'              I don't know how to get "onClose" from MM.
'
' HISTORY:
'         1.4.0 (01/23/2006 18:28)
'            Added: Show AlbumArtist in line 2 if it isn't the TrackArtist, except
'                   if AlbumArtist is Various, Various Artists or VA
'            Fixed: If Album shouldn't be shown there is a blank line instead
'
'         1.3.0 (01/22/2006 15:15)
'            Added: Line limiter. User can choose how long the lines 1 and 2
'                   should be.
'
'         1.2.0 (01/19/2006 17:00)
'            Added: Function to copy all information to clipboard
'                   (I got this idea and parts from Peke's script CopyInfoExt.vbs)
'
'         1.1.3 (12/22/2005 17:23)
'            Fixed: If showPlayStatus is disabled PlayerInfo won't be shown
'
'         1.1.2 (12/19/2005 11:41)
'            Fixed: decimal point isn't shown correct on foreign languages
'            Added: signature cutter (-- ) on line0 for users who need this.
'                   Can be enabled/disabled by user.
'
'         1.1.1 beta (12/16/2005 11:05)
'            Some CleanUp and Optimizing and some reformatting of routines
'            Fixed (hopefully): Script Host error in NowPlaying2.vbs "Access denied"
'                   (german: "Erlaubnis verweigert"): Comes up at song change
'            Fixed: 3rd line isn't written if showRating is set False
'
'         1.1.0 beta (12/15/2005 23:41)
'            Added: User define variable to enable/disable filename for output
'            Added: Output of Album Name to Textfile
'            Added: User define variable to enable/disable Album Name for output
'            Added: User define variable to enable/disable file update
'
'         1.0.0 (Released 12/13/2005)
'
' EXAMPLE OUTPUT (if all things should be shown):
'        For a playing song including signature cutter:
'           --
'           listening: Blank & Jones - Breezin
'               Album: Relax (Limited Edition)
'           my rating: 3 of 5 stars / MediaPlayer: MediaMonkey 2.5.1
'        For a playing song w/o cutter:
'           listening: Blank & Jones - Breezin
'               Album: Relax (Limited Edition)
'           my rating: 3 of 5 stars / MediaPlayer: MediaMonkey 2.5.1
'        For a paused song w/o cutter:
'           listening: Blank & Jones - Breezin
'               Album: Relax (Limited Edition)
'           my rating: 3 of 5 stars / MediaPlayer: MediaMonkey 2.5.1 (paused)
'        For a stopped song w/o cutter:
'           listening: Blank & Jones - Breezin
'               Album: Relax (Limited Edition)
'           my rating: 3 of 5 stars / MediaPlayer: MediaMonkey 2.5.1 (stopped)
'
' INSTALL: Copy both scripts NowPlaying.vbs and NowPlaying2.vbs to MM Scripts
'          directory and change the below settings as you need them.
'          Afterwards add the following lines to Scripts.ini
'          Don't forget to remove comments (') and set the order appropriately
'          Needs file 'NowPlaying2.vbs' to be in '{MM}\Scripts\'
'
'
'[NowPlaying]
'FileName=NowPlaying.vbs
'ProcName=NowPlaying
'Order=22
'DisplayName=&NowPlaying
'Description=Save current info about playing song in a textfile
'Language=VBScript
'ScriptType=2
'
'======================================================================

Option Explicit

Dim oFSO, LoopScript, showRating, showPlayerInfo, showPlayStatus, WShell, command, res
Dim filePath, fileName, showAlbumName, runLoop, updateFile, showLineZero, copyToClipboard
Dim updateClipboard, maxLineLenght

'=============================================================
'    You can change the following settings for your needs
'=============================================================
'
' Here you can define if Rating is shown or not
' True = shown; False = disabled
showRating = True

' Here you can define if PlayerInfo is shown or not
' True = shown; False = disabled
showPlayerInfo = True

' Here you can define if PlayStatus is shown or not
' True = shown; False = disabled
showPlayStatus = True

' Here you can define if the Album Name is shown or not
' True = shown; False = disabled
showAlbumName = True

' If you want the file updated only on song change set
' "runLoop" to False otherwise set it to True and the file
' will be updated continuous (you can set the interval below).
runLoop = True

' Here you can set how often the player status should be checked
' and the file be updated. Value is set in seconds.
updateFile = 20

' Here you can define the name of the textfile. It will be stored
' in MM defined "My Music" (german: "Eigene Musik") folder
fileName = "NowPlaying.txt"

' Here you can choose if the line0 (-- ) will be inserted as signature cutter
' True = shown; False = disabled
showLineZero = False

' Here you can choose if the line lenght of line 1 + 2 should be limited.
' This is, because for correct formatting each line don't should be longer
' than 72 chars. I'll use this parameter only for line 1 and line 2.
' I think these lines are the only ones that can be more than 72 chars ;-)
' For unlimited lenght set it to 0 (zero)
maxLineLenght = 0

' Should the clipboard be updatd every time the loop is run?
' If you want this, then set it to True otherwise to False
' (If set to False it only will copy to clipboard on song start)
updateClipboard = False

' If you want to have song info "Artist - Title" copied to clipboard
' set this to "True". If you don't want set it to "False"
copyToClipboard = False

'=============================================================
'            End of editing
'=============================================================
LoopScript = SDB.ApplicationPath&"Scripts\NowPlaying2.vbs"
Set oFSO = CreateObject("Scripting.FileSystemObject")

Sub NowPlaying

	If not oFSO.FileExists(LoopScript) Then
		res = SDB.MessageBox("File '"&LoopScript&"' cannot be found.", mtError, Array(mbOk))
	Else
		Set WShell = CreateObject("WScript.Shell")
		command = "wscript " & Chr(34)&LoopScript&Chr(34) & " " & showRating & " " & showPlayerInfo & " " & showPlayStatus & " " & showAlbumName & " " & Chr(34)&fileName&Chr(34) & " " & runLoop & " " & updateFile & " " & showLineZero & " " & maxLineLenght & " " & updateClipboard & " " & copyToClipboard
		res = WShell.Run(command, 8, 0)
	End If

End Sub
NowPlaying2.vbs

Code: Select all

'
' MediaMonkey Script
'
' NAME: NowPlaying 1.4.0 helper script
'       NowPlaying2.vbs
'


Option Explicit

Dim SDB, oFSO, oOutput, oTrack, oPlayer, oVersion, oAlbum, Args, Progress
Dim oCSI, TrackIdx, isPause, isPlay, Status, Rat, Rating, x, PlayerInfo
Dim showRating, showPlayerInfo, showPlayStatus, showAlbumName, div, fileName
Dim filePath, runLoop, updateFile, line1, line2, line2a, line3, line0, showLineZero
Dim copyToClipboard, updateClipboard, maxLineLenght

' Set objects and variables
Set SDB = CreateObject("SongsDB.SDBApplication")
Set Args = WScript.Arguments
oCSI = SDB.Player.CurrentSong.ID
div = ""
showRating = CBool(Args(0))
showPlayerInfo = CBool(Args(1))
showPlayStatus = CBool(Args(2))
showAlbumName = CBool(Args(3))
fileName = Args(4)
runLoop = CBool(Args(5))
updateFile = Args(6)*1000
showLineZero = CBool(Args(7))
copyToClipboard = CBool(Args(10))
updateClipboard = CBool(Args(9))
maxLineLenght = Args(8)
filePath = SDB.MyMusicPath
x = 1

' start loop for current song
Do while x = 1
        ' set objects and variables needed for current song
	Set oFSO = CreateObject("Scripting.FileSystemObject")
	Set oPlayer = SDB.Player
	Set oTrack = oPlayer.CurrentSong
	Set oAlbum = oTrack.Album
	TrackIdx = oTrack.ID
	isPause = oPlayer.isPaused
	isPlay = oPlayer.isPlaying

        ' if song has changed exit this loop/script because the
        ' main script will be restarted by MM
	If oCSI <> TrackIdx Then
		Exit Do
	End If

	'========================================
	' check some states and predefine output
	'========================================
	' if Rating should be shown
	if showRating Then
		Rat = CSng(oTrack.Rating/20)
		If Rat < 0 Then
			Rating = "my rating: not rated yet"
		Else
			Rating = "my rating: " & Rat & " of 5 stars"
		End If
	End If

	' if Player Info should be shown
	If showPlayerInfo Then
		PlayerInfo = "MediaPlayer: MediaMonkey " & SDB.VersionString
	End If

	' we need status of current song
	If isPlay = False Then
		Status = " (stopped)"
		x = 0
		runLoop = False
	ElseIf isPause Then
		Status = " (paused)"
	Else
		Status = ""
	End If

	' the divider is needed if rating and player info should be shown
	If showRating And showPlayerInfo Then
		div = " / "
	ElseIf Not showRating Then
		div = ""
	End If

	'========================================
	' now we collect the wanted lines
	'========================================

	' if for some reason needed we use line0 to cut the signature
	line0 = "-- "

	' now the first line with info about Artist and Track
	line1 = "listening: " & oTrack.ArtistName & " - " & oTrack.Title

	' if Album Name should be shown ...
	If showAlbumName Then
		' ... and isn't empty write the 2nd line
		If Not oTrack.AlbumName = "" Then
			line2 = "    Album: " & oTrack.AlbumName
		Else
			line2 = "    Album: unknown"
		End If

		If Not oTrack.ArtistName = oTrack.AlbumArtistName Then
			If Not (oTrack.AlbumArtistName = "Various Artists" Or _
				oTrack.AlbumArtistName = "VA" Or _
				oTrack.AlbumArtistName = "Various") Then
				line2a = "(" & oTrack.AlbumArtistName & ")"
			End If
		Else
			line2a = ""
		End If

		If maxLineLenght Then
			line2 =  Left(line2, maxLineLenght-(Len(line2a)+1)) & " " & line2a
		Else
			line2 =  line2 & " " & line2a
		End If
	End If

	' and now line 3 if you wanted so
	' we have to put PlayStatus from 3rd to 1st line if line 3 isn't needed
	If Not showRating And Not showPlayerInfo Then
		If maxLineLenght Then
			line1 =  Left(line1, maxLineLenght-(Len(Status)+1)) & " " & Status
		Else
			line1 =  line1 & " " & Status
		End If
	Else
		If maxLineLenght Then
			line1 =  Left(line1, maxLineLenght)
		End If
	End If

	' If all should be shown then get all
	If showRating And showPlayerInfo And showPlayStatus Then
		line3 = Rating & div &  PlayerInfo & Status
	' otherwise ...
	ElseIf showRating And showPlayerInfo And Not showPlayStatus Then
		line3 = Rating & div &  PlayerInfo
	ElseIf showRating Or showPlayerInfo Then
		' write rating and status only ...
		If showRating Then
			line3 = Rating & Status
		' ... or Player Info and status only
		ElseIf showPlayerInfo Then
			line3 = PlayerInfo & Status
		End If
	End If

	'========================================
	' here we go to finish
	'========================================
	' open the file for writing
	Set oOutput = oFSO.CreateTextFile(filePath&fileName)

	' write lines to file
	' if for some reason needed we use line0 to cut the signature
	Dim ClpBrd
	If showLineZero Then
		oOutput.WriteLine line0
		ClpBrd = line0 & VBnewline
	End If
	oOutput.WriteLine line1
	If showAlbumName Then
		oOutput.WriteLine line2
	End If
	oOutput.WriteLine line3

	' and close the file when finished
	oOutput.Close()

	ClpBrd = ClpBrd & line1 & VBnewline
 	If showAlbumName Then
		ClpBrd = ClpBrd & line2 & VBnewline
	End If
	ClpBrd = ClpBrd & line3

	'========================================
	' copy info to clipboard
	'========================================
	' should info copied to clipboard either, then do it
	If copyToClipboard Then
		Dim objIE, strURL
		Set objIE = CreateObject("InternetExplorer.Application")
		objIE.Navigate("about:blank")
		strURL = objIE.document.parentwindow.clipboardData.SetData("Text",ClpBrd)
		objIE.Quit
	End If
	' but if only once, then ...
	If Not updateClipboard Then
		copyToClipboard = False
	End If

	' reset objects and variables
	Set oTrack = Nothing
	Set oAlbum = Nothing
	Set oOutput = Nothing
	Set oFSO = Nothing
'	Set Progress = Nothing
	oCSI = TrackIdx
	TrackIdx = ""
	Rating = ""
	div = ""
	PlayerInfo = ""
	Status = ""
	isPause = ""
	isPlay = ""

	' Hmm, do I have to wait before I can rerun or must I leave?
	If runLoop Then
		WScript.Sleep updateFile
	Else
		Exit Do
	End If
Loop
NowPlayingConf.vbs

Code: Select all

'
' MediaMonkey Script
'
' NAME: NowPlaying Configuration 0.4.2
'       NowPlayingConf.vbs
'
' AUTHOR: margu
'
' DATE : (01/23/2006 18:40)
'
' NOTE: took parts and suggestions from Rissers TitleCase.vbs and
'       trixmotos CueReader.vbs to understand Form Objects handling
'
' DESCRIPTION:
'	Because it's exhausting to manually editing the NowPlaying.vbs
'	if you want to change the behaviour of the script, I thought
'	about how funny it could be to have a configuration tool.
'	Well, here it is :-)
'	After you setup all like described below you will find this
'	config tool at "Tools->Scripts" in MM Menu.
'
' HISTORY:
'       0.4.2 (01/23/2006 18:40)
'           Change: For the output filename one can now select a file
'                   by using the file select dialog
'           Change: Preview output for changed line2 look
'
'       0.4.0 (01/22/2006 17:01)
'            Added: Config options for maxLineLenght
'
'       0.3.0 (01/19/2006 17:02)
'            Added: Config options for copyToClipboard
'
'       0.2.0 (12/30/2005 23:57)
'            Added: Song from "now playing" list will be used for preview,
'                   because one can see how it will look with own songs
'                   (especially the player status, 'cause player is usable
'                   while config run).
'           Change: Some 'make-up' :-)
'
'       0.1.1 beta1 (12/22/2005 17:34)
'            Fixed: If showPlayStatus is disabled PlayerInfo won't be shown
'                   in Preview
'
'	0.1.0 beta1 (12/21/2005 00:34)
'            first pre-release
'
' INSTALL: Copy this script (NowPlayingConf.vbs) to MM Scripts
'          directory and change the below settings as you need them.
'          Afterwards add the following lines to Scripts.ini
'          Don't forget to remove comments (') and set the order appropriately
'
'
'[NowPlayingConf]
'FileName=NowPlayingConf.vbs
'ProcName=NowPlayingConf
'Order=23
'DisplayName=NowPlaying Configuration
'Description=Change the behaviour of the output from NowPlaying script
'Language=VBScript
'ScriptType=0
'
'======================================================================

Option Explicit
Dim NPScript

'=============================================================
'    You can change the following settings for your needs
'=============================================================
'
' Here you have to set the name of your NowPlaying.vbs
' if you have changed it from default
NPScript = "NowPlaying.vbs"

'=============================================================
'            End of editing
'=============================================================
' define variables for first preview info
Dim oTrack, oPlayer, oVersion, oAlbum
Dim egArtTit, egAlbN, egRat, egPI, egPS
Set oPlayer = SDB.Player
Set oTrack = oPlayer.CurrentSong
Set oAlbum = oTrack.Album
egArtTit = "listening: " & oTrack.ArtistName & " - " & oTrack.Title
If oTrack.AlbumName = "" Then
	egAlbN = "    Album: unknown"
Else
	egAlbN = "    Album: " & oTrack.AlbumName
End If
If CSng(oTrack.Rating/20) < 0 Then
	egRat = "my rating: not rated yet"
Else
	egRat = "my rating: " & CSng(oTrack.Rating/20) & " of 5 stars"
End If
egPI = "MediaPlayer: MediaMonkey " & SDB.VersionString
If Not oPlayer.isPlaying Then
	egPS = " (stopped)"
ElseIf oPlayer.isPaused Then
	egPS = " (paused)"
Else
	egPS = ""
End If

' define variables and fill array for hints
Dim a,b,c,d,e,f,g,h,i,j,k
a = "Here you can define if" & VBnewline & "Rating is shown or not"
b = "Here you can define if" & VBnewline & "PlayerInfo is shown or not"
c = "Here you can define if" & VBnewline & "PlayStatus is shown or not"
d = "Here you can define if the" & VBnewline & "Album Name is shown or not"
e = "Here you can define if the file" & VBnewline & "is updated only on song change or" & VBnewline & "will be updated continuous"
f = "Here you can set how often the player status" & VBnewline & "should be checked and the file be updated." & VBnewline & "Value is set in seconds"
g = "Here you can define the name" & VBnewline & "of the textfile. It will be" & VBnewline & "stored in MM defined 'My Music'" & VBnewline & "(german: 'Eigene Musik') folder"
h = "Here you can choose if the line0 (-- )" & VBnewline & "will be inserted as signature cutter"
i = "Here you can set the maximum" & VBnewline & "lenght of line 1 + 2." & VBnewline & "For unlimited set it to 0 (zero)."
j = "Here you can define if you want" & VBnewline & "the clipboard be updated."
k = "Here you can define if you" & VBnewline & "want to have all information" & VBnewline & "copied to clipboard"
Dim vars, hints
hints = Array(a,b,c,d,e,f,g,h,i,j,k)

' fill array with the names of all variables in NowPlaying script
vars = Array("showRating","showPlayerInfo","showPlayStatus","showAlbumName","runLoop", _
	     "updateFile","fileName","showLineZero","maxLineLenght","updateClipboard", _
	     "copyToClipboard")

Public oFileVarVal, oFormVarVal
Set oFileVarVal = CreateObject("Scripting.Dictionary")
Set oFormVarVal = CreateObject("Scripting.Dictionary")

NPScript = SDB.ApplicationPath&"Scripts\"&NPScript
Dim firstrun, PVLabel
firstrun = 1

' we need some regular expressions
Dim oRegvars, oChkcomm, oDigit, oQuote, oPath
Set oRegvars = new regExp
Set oChkcomm = new regExp
Set oDigit = new regExp
Set oQuote = new regExp
Set oPath = new regExp
oRegvars.ignoreCase = False
oRegvars.pattern = "^(?:" & vars(0) & "|" & vars(1) & "|" & vars(2) & "|" & vars(3) & "|" & vars(4) & "|" & vars(5) & "|" & vars(6) & "|" & vars(7) & "|" & vars(8) & "|" & vars(9) & "|" & vars(10) & ")\b( =)"
oChkcomm.ignoreCase = True
oChkcomm.pattern = "^'(?:\')"
oDigit.pattern = "^\d*(?:[0-9])"
oQuote.pattern = Chr(34) ' I have to find a better regexp for this
'oQuote.pattern = "^(?:" & Chr(34) & ")$" ' I have to find a better regexp for this
'oPath.ignoreCase = True
'oPath.pattern = "(\w+[\.]\w+)$"

Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")

Sub CloseDown
	Set SDB.Objects("NowPlayingConfSave") = Nothing
	Set SDB.Objects("oFileVarVal") = Nothing
	Set SDB.Objects("oFormVarVal") = Nothing
End Sub

Sub OnCancel(ClickedBtn)
	CloseDown
End Sub

Sub OnOK(ClickedBtn)
	Dim res, oBox0, oBox1, oBox2, oBox3, oBox4, oBox7, oBox10, oBox9, SEdt, Edt, SEdt2
	Set oBox0 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox0")
	Set oBox1 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox1")
	Set oBox2 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox2")
	Set oBox3 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox3")
	Set oBox4 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox4")
	Set oBox7 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox7")
	Set oBox9 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox9")
	Set oBox10 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox10")
	Set SEdt = ClickedBtn.Common.TopParent.Common.ChildControl("SEdt")
	Set Edt = ClickedBtn.Common.TopParent.Common.ChildControl("Edt")
	Set SEdt2 = ClickedBtn.Common.TopParent.Common.ChildControl("SEdt2")

	Set SDB.Objects("oFormVarVal") = Nothing

	oFormVarVal.add oBox0.Caption, oBox0.Checked
	oFormVarVal.add oBox1.Caption, oBox1.Checked
	oFormVarVal.add oBox2.Caption, oBox2.Checked
	oFormVarVal.add oBox3.Caption, oBox3.Checked
	oFormVarVal.add oBox4.Caption, oBox4.Checked
	oFormVarVal.add oBox7.Caption, oBox7.Checked
	oFormVarVal.add oBox9.Caption, oBox9.Checked
	oFormVarVal.add oBox10.Caption, oBox10.Checked
	oFormVarVal.add vars(5), SEdt.Value
	oFormVarVal.add vars(8), SEdt2.Value

	PVLabel = oFormVarVal.Item(PVLabel)

	firstrun = 0

	' if the filename is missing generate an error message and
	' go back to main window without saving anything..
	If Edt.Text = "" Then
		res = SDB.MessageBox("Filename is missing.", mtError, Array(mbOk))
		NowPlayingConf
		Exit Sub
	End If
	oFormVarVal.add vars(6), Edt.Text

	' WriteOutput
	Dim oOutput, line, varlist, newline, tmp
	newline = ""

	' open the file for reading
	Set oOutput = oFSO.OpenTextFile(NPScript, 1, 0)
	' we've to read each line of the file to find the variables
	Do While Not oOutput.AtEndOfStream
		' cleaning the line
		line = Trim(oOutput.ReadLine)
                If Not line = "" Then
		' if one of the variables are found do somethng
		If oRegvars.test(line) Then
                	varlist = Split(line," = ")
			newline = newline & varlist(0) & " = "
			If oQuote.test(varlist(1)) Then
				newline = newline & Chr(34) & oFormVarVal.Item(varlist(0)) & Chr(34) & VBnewline
			Else
				newline = newline  & oFormVarVal.Item(varlist(0)) & VBnewline
			End If
		Else
			newline = newline & line & VBnewline
		End If
		End If
	Loop
	' and close the file when finished
	oOutput.Close()
	Set oOutput = Nothing

	' now overwrite the old vbs file with the new settings
	Set oOutput = oFSO.CreateTextFile(NPScript)
	oOutput.WriteLine newline
	oOutput.Close()

	res = SDB.MessageBox("File was changed successfully.", mtInformation, Array(mbOk))
	Exit Sub
End Sub

Sub OnReset(ClickedBtn)
	Set SDB.Objects("oFormVarVal") = Nothing
	firstrun = 1
	NowPlayingConf
End Sub

Sub OnPreview(ClickedBtn)
	Dim res, oBox0, oBox1, oBox2, oBox3, oBox4, oBox7, oBox10, oBox9, SEdt, Edt, SEdt2
	Set oBox0 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox0")
	Set oBox1 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox1")
	Set oBox2 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox2")
	Set oBox3 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox3")
	Set oBox4 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox4")
	Set oBox7 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox7")
	Set oBox9 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox9")
	Set oBox10 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox10")
	Set SEdt = ClickedBtn.Common.TopParent.Common.ChildControl("SEdt")
	Set SEdt2 = ClickedBtn.Common.TopParent.Common.ChildControl("SEdt2")
	Set Edt = ClickedBtn.Common.TopParent.Common.ChildControl("Edt")

	Set SDB.Objects("oFormVarVal") = Nothing

	oFormVarVal.add oBox0.Caption, oBox0.Checked
	oFormVarVal.add oBox1.Caption, oBox1.Checked
	oFormVarVal.add oBox2.Caption, oBox2.Checked
	oFormVarVal.add oBox3.Caption, oBox3.Checked
	oFormVarVal.add oBox4.Caption, oBox4.Checked
	oFormVarVal.add oBox7.Caption, oBox7.Checked
	oFormVarVal.add oBox9.Caption, oBox9.Checked
	oFormVarVal.add oBox10.Caption, oBox10.Checked
	oFormVarVal.add vars(5), SEdt.Value
	oFormVarVal.add vars(8), SEdt2.Value

	firstrun = 0

	' here we start to generate the preview lines
	Dim Rating, PlayerInfo, Status, div, line0
	PVLabel = ""

	If oBox0.Checked Then Rating = egRat
        If oBox1.Checked Then PlayerInfo = egPI
        If oBox2.Checked Then Status = egPS
	div = " / "
	line0 = "-- "

	If oBox7.Checked Then PVLabel = PVLabel & line0 & VBnewline

	If Not oBox0.Checked And Not oBox1.Checked Then
		If Not SEdt2.Value = 0 Then
			PVLabel =  PVLabel & Left(egArtTit, SEdt2.Value-(Len(Status)+1)) & " " & Status
		Else
			PVLabel =  PVLabel & egArtTit & " " & Status
		End If
	Else
		If Not SEdt2.Value = 0 Then
			PVLabel = PVLabel & Left(egArtTit, SEdt2.Value)
		Else
			PVLabel = PVLabel & egArtTit
		End If
	End If

        PVLabel = PVLabel & VBnewline

	Dim line2a
	If Not oTrack.ArtistName = oTrack.AlbumArtistName Then
		If Not (oTrack.AlbumArtistName = "Various Artists" Or _
			oTrack.AlbumArtistName = "VA" Or _
			oTrack.AlbumArtistName = "Various") Then
			line2a = "(" & oTrack.AlbumArtistName & ")"
		End If
	Else
		line2a = ""
	End If

	If Not SEdt2.Value = 0 Then
		If oBox3.Checked Then PVLabel = PVLabel & Left(egAlbN, SEdt2.Value-(Len(line2a)+1)) & " " & line2a & VBnewline
        Else
        	If oBox3.Checked Then PVLabel = PVLabel & egAlbN & " " & line2a  & VBnewline
        End If

	If oBox0.Checked And oBox1.Checked And oBox2.Checked Then
		PVLabel = PVLabel & Rating & div &  PlayerInfo & " " & Status
	ElseIf oBox0.Checked And oBox1.Checked And Not oBox2.Checked Then
		PVLabel = PVLabel & Rating & div &  PlayerInfo
	ElseIf oBox0.Checked Or oBox1.Checked Then
		If oBox0.Checked Then
			PVLabel = PVLabel & Rating & " " & Status
		ElseIf oBox1.Checked Then
			PVLabel = PVLabel & PlayerInfo & " " & Status
		End If
	End If
        PVLabel = PVLabel & VBnewline

	oFormVarVal.add "PVLabel", PVLabel

	' if the filename is missing generate an error message and
	' leave field as is.
	If Edt.Text = "" Then
		res = SDB.MessageBox("Filename is missing.", mtError, Array(mbOk))
		NowPlayingConf
		Exit Sub
	End If
	oFormVarVal.add vars(6), Edt.Text

	If oBox10.Checked Then
		Dim objIE, strURL
		Set objIE = CreateObject("InternetExplorer.Application")
		objIE.Navigate("about:blank")
		strURL = objIE.document.parentwindow.clipboardData.SetData("Text",PVLabel)
		objIE.Quit
	End If

	NowPlayingConf
End Sub

Sub OnOpen(ClickedBtn)
	Dim res, oBox0, oBox1, oBox2, oBox3, oBox4, oBox7, oBox10, oBox9, SEdt, Edt, SEdt2, fname
	Set oBox0 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox0")
	Set oBox1 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox1")
	Set oBox2 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox2")
	Set oBox3 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox3")
	Set oBox4 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox4")
	Set oBox7 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox7")
	Set oBox9 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox9")
	Set oBox10 = ClickedBtn.Common.TopParent.Common.ChildControl("oBox10")
	Set SEdt = ClickedBtn.Common.TopParent.Common.ChildControl("SEdt")
	Set SEdt2 = ClickedBtn.Common.TopParent.Common.ChildControl("SEdt2")
	Set Edt = ClickedBtn.Common.TopParent.Common.ChildControl("Edt")

	Set SDB.Objects("oFormVarVal") = Nothing

	oFormVarVal.add oBox0.Caption, oBox0.Checked
	oFormVarVal.add oBox1.Caption, oBox1.Checked
	oFormVarVal.add oBox2.Caption, oBox2.Checked
	oFormVarVal.add oBox3.Caption, oBox3.Checked
	oFormVarVal.add oBox4.Caption, oBox4.Checked
	oFormVarVal.add oBox7.Caption, oBox7.Checked
	oFormVarVal.add oBox9.Caption, oBox9.Checked
	oFormVarVal.add oBox10.Caption, oBox10.Checked
	oFormVarVal.add vars(5), SEdt.Value
	oFormVarVal.add vars(8), SEdt2.Value

	firstrun = 0

	With SDB.CommonDialog
		.DefaultExt = "txt"
		.Filter = "TXT (*.txt)|*.txt|All files (*.*)|*.*"
		.Title = SDB.Localize("Search...")
		.InitDir = SDB.IniFile.StringValue("Scripts", "NowPlayingDir")
		.ShowOpen
		fname = .FileName
	End With

'	fname = oPath.Replace(fname,"$1")
	fname = Mid(fname,InStrRev(fname,"\")+1)

	oFormVarVal.add vars(6), fname

	NowPlayingConf

End Sub

Function ReadFile
	Dim oInput, line, varlist

	If firstrun = 1 Then
		' open the file for reading
		Set oInput = oFSO.OpenTextFile(NPScript, 1, 0)
		Dim xy
		xy=0
		' we've to read each line of the file to find the variables
		' but we stop as soon as we have all needed vars
		Do While (xy < UBound(vars))
			' cleaning the line
			line = Trim(oInput.ReadLine)
			' only work with lines which aren't comments
			If Not oChkcomm.test(line) Then
				' if one of the variables are found do somethng
				If oRegvars.test(line) Then
		                	varlist = Split(line," = ")
					varlist(1) = oQuote.Replace(varlist(1),"")
					varlist(1) = oQuote.Replace(varlist(1),"")
					oFileVarVal.add varlist(0), varlist(1)
					xy=xy+1
				End If
			End If
		Loop
		' and close the file when finished
		oInput.Close()

		If oFormVarVal.Item(PVLabel) Then
			PVLabel = oFormVarVal.Item(PVLabel)
		Else
'			PVLabel = "Preview:" & VBnewline
			PVLabel = ""
		End If
	End If
End Function

Sub NowPlayingConf
	Dim oUI, oForm, oHead, oHeader, oFoot, oMain, oPrevw, oPrevw0, oPrevw1, oLblPvw
	Dim oLblPvw0, oPrevw2, oBtn1, oBtn2, oBtn3, oBtn4, oBtn5, oBox0, oBox1, oBox2, oBox3
	Dim oBox4, oBox7, oBox10, oBox9, SEdt, SEdtLbl, Edt, EdtLbl, SEdt2, SEdt2Lbl

	' first we check if NowPlaying script exist
	' if file doesn't exist exit with an error message
	If Not oFSO.FileExists(NPScript) Then
		res = SDB.MessageBox("File '"&NPScript&"' cannot be found.", mtError, Array(mbOk))
		Exit Sub
	End If

	' read vbs file to get config data
	ReadFile

	Set oUI = SDB.UI

	' here we start to open a window
	Set oForm = oUI.NewForm
	oForm.Common.SetRect 0, 0, 415, 330
	oForm.BorderStyle  = 3
	oForm.FormPosition = 4
	oForm.StayOnTop = True
	oForm.Caption = SDB.Localize("NowPlaying Configuration")
	oForm.SavePositionName = "NPCWindow"

	' create a top centered panel for configuration objects
	Set oMain = oUI.NewPanel(oForm)
	oMain.Common.Align = 1
	oMain.Common.Height = 160

	' and place all configuration objects
	Set oBox0 = oUI.NewCheckBox(oMain) ' showRating
	oBox0.Caption = vars(0)
	oBox0.Common.Top = 0
	oBox0.Common.Left = 10
	oBox0.Common.Hint = hints(0)
	oBox0.Common.ControlName = "oBox0"

	Set oBox1 = oUI.NewCheckBox(oMain) ' showPlayerInfo
	oBox1.Caption = vars(1)
	oBox1.Common.Top = 20
	oBox1.Common.Left = 10
	oBox1.Common.Hint = hints(1)
	oBox1.Common.ControlName = "oBox1"

	Set oBox2 = oUI.NewCheckBox(oMain) ' showPlayStatus
	oBox2.Caption = vars(2)
	oBox2.Common.Top = 40
	oBox2.Common.Left = 10
	oBox2.Common.Hint = hints(2)
	oBox2.Common.ControlName = "oBox2"

	Set oBox3 = oUI.NewCheckBox(oMain) ' showAlbumName
	oBox3.Caption = vars(3)
	oBox3.Common.Top = 60
	oBox3.Common.Left = 10
	oBox3.Common.Hint = hints(3)
	oBox3.Common.ControlName = "oBox3"

	Set oBox7 = oUI.NewCheckBox(oMain) ' showLineZero
	oBox7.Caption = vars(7)
	oBox7.Common.Top = 80
	oBox7.Common.Left = 10
	oBox7.Common.Hint = hints(7)
	oBox7.Common.ControlName = "oBox7"

	Set oBox4 = oUI.NewCheckBox(oMain) ' runLoop
	oBox4.Caption = vars(4)
	oBox4.Common.Top = 0
	oBox4.Common.Left = 200
	oBox4.Common.Hint = hints(4)
	oBox4.Common.ControlName = "oBox4"

	Set SEdt = oUI.NewSpinEdit(oMain) ' updateFile
	SEdt.Common.Top = 20
	SEdt.Common.Left = 200
	SEdt.Common.Width = 45
	SEdt.Common.Hint = hints(5)
	SEdt.MinValue = 10
	SEdt.MaxValue = 120
	SEdt.Common.ControlName = "SEdt"
	Set SEdtLbl = oUI.NewLabel(oMain) ' updateFile
	SEdtLbl.Caption = "update interval in seconds"
	SEdtLbl.Common.SetRect SEdt.Common.Left+50, SEdt.Common.Top+5, 150, SEdt.Common.Height
	SEdtLbl.Common.Hint = hints(5)

	Set SEdt2 = oUI.NewSpinEdit(oMain) ' maxLineLenght
	SEdt2.Common.Top = 50
	SEdt2.Common.Left = 200
	SEdt2.Common.Width = 45
	SEdt2.Common.Hint = hints(8)
	SEdt2.MinValue = 0
	SEdt2.MaxValue = 150
	SEdt2.Common.ControlName = "SEdt2"
	Set SEdt2Lbl = oUI.NewLabel(oMain) ' maxLineLenght
	SEdt2Lbl.Caption = "max. line lenght for lines 1+2" & VBnewline & "(0 = unlimited characters)"
	SEdt2Lbl.Common.SetRect SEdt2.Common.Left+50, SEdt2.Common.Top-5, 150, SEdt2.Common.Height+5
	SEdt2Lbl.Common.Hint = hints(8)

	Set oBox10 = oUI.NewCheckBox(oMain) ' copyToClipboard
	oBox10.Caption = vars(10)
	oBox10.Common.Top = 80
	oBox10.Common.Left = 200
	oBox10.Common.Hint = hints(10)
	oBox10.Common.ControlName = "oBox10"

	Set oBox9 = oUI.NewCheckBox(oMain) ' updateClipboard
	oBox9.Caption = vars(9)
	oBox9.Common.Top = 100
	oBox9.Common.Left = 200
	oBox9.Common.Hint = hints(9)
	oBox9.Common.ControlName = "oBox9"

	Set EdtLbl = oUI.NewLabel(oMain) ' fileName
	EdtLbl.Caption = "name of the output file stored in" & VBnewline & "MediaMonkeys 'My Music' folder:"
	EdtLbl.Common.SetRect oBox7.Common.Left+25, SEdt.Common.Top+105, 200, SEdt.Common.Height+10
	EdtLbl.Common.Hint = hints(6)
	Set Edt = oUI.NewEdit(oMain) ' fileName
	Edt.Common.SetRect SEdt.Common.Left, SEdt.Common.Top+110, 120, SEdt.Common.Height
	Edt.Common.Hint = hints(6)
	Edt.Common.ControlName = "Edt"
	Set oBtn5 = oUI.NewButton(oMain) ' fileName
	oBtn5.Caption = SDB.Localize("&Search")
	oBtn5.Common.SetRect Edt.Common.Left+130, Edt.Common.Top, 70, Edt.Common.Height
	oBtn5.UseScript = Script.ScriptPath
	oBtn5.OnClickFunc = "OnOpen"


	' only on first run we need to set this values, otherwise
	' we can't handle the preview for which the current values
	' need to be present
	If firstrun = 1 Then
		If oFileVarVal.Item(vars(0)) = "True" Then oBox0.Checked = True
		If oFileVarVal.Item(vars(1)) = "True" Then oBox1.Checked = True
		If oFileVarVal.Item(vars(2)) = "True" Then oBox2.Checked = True
		If oFileVarVal.Item(vars(3)) = "True" Then oBox3.Checked = True
		If oFileVarVal.Item(vars(4)) = "True" Then oBox4.Checked = True
		If oFileVarVal.Item(vars(7)) = "True" Then oBox7.Checked = True
		If oFileVarVal.Item(vars(9)) = "True" Then oBox9.Checked = True
		If oFileVarVal.Item(vars(10)) = "True" Then oBox10.Checked = True
               	SEdt.Value = oFileVarVal.Item(vars(5))
		Edt.Text = oFileVarVal.Item(vars(6))
               	SEdt2.Value = oFileVarVal.Item(vars(8))


		firstrun = 0
	Else
		oBox0.Checked = oFormVarVal.Item(vars(0))
		oBox1.Checked = oFormVarVal.Item(vars(1))
		oBox2.Checked = oFormVarVal.Item(vars(2))
		oBox3.Checked = oFormVarVal.Item(vars(3))
		oBox4.Checked = oFormVarVal.Item(vars(4))
		oBox7.Checked = oFormVarVal.Item(vars(7))
		oBox9.Checked = oFormVarVal.Item(vars(9))
		oBox10.Checked = oFormVarVal.Item(vars(10))
		SEdt.Value = oFormVarVal.Item(vars(5))
		Edt.Text = oFormVarVal.Item(vars(6))
               	SEdt2.Value = oFormVarVal.Item(vars(8))
        End If

	' create a panel with header on top of the window
	Set oHead = oUI.NewPanel(oForm)
	oHead.Common.Align = 1
	oHead.Common.Height = 25

	Set oHeader = oUI.NewLabel(oHead) ' Header
	oHeader.Caption = "Select what you want that the look of the textfile is."
	oHeader.Common.SetRect 65,5,290,15

	' create a panel at the bottom of the window
	' with needed buttons
	Set oFoot = oUI.NewPanel(oForm)
	oFoot.Common.Align = 2
	oFoot.Common.Height = 35

	' one for saving the changes
	Set oBtn1 = oUI.NewButton(oFoot)
	oBtn1.Caption = SDB.Localize("&Ok")
	oBtn1.Common.SetRect oFoot.Common.Width - 400, 8, 85, 25
	oBtn1.Common.Anchors = 2 + 8
	oBtn1.Default = True
	oBtn1.UseScript = Script.ScriptPath
	oBtn1.OnClickFunc = "OnOK"

	' one that close the window
	Set oBtn2 = oUI.NewButton(oFoot)
	oBtn2.Caption = SDB.Localize("&Cancel")
	oBtn2.Common.SetRect oFoot.Common.Width - 300, 8, 85, 25
	oBtn2.Common.Anchors = 2 + 8
	oBtn2.Cancel = True
	oBtn2.UseScript = Script.ScriptPath
	oBtn2.OnClickFunc = "OnCancel"

	' one that reset the form
	Set oBtn3 = oUI.NewButton(oFoot)
	oBtn3.Caption = SDB.Localize("&Reset")
	oBtn3.Common.SetRect oFoot.Common.Width - 200, 8, 85, 25
	oBtn3.Common.Anchors = 2 + 8
	oBtn3.UseScript = Script.ScriptPath
	oBtn3.OnClickFunc = "OnReset"

	' one to show a preview
	Set oBtn4 = oUI.NewButton(oFoot)
	oBtn4.Caption = SDB.Localize("&Preview")
	oBtn4.Common.SetRect oFoot.Common.Width - 100, 8, 85, 25
	oBtn4.Common.Anchors = 2 + 8
	oBtn4.UseScript = Script.ScriptPath
	oBtn4.OnClickFunc = "OnPreview"

	' create a bottom centered panel for preview output
	Set oPrevw0 = oUI.NewPanel(oForm)
	oPrevw0.Common.Align = 3  ' align left
	oPrevw0.Common.Width = 5
	Set oPrevw1 = oUI.NewPanel(oForm)
	oPrevw1.Common.Align = 4  ' align right
	oPrevw1.Common.Width = 5
	Set oPrevw = oUI.NewPanel(oForm) ' main preview panel
	oPrevw.Common.SetRect oPrevw0.Common.Width+2,oPrevw0.Common.Top+2,oPrevw1.Common.Left-8,oPrevw0.Common.Height-4
	Set oPrevw2 = oUI.NewPanel(oForm) ' header panel
	oPrevw2.Common.SetRect 15,oPrevw1.Common.Top-5,50,12
'	oPrevw2.Common.SetRect 15,180,50,12
	Set oLblPvw0 = oUI.NewLabel(oPrevw2) ' header
	oLblPvw0.Common.SetRect 4,0,42,12
	oLblPvw0.Caption = "Preview:"

	Set oLblPvw = oUI.NewLabel(oPrevw) ' Preview
	oLblPvw.Common.SetRect 5,10,oPrevw.Common.Width-5,oPrevw.Common.Height-5
	oLblPvw.Caption = PVLabel

	oForm.Common.Visible = True
	SDB.Objects("NowPlayingConfSave") = oForm
End Sub

by margu » Sun Jan 22, 2006 11:35 am

I did it again :wink:

NowPlaying.vbs (V. 1.3.0)
NowPlaying2.vbs (V. 1.3.0)
NowPlayingConf.vbs (V. 0.4.0)


I added the funtionality to specify the lenght of the output lines, so one can get his signature go to be RFC conform by limit the line to 72 chars.

NowPlaying.vbs

Code: Select all

'New Code as always below :)

by Peke » Thu Jan 19, 2006 9:17 pm

margu,
Thats whz I like to to write simpe and easy scripts so that someone can use them as idea for new one or upgrading old one.
Great Work Keep it going.

by margu » Thu Jan 19, 2006 1:36 pm

Hello,

and again updates :-)

NowPlaying.vbs (V. 1.2.0)
NowPlaying2.vbs (V. 1.2.0)
NowPlayingConf.vbs (V. 0.3.0)

Because of Judas idea and Pekes CopyInfoExt.vbs I've added this functionality to my scripts.
I hope you find it useful :)

Code: Select all

Again a new version below

by margu » Fri Dec 30, 2005 6:07 pm

Hello,

I've updated the NowPlayingConf.vbs (v. 0.2.0) above.

I wish you all a happy and lucky new year and that all your wishes (not only for MM :lol: ) come truth :-)

..::Margu::..

by margu » Thu Dec 22, 2005 11:43 am

Hello @ all

NowPlaying.vbs (v 1.1.3), NowPlaying2.vbs (v 1.1.3)

Updated: NowPlayingConf.vbs (v 0.2.0)

NowPlaying.vbs

Code: Select all

New code below

by margu » Tue Dec 20, 2005 7:21 pm

Hello,

as I talked about a few posts above, I've build an add-on for my NowPlaying script. It is a configuration GUI so one don't have to edit the NowPlaying.vbs manually.
It's called NowPlayingConf.vbs and has to be stored in MMs script directory and need an entry in scripts.ini
Afterwards you will find it in MM menu Tools->Scripts->NowPlaying Configuration

I'm thinking about to put it into MM Options. What do you think about that?

Note:
I've tested this script and think it's well running. But please do a backup copy of your NowPlaying.vbs before using this script, because it's a beta.

Here we go:

NowPlayingConf.vbs

Code: Select all

Update below
As every time: suggestions, hints, bug reports and so on are welcome.

..::M::..

by margu » Mon Dec 19, 2005 5:54 am

Here is a next update (v 1.1.2).

2 things have changed:
- added a switchable signature cutter (-- )
- fixed decimal point behaviour

NowPlaying.vbs

Code: Select all

Updates available below :)

by margu » Mon Dec 19, 2005 4:42 am

Hi popper,

thank you for your reply.
According your 1. suggestion: I didn't implemented this because my Thunderbird insert these line by itself :-)
But I'll put it in with your mentioned enable/disable switch.

Regarding the decimal point I'll fix it in the next release.

On my system this script is either running during the whole weekend (nearling 24h a day :) ) without problems, so I think it will be out of beta next time.

At the moment I'm working (more to learn VBScript) on a configuration UI so one don't have to manualy edit the script for changing the settings. But it's hard work to handle these damn Form Objects ;-)

..::M::..

by popper » Mon Dec 19, 2005 3:59 am

Have been using it since friday and no problems so far, so it seems that everything is fine, thank you.

If you were interested in another minor modification, I've got two suggestions (very low priority, only if you are really bored ;)):
1. According to some Internet RFC, mail signatures should start with one line containing "-- " (dash, dash, space) so that they can be easily recognised as signatures and can e.g. be automatically cut off when quoting something.

So what I would like to see is a "line0" that holds "-- " and could also be switched on and off using one of the switches in nowplaying.vbs.

2. If used on a german system, the rating uses a comma as a decimal point ("2,5 out of 5 points"), which doesn't make sense for english speaking folks. It would be correct to say "2.5 out of 5 points". So either we translate the texts into German (which is potentially uncool) or we replace that comma with a decimal point...

popper
--
not listening to anything right now, because he is supposed to work...

Top