Un Applescript que copia por lotes la etiqueta de la canción en la etiqueta del movimiento

Tengo una biblioteca de iTunes bastante grande (~ 300 GB) que es principalmente música clásica. Me gusta mucho el formato Trabajo y movimiento, pero lamentablemente no es práctico actualizar manualmente mis metadatos al formato Trabajo y movimiento. Casi todas las etiquetas de canciones existentes tienen el siguiente formato:

Telemann - Concerto in E minor: I. Andante
II. Allegro
III. Largo
IV. Allegro
etc.

Una secuencia de comandos que podría automatizar la actualización del sistema de etiquetado sería similar a la siguiente.

  1. En todas las canciones seleccionadas, copie la etiqueta de la canción en la etiqueta de movimiento.
  2. Elimine el número romano, el punto y el espacio del frente de la etiqueta de movimiento. O, en el formato en el que se incluye el nombre completo de la obra en la etiqueta de la canción, elimínelo.

Cualquier ayuda o sugerencia para implementar este script sería muy útil. He mirado y usado los guiones de trabajo y movimiento de Doug , pero no cubren el proceso de coincidencia que sería necesario para eliminar los números romanos desde el principio.

EDITAR

Se ha hecho evidente que muchas de las etiquetas no están en el formato anterior, sino en un formato como el siguiente:

Serenade for strings in C major, Op. 48 - I. Allegro
Serenade for strings in C major, Op. 48 - II. Adagio
Serenade for strings in C major, Op. 48 - III. Allegro moderato
etc.

O en el mismo formato que el anterior, excepto que se usan números arábigos en lugar de los números romanos.

El script debería dar como resultado que las etiquetas de "Movimiento" tengan los siguientes resultados:

Allegro
Adagio
Allegro moderato

La idea es obtener la primera parte de esto ("Serenata para cuerdas en Do mayor, Op. 48") y copiarla en la etiqueta "trabajo", que ya he implementado, luego obtener el texto restante, eliminar el movimiento números y asígnelo a la etiqueta Movimiento. Cualquier ayuda para implementar un sistema que haga esto sería apreciada.

Aquí está el script en su forma actual. Se basa en el guión Name to Work de Doug.

tell application "iTunes"
    set sel to selection of front browser window
    if sel is {} then
        try
            display dialog "Nothing is selected…" buttons {"Quit"} with icon 0
        end try
        return
    end if

    set c to (count of sel)
    set songName to (get name of item 1 of sel)


    set userOptions to display dialog "Edit for Work name and then click OK." default answer songName --prompt for work name

    repeat with i from 1 to c --set the movement numbers
        set thisTrack to item i of sel
        try
            set work of thisTrack to text returned of userOptions
            set movement number of thisTrack to i
            set movement count of thisTrack to c
            set movement of thisTrack to my delRomNum(name of thisTrack) -- copy movement text from song name and delete roman numerals
        end try
    end repeat


end tell

on delRomNum(t) -- the perl command search and delete any roman numeral (must be a word followed by the period and a space character)
    do shell script "/usr/bin/perl -pe 's/\\b[IVXLCDM]+\\b. //g' <<< " & quoted form of t
end delRomNum
@ jackjr300 ¿Podrías ayudar? Toma esto como un complemento.
@kopischke Es posible que también puedas ayudar. Avísame si puedes :) Estoy llamando a los "expertos" en AppleScripting.
Edite su "EDITAR" y muestre el resultado esperado que desea asignar a la etiqueta de movimiento de " Se ha hecho evidente que muchas de las etiquetas no están en el formato anterior, sino en un formato como el siguiente: " porque el resultado quieres no es obvio.
@user3439894 Listo. Gracias por señalar la falta de claridad (¿es una palabra?)

Respuestas (2)

Para eliminar los números romanos, puede usar el delRomNum()controlador de este script:

--- this text as an example.
set movementText to "Telemann - Concerto in E minor: I. Andante
II. Allegro
III. Largo
IV. Allegro
etc."

set movementText to my delRomNum(movementText) -- delete roman numerals


on delRomNum(t) -- the perl command search and delete any roman numeral (must be a word followed by the period and a space character)
    do shell script "/usr/bin/perl -pe 's/\\b[IVXLCDM]+\\b. //g' <<< " & quoted form of t
end delRomNum

El resultado del guión es

"Telemann - Concerto in E minor: Andante
Allegro
Largo
Allegro
etc."

Actualizar:

Si entendí bien:

De cada línea de una cadena, el comando debe eliminar los caracteres desde el principio de la línea hasta la primera aparición de (un número romano o un número arábigo) seguido del punto y un carácter de espacio, así que use este controlador:

-- call it, like this --> set movement of thisTrack to my delRomNum(name of thisTrack)
on delRomNum(t)
    (***  from  the contents of the 't' variable (the end of lines must be an Unix Line Endings), so the 'tr' command change the carriage returns (Mac Line Endings) to linefeed (Unix Line Endings)
    the 'perl' command delete the first character in each line through the first occurrence of a word  which contains (a roman numeral or a number) followed by the period and a space character ***)
    do shell script "tr '\\r' '\\n' <<< " & (quoted form of t) & " | /usr/bin/perl -pe 's/^.*?\\b[IVXLCDM0-9]+\\b. //g'"
end delRomNum

Ejemplo: el script pasa esta cadena al controlador como parámetro

Serenade for strings in C major, Op. 48 - I. Allegro
Serenade for strings in C major, Op. 48 - II. Adagio
Serenade for strings in C major, Op. 48 - III. Allegro moderato
Serenade for strings in C major, Op. 48 - 4. Allegro  Molto Appassionato
Serenade for strings in C major, Op. 48 - 5. Adagio - Allegro Molto
Serenade for strings in C major, Op. 48 - 6. Allegro moderato
VII. Adagio - Allegro Non Troppo
8. Allegro Ma Non Tanto
9. Largo
Adagio
etc.

El controlador devuelve:

Allegro
Adagio
Allegro moderato
Allegro  Molto Appassionato
Adagio - Allegro Molto
Allegro moderato
Adagio - Allegro Non Troppo
Allegro Ma Non Tanto
Largo
Adagio
etc.
Esto funciona muy bien, muchas gracias. Realmente no sé lo que estoy haciendo y, de hecho, agregué una sección a la pregunta y mi script actual, si pudiera echar un vistazo y darme algún consejo, eso sería extraordinariamente útil. Gracias de nuevo.

Bueno, me he dado cuenta de esto yo mismo. En el caso de que esto sea útil para alguien más, este es el script completo.

tell application "iTunes"
    set sel to selection of front browser window
    if sel is {} then
        try
            display dialog "Nothing is selected…" buttons {"Quit"} with icon 0
        end try
        return
    end if

    set c to (count of sel)
    set songName to (get name of item 1 of sel)


    set workName to display dialog "Edit for Work name and then click OK." default answer songName --prompt for work name
    set movementLength to display dialog "Edit to everything except the movement name. Do not include the roman numeral if one is present. If an arabic numeral is present, include it." default answer songName --prompt for movement length


    repeat with i from 1 to c --set the movement numbers
        set thisTrack to item i of sel
        set songName to (get name of thisTrack)
        set work of thisTrack to text returned of workName
        set movement number of thisTrack to i
        set movement count of thisTrack to c
        set movement of thisTrack to my delRomNum(text ((length of text returned of movementLength) + 1) thru (length of songName) of songName as string) -- copy movement text from song name and delete roman numerals
    end repeat


end tell

on delRomNum(t) -- the perl command search and delete any roman numeral (must be a word followed by the period and a space character)
    do shell script "/usr/bin/perl -pe 's/\\b[IVXLCDM]+\\b. //g' <<< " & quoted form of t
end delRomNum
ver mi respuesta actualizada.