IPB

Bienvenue invité ( Connexion | Inscription )

 
Reply to this topicStart new topic
> Demande pour modifier Applescript iTunes (Résolu), Capitalisation,lowercase,etc...
Options
-do_ob-
posté 14 Jan 2010, 15:46
Message #1


Adepte de Macbidouille
*

Groupe : Membres
Messages : 179
Inscrit : 28 Apr 2008
Membre no 113 242



Bonjour à tous,

Je cherche à modifier un script existant que j'ai chopé sur Doug's appelscript for Itune

Il s'agit d'un Script qui modifie dans les Tags la capitalisation à la manière anglo-saxonne (C'est à dire avec une majuscule à presque chaque mot).
Avant que le script se lance on peut choisir sur quel Tags il va agir (Titre, compositeur,artiste,etc...)

Pour les Tags "artiste" et "compositeur" je ne souhaite rien changer. Par contre pour le "titre" et "album" le modifier pour qu'uniquement la première lettre soit en lettre capitale.
Je n'y comprends pas grand chose. Je tâtonnerai bien me n'arrive pas à repérer où je pourrai essayer de modifier qqchose.
Si qqn peut me tuyauter sur quoi modifier wink.gif

CODE
(*
Proper English Title Capitalization
By Cantus Vetustus
Report Bugs/Suggestions to [email protected]

Based on Doug Adams's original "Track Names to Word Caps" AppleScript.
His AppleScript can be downloaded at: http://www.malcolmadams.com/itunes/scripts/scripts09.shtml
*)


--===========LIST OF TAGS TO MODIFY===========--
--These are the tags that will be selected by default.
property my_tags_to_modify : {"name", "album"}
--This is the list of tags you can modify.
property tags_to_modify : {"name", "artist", "composer", "album"}

--===========LIST OF LOWERCASE WORDS===========--
--These are the words that will remain lowercase, unless they begin or end the title.
property lowercase_words : {"a", "an", "and", "at", "but", "by", "for", "in", "nor", "of", "on", "or", "so", "the", "to", "with", "et"}
--Feel free to add these: "amid", "anti", "as", "down", "into", "like", "near", "off", "onto", "out", "over", "past", "per", "plus", "save", "some", "than", "till", "up", "upon", "via", "yet"

--===========LIST OF UNMODIFIED WORDS===========--
--These are the words that won't be modified at all. It's a good place to put all-uppercase words.
property unmodified_words : {"FM", "USA", "WDPK", "OYF’N", "UR", "TV", "MGM", "DVD", "ABC", "CD", "USSR", "CA", "WA", "NY", "NYC", "LP", "EP", "VHS", "UK", "GB", "'Bout", "'Cause", "o'", "'n'", "n'", "McCartney", "vs.", "de", "feat.", "Pi-hsien", "von", "van"}

--===========LIST OF TRAILING CHARACTERS===========--
--Any word trailed by a character in this list will be title cased. (ie. "a song" (with a remix) -> "A Song" (With a Remix))
property other_chars : "_!\"$%&/()=¿?@¡|#¢?“”[]{}*-+•«»—´`ºª…:;."

property lowercase_match : false
property unmodified_Match : false
property other_chars_match : false
property my_tags : my_tags_to_modify

global aWord, newWord

tell application "iTunes"
if selection is not {} then
set old_fi to fixed indexing
set fixed indexing to true
copy selection as list to mySelectedTracks
set songs_selected to (number of items in mySelectedTracks) as number
if songs_selected = 1 then
set songs_selected_message to "There is " & songs_selected & " track selected." as string
set songs_modified_message to songs_selected & " track was modified." as string
else
set songs_selected_message to "There are " & songs_selected & " tracks selected." as string
set songs_modified_message to songs_selected & " tracks were modified." as string
end if

set choice to button returned of (display dialog "Welcome to Proper English Title Capitalization." & return & return & songs_selected_message buttons {"Cancel", "Configure…", "Modify"} default button 3 with icon 1)

if choice = "Configure…" then
set my_tags_to_modify to (choose from list tags_to_modify with prompt "Select the track tags you wish to modify (unselected tags will be ignored):" default items my_tags_to_modify with multiple selections allowed without empty selection allowed)
if my_tags_to_modify is false then
set my_tags_to_modify to my_tags
run me
else
display dialog "Now we're ready." buttons {"Cancel", "Modify"} default button 2
end if
end if

repeat with selected_tag in my_tags_to_modify --Check which tags are to be modified.
repeat with aTrack in mySelectedTracks
set selected_tag to selected_tag as string
if selected_tag = "name" then set theTitle_as_List to (my TextToList(aTrack's name, space))
if selected_tag = "artist" then set theTitle_as_List to (my TextToList(aTrack's artist, space))
if selected_tag = "composer" then set theTitle_as_List to (my TextToList(aTrack's composer, space))
if selected_tag = "album" then set theTitle_as_List to (my TextToList(aTrack's album, space))
set newTitle to {}
set last_item to number of items in theTitle_as_List as number
set word_counter to 1

repeat with aWord in theTitle_as_List
set newWord to ""

repeat with my_unmodified_Match in unmodified_words
--Check if any of the words belong to the list of unmodified words.
if (my_unmodified_Match as string) = (aWord as string) then
set unmodified_Match to true
exit repeat
end if
end repeat

if unmodified_Match then
--Unmodify matching words in unmodified_words list (actually just copy the word from the list).
set newWord to my_unmodified_Match as string
set unmodified_Match to false
else if (word_counter = 1) or (word_counter = last_item) then
--Capitalize first and last words in title.
my SetCase(aWord)
else
--For words not beginning or ending the title (middle words).
repeat with my_lowercase_Match in lowercase_words
--Check if any of the middle words belong to the list of lowerase words.
if (my_lowercase_Match as string) = (aWord as string) then
set lowercase_match to true
exit repeat
end if
end repeat

if lowercase_match then
--Lowercase matching words in lowercase_words list (actually just copy the word from the list).
set newWord to my_lowercase_Match as string
set lowercase_match to false
else
--Capitalize the rest of the words.
my SetCase(aWord)
end if

end if

copy newWord to end of newTitle
set word_counter to (word_counter + 1)
end repeat

if selected_tag = "name" then set aTrack's name to my ListToText(newTitle, space)
if selected_tag = "artist" then set aTrack's artist to my ListToText(newTitle, space)
if selected_tag = "composer" then set aTrack's composer to my ListToText(newTitle, space)
if selected_tag = "album" then set aTrack's album to my ListToText(newTitle, space)
end repeat
end repeat

copy old_fi to fixed indexing
display dialog "Done!" & return & return & songs_modified_message buttons {"OK"} default button 1 with icon 1 giving up after 5
else
display dialog "There are no tracks selected." buttons {"Cancel"} default button 1 with icon 0
end if
end tell

--The handler taking care of the casing of words.
on SetCase(aWord)
repeat with j from 1 to (length of aWord)
if other_chars contains (character j of aWord) then
set j to (character j of aWord)
set newWord to newWord & j
set other_chars_match to true
else if other_chars_match then
set j to (character j of aWord)
if ((ASCII number of j) is greater than 96) and ((ASCII number of j) is less than 123) then
set newWord to newWord & (ASCII character ((ASCII number of j) - 32))
else if ((ASCII number of j) is greater than 64) and ((ASCII number of j) is less than 91) then
set newWord to newWord & j
else
set newWord to newWord & j
end if
set other_chars_match to false
else if (j = 1) then
set j to (character j of aWord)
if ((ASCII number of j) is greater than 96) and ((ASCII number of j) is less than 123) then
set newWord to newWord & (ASCII character ((ASCII number of j) - 32))
else
set newWord to newWord & j
end if
else
set j to (character j of aWord)
if ((ASCII number of j) is greater than 96) and ((ASCII number of j) is less than 123) then
set newWord to newWord & j
else if ((ASCII number of j) is greater than 64) and ((ASCII number of j) is less than 91) then
set x to (ASCII character ((ASCII number of j) + 32))
set newWord to newWord & x
else
set newWord to newWord & j
end if
end if
end repeat
end SetCase

on TextToList(theText, theDelimiter)
set saveDelim to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {theDelimiter}
set theList to every text item of theText
on error errStr number errNum
set AppleScript's text item delimiters to saveDelim
error errStr number errNum
end try
set AppleScript's text item delimiters to saveDelim
return (theList)
end TextToList

on ListToText(theList, theDelimiter)
set saveDelim to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {theDelimiter}
set theText to theList as text
on error errStr number errNum
set AppleScript's text item delimiters to saveDelim
error errStr number errNum
end try
set AppleScript's text item delimiters to saveDelim
return (theText)
end ListToText


--Created by Doug Adams
--First Modified by Cantus Vetustus on Mon Jun 16, 2003
--Last Modified by Cantus Vetustus on Tue Jun 18, 2003


Merci de votre aide

Ce message a été modifié par -do_ob- - 22 Jan 2010, 21:16.


--------------------
Sous 10.10.5
Go to the top of the page
 
+Quote Post
Guest_EricaL**_*
posté 19 Jan 2010, 06:48
Message #2





Guests






Bonjour,

Voici le script modifié, il fonctionne bien ici.

Code
property firstword : true
property t_tag : ""

--===========LIST OF TAGS TO MODIFY===========--
--These are the tags that will be selected by default.
property my_tags_to_modify : {"name", "album"}
--This is the list of tags you can modify.
property tags_to_modify : {"name", "artist", "composer", "album"}

--===========LIST OF LOWERCASE WORDS===========--
--These are the words that will remain lowercase, unless they begin or end the title.
property lowercase_words : {"a", "an", "and", "at", "but", "by", "for", "in", "nor", "of", "on", "or", "so", "the", "to", "with", "et"}
--Feel free to add these: "amid", "anti", "as", "down", "into", "like", "near", "off", "onto", "out", "over", "past", "per", "plus", "save", "some", "than", "till", "up", "upon", "via", "yet"

--===========LIST OF UNMODIFIED WORDS===========--
--These are the words that won't be modified at all. It's a good place to put all-uppercase words.
property unmodified_words : {"FM", "USA", "WDPK", "OYF’N", "UR", "TV", "MGM", "DVD", "ABC", "CD", "USSR", "CA", "WA", "NY", "NYC", "LP", "EP", "VHS", "UK", "GB", "'Bout", "'Cause", "o'", "'n'", "n'", "McCartney", "vs.", "de", "feat.", "Pi-hsien", "von", "van"}

--===========LIST OF TRAILING CHARACTERS===========--
--Any word trailed by a character in this list will be title cased. (ie. "a song" (with a remix)  -> "A Song" (With a Remix))
property other_chars : "_!\"$%&/()=¿?@¡|#¢?“”[]{}*-+•«»—´`ºª…:;."

property lowercase_match : false
property unmodified_Match : false
property other_chars_match : false
property my_tags : my_tags_to_modify

global aWord, newWord

tell application "iTunes"
    if selection is not {} then
        set old_fi to fixed indexing
        set fixed indexing to true
        copy selection as list to mySelectedTracks
        set songs_selected to (number of items in mySelectedTracks) as number
        if songs_selected = 1 then
            set songs_selected_message to "There is " & songs_selected & " track selected." as string
            set songs_modified_message to songs_selected & " track was modified." as string
        else
            set songs_selected_message to "There are " & songs_selected & " tracks selected." as string
            set songs_modified_message to songs_selected & " tracks were modified." as string
        end if
        
        set choice to button returned of (display dialog "Welcome to Proper English Title Capitalization." & return & return & songs_selected_message buttons {"Cancel", "Configure…", "Modify"} default button 3 with icon 1)
        
        if choice = "Configure…" then
            set my_tags_to_modify to (choose from list tags_to_modify with prompt "Select the track tags you wish to modify (unselected tags will be ignored):" default items my_tags_to_modify with multiple selections allowed without empty selection allowed)
            if my_tags_to_modify is false then
                set my_tags_to_modify to my_tags
                run me
            else
                display dialog "Now we're ready." buttons {"Cancel", "Modify"} default button 2
            end if
        end if
        
        repeat with selected_tag in my_tags_to_modify --Check which tags are to be modified.
            set selected_tag to selected_tag as string
            set t_tag to selected_tag
            repeat with aTrack in mySelectedTracks
                set firstword to true
                if selected_tag = "name" then set theTitle_as_List to (my TextToList(aTrack's name, space))
                if selected_tag = "artist" then set theTitle_as_List to (my TextToList(aTrack's artist, space))
                if selected_tag = "composer" then set theTitle_as_List to (my TextToList(aTrack's composer, space))
                if selected_tag = "album" then set theTitle_as_List to (my TextToList(aTrack's album, space))
                set newTitle to {}
                set last_item to number of items in theTitle_as_List as number
                set word_counter to 1
                
                repeat with aWord in theTitle_as_List
                    set newWord to ""
                    
                    repeat with my_unmodified_Match in unmodified_words
                        --Check if any of the words belong to the list of unmodified words.
                        if (my_unmodified_Match as string) = (aWord as string) then
                            set unmodified_Match to true
                            exit repeat
                        end if
                    end repeat
                    
                    if unmodified_Match then
                        --Unmodify matching words in unmodified_words list (actually just copy the word from the list).
                        set newWord to my_unmodified_Match as string
                        set unmodified_Match to false
                    else if (word_counter = 1) or (word_counter = last_item) then
                        --Capitalize first and last words in title.
                        my SetCase(aWord)
                        --if (word_counter = 1) and selected_tag is in {"name", "album"} then set firstword to false
                    else
                        --For words not beginning or ending the title (middle words).
                        repeat with my_lowercase_Match in lowercase_words
                            --Check if any of the middle words belong to the list of lowerase words.
                            if (my_lowercase_Match as string) = (aWord as string) then
                                set lowercase_match to true
                                exit repeat
                            end if
                        end repeat
                        
                        if lowercase_match then
                            --Lowercase matching words in lowercase_words list (actually just copy the word from the list).
                            set newWord to my_lowercase_Match as string
                            set lowercase_match to false --" en cherchant son etoile"
                        else
                            --Capitalize the rest of the words.
                            my SetCase(aWord)
                            --if selected_tag is in {"name", "album"} then set firstword to false
                        end if
                    end if
                    
                    copy newWord to end of newTitle
                    set word_counter to (word_counter + 1)
                end repeat
                
                if selected_tag = "name" then set aTrack's name to my ListToText(newTitle, space)
                if selected_tag = "artist" then set aTrack's artist to my ListToText(newTitle, space)
                if selected_tag = "composer" then set aTrack's composer to my ListToText(newTitle, space)
                if selected_tag = "album" then set aTrack's album to my ListToText(newTitle, space)
            end repeat
        end repeat
        
        copy old_fi to fixed indexing
        display dialog "Done!" & return & return & songs_modified_message buttons {"OK"} default button 1 with icon 1 giving up after 5
    else
        display dialog "There are no tracks selected." buttons {"Cancel"} default button 1 with icon 0
    end if
end tell

--The handler taking care of the casing of words.
on SetCase(aWord)
    repeat with j from 1 to (length of aWord)
        set c to (character j of aWord)
        set n to (ASCII number of c)
        if other_chars contains c then
            set newWord to newWord & c
            set other_chars_match to true
        else if other_chars_match and firstword then
            if (n is greater than 96) and (n is less than 123) then
                set newWord to newWord & (ASCII character (n - 32))
            else
                set newWord to newWord & c
            end if
            if t_tag is in {"name", "album"} then set firstword to false
            set other_chars_match to false
        else if (j = 1) and firstword then
            if (n is greater than 96) and (n is less than 123) then
                set newWord to newWord & (ASCII character (n - 32))
            else
                set newWord to newWord & c
            end if
            if t_tag is in {"name", "album"} then set firstword to false
        else
            if (n is greater than 64) and (n is less than 91) then
                set newWord to newWord & (ASCII character (n + 32))
            else
                set newWord to newWord & c
            end if
        end if
    end repeat
end SetCase

on TextToList(theText, theDelimiter)
    set saveDelim to AppleScript's text item delimiters
    try
        set AppleScript's text item delimiters to {theDelimiter}
        set theList to every text item of theText
    on error errStr number errNum
        set AppleScript's text item delimiters to saveDelim
        error errStr number errNum
    end try
    set AppleScript's text item delimiters to saveDelim
    return (theList)
end TextToList

on ListToText(theList, theDelimiter)
    set saveDelim to AppleScript's text item delimiters
    try
        set AppleScript's text item delimiters to {theDelimiter}
        set theText to theList as text
    on error errStr number errNum
        set AppleScript's text item delimiters to saveDelim
        error errStr number errNum
    end try
    set AppleScript's text item delimiters to saveDelim
    return (theText)
end ListToText

Go to the top of the page
 
+Quote Post
-do_ob-
posté 22 Jan 2010, 21:15
Message #3


Adepte de Macbidouille
*

Groupe : Membres
Messages : 179
Inscrit : 28 Apr 2008
Membre no 113 242



Génial!!
Ca marche impec!
biggrin.gif
Je sais pas comment te remercier.

Beau boulot.




--------------------
Sous 10.10.5
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
4 utilisateur(s) sur ce sujet (4 invité(s) et 0 utilisateur(s) anonyme(s))
0 membre(s) :

 



Nous sommes le : 28th April 2024 - 02:10