[com.apple.metadata]オーディオファイルのコメントにビットレートを入れる

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use framework "AVFoundation"
use scripting additions
property refMe : a reference to current application
###入力
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
####UTIリスト オーディオのみ
set listUTI to {"public.audio"}
####ダイアログを出す
set strName to (name of current application) as text
if strName is "osascript" then
tell application "Finder" to activate
else
tell current application to activate
end if
set listAliasFilePath to (choose file with prompt "オーディオファイルを選んでください" default location (aliasDefaultLocation) of type listUTI with invisibles, showing package contents and multiple selections allowed) as list
####選んだファイルの数だけ繰り返す
repeat with itemAliasFilePath in listAliasFilePath
set aliasFilePath to itemAliasFilePath as alias
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePath to (refMe's NSString's stringWithString:(strFilePath))
set ocidFilePathURL to (refMe's NSURL's fileURLWithPath:(ocidFilePath))
log "######AVAsset"
set ocidReadAsset to (refMe's AVAsset's assetWithURL:(ocidFilePathURL))
set ocidReadAssetDuration to ocidReadAsset's duration()
set numTimeSclae to item 2 of ocidReadAssetDuration
log numTimeSclae
log "######AVAssetTrack"
set ocidReadAssetTrackArray to ocidReadAsset's tracks()
set numCntTrackNo to (count of ocidReadAssetTrackArray) as integer
set ocidTrack to (ocidReadAssetTrackArray's objectAtIndex:0)
set numDataRate to ocidTrack's estimatedDataRate() as number
set numDataRate to (numDataRate / 1000) as integer
set strDataRate to numDataRate as text
###メタデータ整形 (ダブルクオテーションを2重にエスケープするのがポイントか?)
set strPlistData to ("<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><!DOCTYPE plist PUBLIC \\\"-//Apple//DTD PLIST 1.0//EN\\\" \\\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\\\"><plist version=\\\"1.0\\\"><string>DataRate: " & strDataRate & " kbps</string></plist>") as text
###コマンド整形
set strCommandText to ("/usr/bin/xattr -w com.apple.metadata:kMDItemComment \"" & strPlistData & "\" \"" & strFilePath & "\"") as text
###コマンド実行
set strResults to (do shell script strCommandText) as text
end repeat
| 固定リンク
「Media Music」カテゴリの記事
- [Music]メタデータの文字化け置換(EU系の文字化けの置換) 少し増えた(2024.03.18)
- [shortcut]再生中の音楽をShazamでしらべてタイトルアーティストを設定する(2023.12.11)
- [Music]メタデータの文字化け置換(1つ毎処理)(2023.12.09)
- [afinfo]ミュージックファイルの詳細メタ情報の取得(2023.11.01)
- [com.apple.metadata]オーディオファイルのコメントにビットレートを入れる(2023.11.01)