« [Basic]ファイルサイズの取得 | トップページ | [mountedVolume]マウントボリュームのリスト »

[AVMetadataItem]メタデータの取得


#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
#                       com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application
set objFileManager to refMe's NSFileManager's defaultManager()



set ocidUserDesktopPath to (objFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set aliasDefaultLocation to ocidUserDesktopPath as alias

tell application "Finder"
    ##    set aliasDefaultLocation to container of (path to me) as alias
end tell

set listChooseFileUTI to {"public.mp3", "com.apple.m4a-audio"}

set strPromptText to "音楽ファイルを選んでください" as text

set aliasFilePath to (choose file with prompt strPromptText default location (aliasDefaultLocation) of type listChooseFileUTI with invisibles and showing package contents without multiple selections allowed) as alias

###パス
set strFilePath to POSIX path of aliasFilePath as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false

doGetAVMetaData(ocidFilePathURL) as text
log doGetAVMetaData(ocidFilePathURL) as text

return doGetAVMetaData(ocidFilePathURL) as text

###########################################
### メタデータを読み取るサブ
###########################################


to doGetAVMetaData(argURL)
    ####取得するキー
    set ocidCommonKey to refMe's AVMetadataCommonKeyType
    (*主要なキー
AVMetadataCommonKeyArtist
AVMetadataCommonKeyAlbumName
AVMetadataCommonKeyTitle
AVMetadataCommonKeyType -->ジャンル
他は:https://developer.apple.com/documentation/avfoundation/avmetadatakey
    *)
    ###URLアセットを取得
    set ocidAVURLAsset to refMe's AVURLAsset's URLAssetWithURL:argURL options:(missing value)
    ###メタデータを取得
    set ocidCommonMetadata to ocidAVURLAsset's commonMetadata()
    ###タイトルメタデータを取得
    set ocidMetaArray to refMe's AVMetadataItem's metadataItemsFromArray:ocidCommonMetadata withKey:(ocidCommonKey) keySpace:(refMe's AVMetadataKeySpaceCommon)
    ###データが取得できなければNULLを返す
    try
        set ocidMetaKey to ocidMetaArray's objectAtIndex:0
        set strMetaValue to ocidMetaKey's value() as text
    on error
        set strMetaValue to missing value
    end try
    return (strMetaValue)
end doGetAVMetaData

|

« [Basic]ファイルサイズの取得 | トップページ | [mountedVolume]マウントボリュームのリスト »

AppleScript Music」カテゴリの記事