My script returns gibberish text: How to get it right. Help please!

GO TO ADMIN PANEL > ADD-ONS AND INSTALL VERTIFORO SIDEBAR TO SEE FORUMS AND SIDEBAR

cjmnews

Moderator
Staff member
Moderator
Joined
Apr 26, 2006
Messages
9,454
Points
48
Location
Arizona
OK, this shows that MDLS is the problem.

Need to research why it is not doing this in Unicode.
 

cjmnews

Moderator
Staff member
Moderator
Joined
Apr 26, 2006
Messages
9,454
Points
48
Location
Arizona
I can't find a way to change the MDLS behavior. It looks like we'll need to find a way to change the characters to be the way you need it.

I don't think you need the "paragraph 2 of" any more. It seems that splitting the lines removed that.
The awk is splitting the line for you My guess is MLDS is returning
data<3 spaces>author
and the awk is getting you the author, formatted poorly.

The fix is to either encode the entire string as unicode or all as ascii.
so the accented e would become U+0065 followed by the accent U+0301 and so on.
Or convert to extended ascii so the e\\\\U0301 would become 0x82 which is the extended ascii for accented e.
I have seen some perl solutions that convert the ascii to unicode.
It may be easier to write code in Java or something to do the conversion.

still researching
 

Scriptonite

New member
Joined
Apr 2, 2015
Messages
12
Points
0
Besides wishing you good luck with that, I will dare to suggest that you look into some of the other wonderful applescripts made by Doug Adams to manage iTunes libraries at Doug Scripts.
You might find useful pieces of codes or at least hinting ones.
I've myself modified in the past some of the scripts to fit my special needs using my little understanding of scripts and simple deductions, but these MLDS, unicode, ascii, etc., go beyond my frugal knowledge in this matter.

Thank you very much for your continuous support!

Cheers!
 

Scriptonite

New member
Joined
Apr 2, 2015
Messages
12
Points
0
Hi,

With the help of a member at "Ask Different" I got two solutions to my script, although neither works from the iTunes Scripts menu.
They only work by selecting the tracks in iTunes and running the scripts opened directly in AppleScript editor.

(mdls solution)

tell application "iTunes"
set sel to the selection
if sel is {} then display dialog "Please select something" buttons {"Cancel"}
set tc to count sel
repeat with i from 1 to tc
tell (get item i of sel)
set loc to location
set authorfield to my getAuthors(loc)
if authorfield is not "" then set artist to authorfield & "-"
end tell
end repeat
end tell

on getAuthors(f)
do shell script "mdls -name kMDItemAuthors " & (quoted form of POSIX path of f) & " | /usr/bin/perl -ne 'if (m/^ /) {s/^ +[\"]?|\"$//g;s/\\\\u([[:xdigit:]]{1,4})/chr(eval(\"0x$1\"))/egi;print}' "
end getAuthors

(python solution)

tell application "iTunes"
set sel to the selection
if sel is {} then display dialog "Please select something" buttons {"Cancel"}
set tc to count sel
repeat with i from 1 to tc
tell (get item i of sel)
set loc to location
set authorfield to my getAuthors(loc)
if authorfield is not "" then set artist to authorfield & "-"
end tell
end repeat
end tell

on getAuthors(f)
do shell script "export PYTHONIOENCODING=UTF-8; /usr/bin/python -c 'import sys; print (sys.argv[1].replace(\"\\U\",\"\\u\").decode(\"unicode-escape\"))' \"$(mdls -name kMDItemAuthors " & (quoted form of POSIX path of f) & " | sed -nE 's/\"$//;s/^ +[\"]?//p')\""
end getAuthors

If selected from the iTunes Script menu, they will yield the same wrong characters (Mercé Lamás del Jagüey Nuñez becomes in iTunes Merce\U0301 Lama\U0301s del Jagu\U0308ey Nun\U0303ez-)

Running any of those scripts in Applescript Editor with tracks selected in iTunes will result in the correct transcription of special characters to iTunes! Great!

I will continue though, asking for help to get them working from the iTunes Script menu along with the other "Doug Scripts"

 
Top