Converting Greek characters to latin

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

Moderators: Peke, Gurus

PKT

Converting Greek characters to latin

Post by PKT »

I have a number of songs with tags written in Greek characters. I would like to convert them to english using a mechanical approach (e.g. omega=w, rho=r).

I do not have coding skills so I would appreciate anybody's help.

Thanks. MediaMonkey rocks!
psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Post by psyXonova »

I have made a script that does that Greek to Greeklish conversion but i though that noone will need it. I will post it in a while.
psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Post by psyXonova »

KK, here it is, hope you like it. You can change how characters are replaced by editing Function ConvertChar

Also make sure that before copying the code below you must set the character encoding inside Internet Explorer or Firefox to Greek.

To check if the code is copied correctly, you should see Greek characters inside the ConvertChar funtion

Code: Select all

' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
'
'                "Greeklish.vbs", Dec-28-2005, v1.00
'         VBScript for MediaMonkey 2.3.1 (or above), written by psyXonova
'
' Purpose:
' - To convert Artists, Titles and Albums written in Greek to Greeklish.
'
' Notes:
' A big portion of this code has been copied from the Checkcase.vbs
'
' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----

Option Explicit

Public holdArtist, holdAlbum, holdTitle, holdAlbumArtist
Set holdArtist = CreateObject("Scripting.Dictionary")
Set holdAlbum = CreateObject("Scripting.Dictionary")
Set holdTitle = CreateObject("Scripting.Dictionary")
Set holdAlbumArtist = CreateObject("Scripting.Dictionary")

Const mmAnchorRight = 4
Const mmAnchorBottom = 8
Const mmAlignTop = 1
Const mmAlignBottom = 2
Const mmAlignClient = 5
Const mmListDropdown = 2
Const mmFormScreenCenter = 4
Public styleOn

Function ConvertChar(s)

Select Case s

Case "Á", "á", "¢", "Ü"
ConvertChar = "a"

Case "Â", "â"
ConvertChar = "b"

Case "Ã", "ã"
ConvertChar = "g"

Case "Ä", "ä"
ConvertChar = "d"

Case "Å", "å", "¸", "Ý"
ConvertChar = "e"

Case "Æ", "æ"
ConvertChar = "z"

Case "Ç", "ç", "¹", "Þ"
ConvertChar = "h"

Case "È", "è"
ConvertChar = "8"

Case "É", "é", "º", "ß"
ConvertChar = "i"

Case "Ê", "ê"
ConvertChar = "k"

Case "Ë", "ë"
ConvertChar = "l"

Case "Ì", "ì"
ConvertChar = "m"

Case "Í", "í"
ConvertChar = "n"

Case "Î", "î"
ConvertChar = "3"

Case "Ï", "ï", "¼", "ü"
ConvertChar = "o"

Case "Ð", "ð"
ConvertChar = "p"

Case "Ñ", "ñ"
ConvertChar = "r"

Case "Ó", "ó", "ò"
ConvertChar = "s"

Case "Ô", "ô"
ConvertChar = "t"

Case "Õ", "õ", "¾", "ý"
ConvertChar = "y"

Case "Ö", "ö"
ConvertChar = "f"

Case "×", "÷"
ConvertChar = "x"

Case "Ø", "ø"
ConvertChar = "ps"

Case "Ù", "ù", "¿", "þ"
ConvertChar = "w"

Case Else
ConvertChar = s

End Select

End Function

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

Function rdQS(UnquotedString)
  rdQS = "'" & Replace(UnquotedString, "'", "''") & "'"
End Function

Function ConvertItem(s)
  Dim currentWord, fixed, theChar
  Dim i
  currentWord = ""
  
  For i = 1 to Len(s)
    theChar = Mid(s,i,1)
    currentWord = currentWord & ConvertChar(theChar)  
  Next
      
  ConvertItem = currentWord
End Function

Sub CloseDown
  Set holdAlbum = nothing
  Set holdAlbumArtist = nothing
  Set holdArtist = nothing
  Set holdTitle = Nothing
  SDB.Objects("CaseThingy") = Nothing
  SDB.Objects("holdArtist") = Nothing
  SDB.Objects("holdAlbumArtist") = Nothing
  SDB.Objects("holdAlbum") = Nothing
  SDB.Objects("holdTitle") = Nothing
End Sub

Sub OnCancel(Btn)
  CloseDown
End Sub

Sub OnOK(Btn)
  Set holdAlbum = SDB.Objects("holdAlbum")
  Set holdAlbumArtist = SDB.Objects("holdAlbumArtist")
  Set holdArtist = SDB.Objects("holdArtist")
  Set holdTitle = SDB.Objects("holdTitle")

  Dim itm, str, sql
  Dim items, albumNames, artistNames
  Set items = CreateObject("Scripting.Dictionary")
  Set albumNames = CreateObject("Scripting.Dictionary")
  Set artistNames = CreateObject("Scripting.Dictionary")

  For Each itm In holdArtist
    str = holdArtist.item(itm)
    If Not items.exists(itm) Then
      items.add itm, itm
    End If
    itm.Custom1 = itm.ArtistName
    itm.artistName = str
    If Not artistNames.exists(str) Then
      sql = "UPDATE Artists SET Artists.Artist = " & rdQS(str) & " WHERE Artists.Artist= " & rdQS(Itm.ArtistName)
      SDB.database.execSQL(sql)
      ' This will affect ALL instances of this artist, including album artist, and on other tracks.
      artistNames.add str, str
    End If
  Next 'itm
  
  For Each itm In holdAlbumArtist
    str = holdAlbumArtist.item(itm)
    If Not items.exists(itm) Then
      items.add itm, itm
    End If
    itm.albumArtistName = str
    If Not artistNames.exists(str) Then
      sql = "UPDATE Artists SET Artists.Artist = " & rdQS(str) & " WHERE Artists.Artist= " & rdQS(Itm.ArtistName)
      SDB.database.execSQL(sql)
      artistNames.add str, str
    End If
  Next 'itm
  
  For Each itm In holdAlbum
    str = holdAlbum.item(itm)
    If Not items.exists(itm) Then
      items.add itm, itm
    End If
    itm.Custom3 = itm.AlbumName
    itm.albumName = str
    If Not albumNames.exists(str) Then
      sql = "UPDATE Albums SET Albums.Album = " & rdQS(str) & " WHERE Albums.Album= " & rdQS(Itm.AlbumName)
      SDB.database.execSQL(sql)
      ' This will affect ALL instances of this album, including other tracks.
      albumNames.add str, str
    End If
  Next 'itm
  
  For Each itm In holdTitle
    str = holdTitle.item(itm)
    If Not items.exists(itm) Then
      items.add itm, itm
    End If
    itm.Custom2 = itm.Title
    itm.title = str
  Next 'itm
  
  Dim list
  Set list = SDB.NewSongList
  For Each itm In items
    list.Add( itm)
  Next
  
  list.UpdateAll
  
  Set items = nothing
  CloseDown
End Sub

Function MapXML(original)
  Dim hold
  hold = Replace(original, "&", "&")
  hold = Replace(hold, "  ", "  ")
  hold = Replace(hold, "<", "<")
  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 MapField(fld)
  If fld="" Then
    MapField = "&nbsp;"
  Else
    MapField = MapXML(fld)
  End If
End Function

Function outField (fixed, normal)
  If fixed = normal Then
    outField = "<td>" & MapField(normal) & "</td>" & vbcrlf
  Else
    outField = "<td class=""highlight"" title=""" & SDB.Localize("Old Value: ") & Chr(13) & MapXML(normal) & """>" & MapField(fixed) & "</td>" & vbcrlf
  End If
End Function

Sub Greeklish
  Dim UI, Form, Foot, Btn, Btn2, WB, doc
  
  Dim trackList
  Dim writeChanges

  Set trackList = SDB.CurrentSongList

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

  Set UI = SDB.UI

  ' Create the window to be shown
  Set Form = UI.NewForm
  Form.Common.SetRect 50, 50, 500, 400
  Form.Common.MinWidth = 200
  Form.Common.MinHeight = 150
  Form.FormPosition = mmFormScreenCenter
  Form.SavePositionName = "CaseWindow"
  Form.Caption = SDB.Localize("Convert Language")
  Form.StayOnTop = True

  ' Create a web browser component
  Set WB = UI.NewActiveX(Form, "Shell.Explorer")
  WB.Common.Align = mmAlignClient      ' Fill all client rectangle
  WB.Common.ControlName = "WB"
  Set doc = WB.Interf.Document

  ' Create a panel at the bottom of the window
  Set Foot = UI.NewPanel(Form)
  Foot.Common.Align = mmAlignBottom
  Foot.Common.Height = 35

  ' Create a button that saves the report
  Set Btn2 = UI.NewButton(Foot)
  Btn2.Caption = SDB.Localize("&Ok")
  Btn2.Common.SetRect Foot.Common.Width - 200, 9, 85, 25
  Btn2.Common.Anchors = mmAnchorRight + mmAnchorBottom
  Btn2.UseScript = Script.ScriptPath
  Btn2.OnClickFunc = "OnOK"
  Btn2.Default = true

  ' Create a button that closes the window
  Set Btn = UI.NewButton(Foot)
  Btn.Caption = SDB.Localize("&Cancel")
  Btn.Common.SetRect Foot.Common.Width - 100, 9, 85, 25
  Btn.Common.Anchors = mmAnchorRight + mmAnchorBottom
  Btn.UseScript = Script.ScriptPath
  Btn.OnClickFunc = "OnCancel"
  Btn.Cancel = true

  Form.Common.Visible = True                ' Only show the form, don't wait for user input
  SDB.Objects("CaseThingy") = Form  ' Save reference to the form somewhere, otherwise it would simply disappear


  doc.write "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbcrlf
  doc.write "<html>" & vbcrlf
  doc.write "  <head>" & vbcrlf
  doc.write "    <title>" & SDB.Localize("Convert Language") & "</title>" & vbcrlf
  doc.write "  </head>" & VbCrLf

  doc.write "<STYLE TYPE=text/css>" & vbcrlf
  doc.write "body{font-family:'Verdana',sans-serif; background-color:#FFFFFF; font-size:9pt; color:#000000;}" & vbcrlf
  doc.write "H1{font-family:'Verdana',sans-serif; font-size:13pt; font-weight:bold; color:#AAAAAA; text-align:left}" & vbcrlf
  doc.write "P{font-family:'Verdana',sans-serif; font-size:8pt; color:#000000;}" & vbcrlf
  doc.write "TH{font-family:'Verdana',sans-serif; font-size:9pt; font-weight:bold; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:3px;}" & vbcrlf
  doc.write "TD{font-family:'Verdana',sans-serif; font-size:8pt; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:1px;}" & vbcrlf
  doc.write "TD.highlight{font-family:'Verdana',sans-serif; font-size:8pt; background-color:#FFFF77; color:#000000; border-color:#000000; border-style: solid; border-left-width:0px; border-right-width:0px; border-top-width:0px; border-bottom-width:1px;}" & vbcrlf
  doc.write "TR.dark{background-color:#EEEEEE}" & vbcrlf
  doc.write "TR.aleft TH{text-align:left}" & vbcrlf
  doc.write "</STYLE>" & vbcrlf

  doc.write "  <body>" & vbcrlf
  doc.write "    <H1>" & SDB.Localize("Greeklish convertion results:") & "</H1>" & vbcrlf
  doc.write "    <table border=""0"" cellspacing=""0"" cellpadding=""4"" width=""100%"">" & vbcrlf
  doc.write "      <tr class=""aleft"">" & vbcrlf
  doc.write "        <th>" & SDB.Localize("Artist") & "</th>" & vbcrlf
  doc.write "        <th>" & SDB.Localize("Title") & "</th>" & vbcrlf
  doc.write "        <th>" & SDB.Localize("Album") & "</th>" & vbcrlf
  doc.write "        <th>" & SDB.Localize("Album Artist") & "</th>" & vbcrlf
  doc.write "      </tr>" & vbcrlf

  Dim i, itm
  Dim artist, album, title, albumArtist
  for i=0 to trackList.count-1
    doc.write "      <tr" & Style() & ">" & vbcrlf

    Set itm = trackList.Item(i)
    artist = ConvertItem(itm.artistName)
    title = ConvertItem(itm.title)
    album = ConvertItem(itm.albumName)
    albumArtist = ConvertItem(itm.albumArtistName)
    
    doc.write outField(artist, itm.artistName)
    doc.write outField(title, itm.title)
    doc.write outField(album, itm.albumName)
    doc.write outField(albumArtist, itm.albumArtistName)
    If artist <> "" And artist <> itm.artistName Then
      holdArtist.add itm, artist
    End If
    If albumArtist <> "" And albumArtist <> itm.albumArtistName Then
      holdAlbumArtist.add itm, albumArtist
    End If
    If title <> "" And title <> itm.title Then
      holdTitle.add itm, title
    End If
    If album <> "" And album <> itm.albumName Then
      holdAlbum.add itm, album
    End If
    doc.write "      </tr>" & vbcrlf
    
  next 'i
  
  doc.write "    </table>" & VbCrLf
  doc.write "  </body>" & VbCrLf
  doc.write "</html>" & vbcrlf
  doc.close
  SDB.Objects("holdArtist") = holdArtist
  SDB.Objects("holdAlbumArtist") = holdAlbumArtist
  SDB.Objects("holdAlbum") = holdAlbum
  SDB.Objects("holdTitle") = holdTitle
End Sub
PKT
Posts: 2
Joined: Sun Mar 12, 2006 12:15 am
Location: New York

Post by PKT »

Thanks man. To be honest, I never thought somebody would have this...!

I am running into trouble. I change encoding on the browser to Greek and I copy the text into Notepad. I save the file as a .vbs but I am probably doing something wrong with the encoding. I chose both ANSI and Unicode but I am getting a compilation message "Unknown character........."

Where am I doing things wrong? I know virtually nothing around scripts and stuff. I would appreciate your help

Eyxaristw file,

Periklis
PKT
Posts: 2
Joined: Sun Mar 12, 2006 12:15 am
Location: New York

Post by PKT »

Man, I played around with my Regional Settings and it seems that I solved the problem. This is awesome

MediaMonkey is king
psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Post by psyXonova »

I am glad you solved your problem. Keep in mind that this script copies Artist, title and album to custom1, custom2, and custom3 before it converts them to Greek, so you can still have your Greek names there.

Elpizw na ekanes thn douleia sou, den kostizei tipota

Giannis
Guest

Post by Guest »

Oraios :D

Sini8os ka8omai kai ta allazo monos afou ine eukolo me tin maimou alla auto voi8a poli

na se kala
omueller
Posts: 3
Joined: Wed Jan 05, 2011 11:28 am

Re: Converting Greek characters to latin

Post by omueller »

Something wrong with my character sets -
cann I have the script as an download?
Thanasis
Posts: 84
Joined: Sun Aug 28, 2011 2:53 am

Re: Converting Greek characters to latin

Post by Thanasis »

Re, pou vrethhkate oloi eseis edw....????
Post Reply