Lyrics to TXT export script

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Lowlander
Posts: 46102
Joined: Sat Sep 06, 2003 5:53 pm
Location: MediaMonkey 5

Lyrics to TXT export script

Post by Lowlander » Wed Oct 22, 2003 1:33 pm

Here is an lyrics export script that will export the lyrics of a song to a textfile.
Included information on the text file are: Artist, Title, Album & Lyrics. And it will only display those songs that have lyrics the ones that don't have lyrics are omitted from the output file.

This has not been tested extensively so using it is on your own risk.

Tip:
* Create a new script file (*.vbs) to include these scripts. This will prevent them from being erased by new installations of MM, allow you to keep the current HTML output script and include as many output scripts as you want.

You'll need to modify the scripts.ini file as well.

The script
Option Explicit ' report undefined variables, ...

' function for quoting strings
Function QStr( astr)
QStr = chr(34) & astr & chr(34)
End Function

Dim list ' list of songs to be exported
Dim res ' results of dialogs calls
Dim fullfile ' fully specified output file name
Dim fso ' FileSystemObject

' SDB variable is connected to MediaMonkey application object

Sub InitExport( ext, filter, iniDirValue)
fullfile = ""

' Get a list of songs to be exported
Set list = SDB.SelectedSongList
If list.count=0 Then
Set list = SDB.AllVisibleSongList
End If

If list.count=0 Then
res = SDB.MessageBox( "Select tracks to be exported, please.", mtError, Array(mbOk))
Exit Sub
End If

' Open inifile and get last used directory
Dim iniF
Set iniF = SDB.IniFile

' Create common dialog and ask where to save the file
Dim dlg
Set dlg = SDB.CommonDialog
dlg.DefaultExt=ext
dlg.Filter=filter
dlg.Flags=cdlOFNOverwritePrompt + cdlOFNHideReadOnly
dlg.InitDir = iniF.StringValue( "Scripts", iniDirValue)
dlg.ShowSave

if Not dlg.Ok Then
Exit Sub ' if cancel was pressed, exit
End If

' Get the selected filename
fullfile = dlg.FileName

' Connect to the FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")

' Write selected directory to the ini file
iniF.StringValue( "Scripts", iniDirValue) = fullfile
End Sub

Sub FinishExport( ok)
On Error Resume Next

' remove the output file if terminated
if not Ok then
fso.DeleteFile( fullfile)
end if

' Notify user that it was successful
if ok then
res = SDB.MessageBox( "Export was completed successfully.", mtInformation, Array(mbOk))
else
res = SDB.MessageBox( "Export was terminated.", mtInformation, Array(mbOk))
end if
End Sub

Sub LyricsExportTXT
' initialize export
Call InitExport( ".txt", "TXT (*.txt)|*.txt|All files (*.*)|*.*", _
"LastExportHTMLDir")
if fullfile="" then
Exit Sub
end if

' Create the output file
Dim fout
Set fout = fso.CreateTextFile( fullfile, True)

' Use progress to notify user about the current action
Dim Progress
Set Progress = SDB.Progress
Progress.Text = "Exporting lyrics to a TXT file..."

' Iterate through the list and export all songs
Progress.MaxValue = list.count
Dim i, itm
for i=0 to list.count-1
Set itm = list.Item(i)

if itm.lyrics <> "" Then
' write artist and lyrics
fout.WriteLine itm.ArtistName & " - " & itm.title & " (" & itm.AlbumName & ")"
fout.WriteLine itm.Lyrics
fout.WriteLine "_______________________________"
fout.WriteLine
End if
Progress.Value = i+1
if Progress.Terminate then
Exit For
end if
next

' Write some code to finish html document
fout.WriteLine "</table><p/><table width=100%><tr>"
fout.WriteLine "<td style='border-bottom-width:0px'><B>Total Tracks: </B>"&i&"</td> <td align=Right style='border-bottom-width:0px'>Generated by <a href='http://www.mediamonkey.com'>MediaMonkey</a></td>"
fout.WriteLine "</tr></table></body></html>"

' Close the output file and finish
fout.Close

' Was it successfull?
Dim ok
if Progress.Terminate then
ok = False
else
ok = True
end if

' hide progress
Set Progress = Nothing

FinishExport( ok)
End Sub
This is the full script no need to add anything to run, just save it to a new .vbs file in the scripts directory and modify the scripts.ini file there. You'll need to restart MM to use the script.


PS you can find a nice program to add scripts to MM here: http://www.songs-db.com/forum/viewtopic ... 7&start=15 Is made by forum member Peke
Lowlander (MediaMonkey user since 2003)