Unicode in SDB title/artist

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: Unicode in SDB title/artist

Re: Unicode in SDB title/artist

by ZvezdanD » Sun Sep 28, 2008 3:36 pm

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
.

Re: Unicode in SDB title/artist

by asaf-g » Sun Sep 28, 2008 3:12 pm

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?

Re: Unicode in SDB title/artist

by asaf-g » Sun Sep 28, 2008 3:09 pm

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.

Re: Unicode in SDB title/artist

by ZvezdanD » Sun Sep 28, 2008 3:02 pm

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

Re: Unicode in SDB title/artist

by ZvezdanD » Sun Sep 28, 2008 2:54 pm

Try to add Msgbox rev & vbCr & Mid(rev, i, 1) after the line For i=1 To Len(rev) and post what you got.

Re: Unicode in SDB title/artist

by asaf-g » Sun Sep 28, 2008 2:47 pm

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 '?'.

Re: Unicode in SDB title/artist

by ZvezdanD » Sun Sep 28, 2008 2:37 pm

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

Re: Unicode in SDB title/artist

by asaf-g » Sun Sep 28, 2008 2:01 pm

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.

Re: Unicode in SDB title/artist

by asaf-g » Sun Sep 28, 2008 1:30 pm

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.

Re: Unicode in SDB title/artist

by trixmoto » Sun Sep 28, 2008 12:18 pm

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.

Unicode in SDB title/artist

by asaf-g » Sat Sep 27, 2008 10:44 am

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.

Top