¿Cómo obtener y configurar los metadatos de un archivo m4a?

0

Estoy intentando automatizar algunos cambios en los metadatos de m4a y preferiría hacerlo a través de AppleScript que no sean las soluciones populares como mutagen.

¿Cómo puedo abordar los metadatos de los archivos m4a? No solo necesito establecer metadatos en valores específicos, debo leer estos valores primero.

Básicamente, lo que necesito hacer es configurar TRACK_NAME en ARTIST + "-" + TRACK_NAME, y luego TRACK_NAME en ALBUM_ARTIST. Esto es necesario para que mi reproductor de medios no distribuya los cumplimientos en toda la biblioteca. Lamentablemente, no sabe nada mejor.

    
pregunta blackeyeliner 25.08.2015 - 15:30

1 respuesta

1

Aquí hay algo rápido para que comiences. Si también desea que se cambie el nombre del archivo, es fácil agregarlo en la sección de copia ...

set dpath to "/some/path/some/where/"
set qdpath to quoted form of dpath

# Choices of apps to use depending what files you have
# mp3
set tapp3 to "/usr/local/bin/id3v2 -t "
# m4a
set tapp4 to "/usr/local/bin/mp4tags -s "

tell application "iTunes"
    set iSel to selection

    repeat with trk in iSel
        set aloc to location of trk
        set loc to quoted form of (POSIX path of aloc)
        set tname to name of trk
        set tartist to artist of trk
        tell application "Finder"
            set fname to name of file (aloc as alias)
            set fext to name extension of file (aloc as alias)
        end tell


        # Copy
        try
            do shell script "cp " & loc & " " & qdpath
        on error eStr
            display dialog eStr
            return
        end try


        # New path
        set qnewfile to quoted form of (dpath & fname)


        # Choose right tool...
        if fext is "mp3" then
            set tapp to tapp3
        else if fext is "m4a" then
            set tapp to tapp4
        else
            display dialog "Unknown file type. Don't know what to use..."
            return
        end if


        # Tag 
        try
            do shell script tapp & "'" & tartist & " - " & tname & "' " & qnewfile
        on error eStr
            display dialog eStr
            return
        end try
    end repeat
end tell

Ya que no te gusta usar las herramientas de línea de comandos y Applescript no tiene soporte incorporado para etiquetas de audio, te quedas con iTunes. Así que aquí hay una versión de lo anterior con solo usar iTunes,

set dpath to "/some/path/"
set qdpath to quoted form of dpath
set listname to "MyList"
set adpath to (POSIX file dpath as alias)

# Copy selected itunes files
tell application "iTunes"
    set iSel to selection

    repeat with trk in iSel
        set tloc to location of trk
        set atloc to quoted form of (POSIX path of tloc)
        set tname to name of trk
        set tartist to artist of trk

        tell application "Finder"
            set fname to name of file (tloc as alias)
            set fext to name extension of file (tloc as alias)

            try
                duplicate file tloc to folder adpath with replacing
            on error eStr
                display dialog "Copy failed for track: " & tname & return & return & eStr
                return
            end try
        end tell
    end repeat
end tell


# Get audio files in selected folder 
#   -- alas no recursive search results without a lot more code... :(
set afiles to {}
tell application "Finder"
    repeat with ext in {".mp3", ".m4a"}
        set l to (every file in adpath whose name contains ext)
        repeat with f in l
            set end of afiles to (f as text)
        end repeat
    end repeat
end tell


# Add to iTunes and change Tags...
#
tell application "iTunes"
    if not (user playlist listname exists) then
        make new user playlist with properties {name:listname}
    end if

    set view of window 1 to playlist listname

    # Add and change tracks' names
    repeat with afile in afiles
        try
            set tid to (add afile to playlist listname)
        end try

        set tname to name of tid
        set aname to artist of tid

        set name of tid to ((aname & " - " & tname) as text)
    end repeat

    # Clean up now?
    set r to display dialog "Done. " & return & return & ¬
        "Remove tracks and list now?" as text buttons {"No", "Yes"} with icon note

    if button returned of r is not "Yes" then
        return
    end if


    # Remove playlist tracks from library; will remove from playlist(s) too
    #   -- WARNING: If track added multiple times all entries will be removed!! 
    repeat with t in (every track in playlist listname)
        try
            set pid to persistent ID of t

            # Thanks Doug Adams, it was driving me nuts....
            delete (some file track of library playlist 1 whose persistent ID is pid)
        end try
        delay 1
    end repeat

    delay 30

    # Remove all tracks from playlist v2
    try
        # Fast mass deletion - Thx to http://apple.stackexchange.com/a/56463
        # but only removes from playlist.. they remain in the library!
        #delete tracks of playlist listname
    end try

    try
        delete playlist listname
    end try
end tell
    
respondido por el Vic 26.08.2015 - 19:36

Lea otras preguntas en las etiquetas