Unicode in SDB title/artist

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

Moderators: Peke, Gurus

asaf-g
Posts: 15
Joined: Sat Sep 27, 2008 10:40 am

Unicode in SDB title/artist

Post by asaf-g »

Hello
When I try to get the value of a title or an artist (or whatever) from the SDB when in unicode, all I get is question marks.
Is there a way to get the real value of the variables?

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

Re: Unicode in SDB title/artist

Post by trixmoto »

Maybe you could be more specific about what you are doing? I've certainly had no problem reading Unicode data from the database and writing it to files, or example.
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.
asaf-g
Posts: 15
Joined: Sat Sep 27, 2008 10:40 am

Re: Unicode in SDB title/artist

Post by asaf-g »

I'm trying to write something that reverses the order of unicode strings inside id3 tags.
When I go to SDB.CurrentSongList and get the Title or the Album, I get "????" instead of letters.
asaf-g
Posts: 15
Joined: Sat Sep 27, 2008 10:40 am

Re: Unicode in SDB title/artist

Post by asaf-g »

Code: Select all

Sub ReverseTags
  Dim list, itm, i

  ' Get list of selected tracks from MediaMonkey
  Set list = SDB.CurrentSongList 

  ' Process all selected tracks
  For i=0 To list.count-1
    Set itm = list.Item(i)
    If (itm.BPM <> 1 AND itm.BPM <> 2) Then     ' Reverse only if modification flag isn't on yet
        itm.Title = ConditionalReverse(itm.Title)
        itm.ArtistName = ConditionalReverse(itm.ArtistName)
        itm.AlbumArtistName = ConditionalReverse(itm.AlbumArtistName)
        itm.Genre = ConditionalReverse(itm.Genre)
        itm.Album.Name = ConditionalReverse(itm.Album.Name)
        itm.BPM = 1 ' Make sure we won't reverte this file at next startup
    End If
  Next

  ' Write all back to DB and update tags
  list.UpdateAll
End Sub

' Reverse if string contains Hebrew
Function ConditionalReverse(rev)
  If rev = "" Then
    ConditionalReverse = rev
  End If

  Dim i, list, tmp

  list = Split(rev)
  tmp = rev

  For i=0 To UBound(list)
    If HasHebrew(list(i)) Then
      'MsgBox ("has hebrew")
      tmp = StrReverse(rev)
    End if
  Next

  ConditionalReverse = tmp
End Function

' Check if a string contains Hebrew ( = ascii betwee 224-250)
Function HasHebrew(rev)
  Dim tmp
  tmp = Asc(rev)

  If (tmp >= 224 OR tmp <= 250) Then
     HasHebrew = true
  End If

  HasHebew = false
End Function
What happens is, in the function HasHebew(rev) - the tmp variable gets "????" instead of actual chars.
ZvezdanD
Posts: 3270
Joined: Thu Jun 08, 2006 7:40 pm

Re: Unicode in SDB title/artist

Post by ZvezdanD »

asaf-g wrote:What happens is, in the function HasHebew(rev) - the tmp variable gets "????" instead of actual chars.
Maybe you could try:

Code: Select all

Function ConditionalReverse(rev)
  If rev = "" Then
    ConditionalReverse = rev
  Else
    Dim i, tmp, bHebrew

    For i=1 To Len(rev)
      tmp = Mid(rev, i, 1)
      If HasHebrew(tmp) Then
        bHebrew = True
        'MsgBox ("has hebrew")
        Exit For
      End if
    Next

    If bHebrew = True Then
      ConditionalReverse = StrReverse(rev)
    Else
      ConditionalReverse = rev
    End If
  End If
End Function

Function HasHebrew(rev)
  Dim tmp
  tmp = AscW(rev)

  If (tmp >= &H590 OR tmp <= &H5FF) Then
     HasHebrew = true
  Else
     HasHebew = false
  End If

End Function
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
asaf-g
Posts: 15
Joined: Sat Sep 27, 2008 10:40 am

Re: Unicode in SDB title/artist

Post by asaf-g »

Still replaces no matter what (does not consider the if HasHebrew())
When I try to debug (aka pop a msgbox) the variable tmp in the HasHebrew function, I always get 63, which is the ascii code for '?'.
ZvezdanD
Posts: 3270
Joined: Thu Jun 08, 2006 7:40 pm

Re: Unicode in SDB title/artist

Post by ZvezdanD »

Try to add Msgbox rev & vbCr & Mid(rev, i, 1) after the line For i=1 To Len(rev) and post what you got.
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
ZvezdanD
Posts: 3270
Joined: Thu Jun 08, 2006 7:40 pm

Re: Unicode in SDB title/artist

Post by ZvezdanD »

You could also try:

Code: Select all

Function ConditionalReverse(rev)
  If rev = "" Then
    ConditionalReverse = rev
  Else
   Dim RE, Matches
    Set RE = New RegExp
    RE.IgnoreCase = True
    RE.Global = True
    RE.Pattern = "[\u0590-\u05FF]"
    Set Matches = RE.Execute(rev)
    If Matches.Count > 0 Then
      ConditionalReverse = StrReverse(rev)
    Else
      ConditionalReverse = rev
    End If
  End If
End Function
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
asaf-g
Posts: 15
Joined: Sat Sep 27, 2008 10:40 am

Re: Unicode in SDB title/artist

Post by asaf-g »

It does show the correct letters + a break-line and the first Hebrew letter of the song title, but it always returns true, even for English only titles.
asaf-g
Posts: 15
Joined: Sat Sep 27, 2008 10:40 am

Re: Unicode in SDB title/artist

Post by asaf-g »

ZvezdanD wrote:You could also try:

Code: Select all

Function ConditionalReverse(rev)
  If rev = "" Then
    ConditionalReverse = rev
  Else
   Dim RE, Matches
    Set RE = New RegExp
    RE.IgnoreCase = True
    RE.Global = True
    RE.Pattern = "[\u0590-\u05FF]"
    Set Matches = RE.Execute(rev)
    If Matches.Count > 0 Then
      ConditionalReverse = StrReverse(rev)
    Else
      ConditionalReverse = rev
    End If
  End If
End Function
This seems to work! I wonder why the other method didn't...

And I'm also looking for a way to auto-start this script before and after I start sync-ing my device. Do you know of a way to do that?
ZvezdanD
Posts: 3270
Joined: Thu Jun 08, 2006 7:40 pm

Re: Unicode in SDB title/artist

Post by ZvezdanD »

asaf-g wrote:It does show the correct letters + a break-line and the first Hebrew letter of the song title, but it always returns true, even for English only titles.
Instead of

Code: Select all

If (tmp >= &H590 OR tmp <= &H5FF) Then
it should be

Code: Select all

If (tmp >= &H590 AND tmp <= &H5FF) Then
.
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
Post Reply