0

コンピューター間でプレイリストの同期を維持するためのスクリプトを作成しています。

私はapplescriptを介してそれを行うと考えました。

前半は、m3u へのエクスポートで、これに行き詰まっています。

コードは次のとおりです。

property delimiter_character : " - "

tell application "iTunes"

set this_playlist to playlist "Alternative Mixtape"
set this_name to (the name of this_playlist) as string

set the playlist_count to the count of tracks of this_playlist
set playlist_data to {}
tell this_playlist
    repeat with i from 1 to the count of tracks
        tell track i
            set the end of the playlist_data to {name, delimiter_character, artist, return, location, return}
        end tell
    end repeat
end tell

end tell

set FileName to "Path:To:File.m3u"
set theFile to open for access FileName with write permission
write playlist_data to theFile
close access theFile

問題は、あらゆる種類の「文字化けした」出力が得られることです。

listlistutxt Hips Of The Yearutxt - utxtMistutxt
alisvvHDD…ÏXËH+Ï›Hips Of The Year.mp3χ»g∏mMp3 hookˇˇˇˇ Bye Bye…Ï<»»gúMϛϋ’.HDD:Music:Mist:Bye Bye:Hips Of The Year.mp3*Hips Of The Year.mp3HDD(/Music/Mist/Bye Bye/Hips Of The Year.mp3

クリップボードをプレーン テキストに変換しようとしましたが、クラス UTF8 またはレコードとしてコピーしようとするとエラーが発生し続けます。

4

1 に答える 1

0

m3u はテキストファイルです。あなたの問題はあなたのコードにあり、playlist_dataはリストとして作成されます。実際には、さらに複雑なリストのリストです。つまり、リストをテキストとしてファイルに書き込んでいます...これがめちゃくちゃになります。このコードを試してください。ファイルに適切に書き込むため、playlist_data をリストではなくテキストとして作成します。他にもいくつかの最適化を行いました。お役に立てば幸いです。

注: プレイリスト名とファイルパスを自分の値に変更する必要があります。

property delimiter_character : " - "

set playlistName to "CD 01"
set filePath to (path to desktop as text) & "cd01.txt"

tell application "iTunes"
    set theTracks to tracks of playlist playlistName

    set playlist_data to ""
    repeat with aTrack in theTracks
        tell aTrack
            set trackName to name
            set trackArtist to artist
            set trackLocation to location
        end tell
        set playlist_data to playlist_data & trackName & delimiter_character & trackArtist & return & trackLocation & return & return
    end repeat
end tell

try
    set theFile to open for access file filePath with write permission
    write playlist_data to theFile
    close access theFile
on error
    close access file filePath
end try

最後に 1 つ注意事項があります。また、playlist_data リストをファイルに書き込むこともできます。この行のリストとしてデータを書き込むように write ステートメントに指示する必要があります。そのステートメントの「as」部分には何も指定していないため、ファイルをテキストとして書き込むデフォルトの動作を行います。ただし、必要に応じて「リスト」を指定できます。これを行うと、テキスト エディタでファイルを読み取ることができなくなることに気付くでしょうが、後でそのファイルを「リストとして」読み込んで AppleScript に戻し、データをリスト形式に戻すことができるという利点があります。 . ただし、これは m3u ファイルを作成するタスクには適していません。

于 2011-11-01T21:21:20.863 に答える