| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 |
|
| 006 | ビデオのpxサイズを取得する |
| 007 | AVURLAssetを使っているが非同期にはなっていない |
| 008 |
|
| 009 |
|
| 010 | com.cocolog-nifty.quicktimer.icefloe *) |
| 011 | ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-- |
| 012 | use AppleScript version "2.8" |
| 013 | use framework "Foundation" |
| 014 | use framework "AVFoundation" |
| 015 | use framework "AppKit" |
| 016 | use framework "UniformTypeIdentifiers" |
| 017 | use scripting additions |
| 018 | property refMe : a reference to current application |
| 019 |
|
| 020 |
|
| 021 | ############################# |
| 022 | ###入力ファイル |
| 023 | ############################# |
| 024 | tell current application |
| 025 | set strName to name as text |
| 026 | end tell |
| 027 | if strName is "osascript" then |
| 028 | tell application "Finder" to activate |
| 029 | else |
| 030 | tell current application to activate |
| 031 | end if |
| 032 | #デスクトップ |
| 033 | set aliasDesktopDirPath to (path to desktop from user domain) as alias |
| 034 | set listUTI to {"public.movie"} as list |
| 035 | set strTitle to ("ファイル選択") as text |
| 036 | set strPrompt to ("ムービーファイルを選んでください") as text |
| 037 | tell application "SystemUIServer" |
| 038 | activate |
| 039 | set listAliasFilePath to (choose file with prompt (strPrompt) default location (aliasDesktopDirPath) of type (listUTI) with invisibles, showing package contents and multiple selections allowed) as list |
| 040 | end tell |
| 041 |
|
| 042 | #NSURLのArrayを作成して |
| 043 | set ocidFileURLArrayM to refMe's NSMutableArray's alloc()'s init() |
| 044 |
|
| 045 | repeat with itemAliasFilePath in listAliasFilePath |
| 046 | set aliasFilePath to itemAliasFilePath as alias |
| 047 | set strFilePath to (POSIX path of aliasFilePath) as text |
| 048 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
| 049 | set ocidFilePathStr to ocidFilePathStr's precomposedStringWithCanonicalMapping() |
| 050 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 051 | set ocidFilePath to ocidFilePath's stringByExpandingTildeInPath() |
| 052 | set ocidFilePathURL to (refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false)) |
| 053 | (ocidFileURLArrayM's addObject:(ocidFilePathURL)) |
| 054 | end repeat |
| 055 |
|
| 056 | #ソート |
| 057 | set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("path") ascending:(yes) selector:("localizedStandardCompare:") |
| 058 | set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor) |
| 059 | set ocidFileURLArrayS to ocidFileURLArrayM's sortedArrayUsingDescriptors:(ocidDescriptorArray) |
| 060 |
|
| 061 | #Arrayのアイテム数 |
| 062 | set numCntArray to ocidFileURLArrayS's |count|() |
| 063 |
|
| 064 | repeat with itemIntNo from 0 to (numCntArray - 1) by 1 |
| 065 | #開くムービーのエイリアス・パスをエイリアスリストから取得して |
| 066 | set ocidItemFileURL to (ocidFileURLArrayS's objectAtIndex:(itemIntNo)) |
| 067 | ###縦横PXサイズ取得 |
| 068 | set ocidOptionDict to refMe's NSMutableDictionary's alloc()'s init() |
| 069 | (ocidOptionDict's setObject:(true) forKey:(refMe's AVURLAssetPreferPreciseDurationAndTimingKey)) |
| 070 | (ocidOptionDict's setObject:(true) forKey:(refMe's AVURLAssetURLRequestAttributionKey)) |
| 071 | set ocidReadAsset to (refMe's AVURLAsset's alloc()'s initWithURL:(ocidItemFileURL) options:(ocidOptionDict)) |
| 072 | # |
| 073 | set ocidVideoAssetTrack to (ocidReadAsset's tracksWithMediaType:(refMe's AVMediaTypeVideo)) |
| 074 | set ocidReadAssetTrackArray to ocidReadAsset's tracks() |
| 075 | set ocidVideoTrack to ocidReadAssetTrackArray's firstObject() |
| 076 | if ocidVideoTrack = (missing value) then |
| 077 | log ocidFilePathURL's |path| as text |
| 078 | return "構造が不正なビデオがあります" |
| 079 | end if |
| 080 | #サイズを取得 |
| 081 | set sizeTrack to ocidVideoTrack's naturalSize() |
| 082 | set numWpx to sizeTrack's width() as integer |
| 083 | set numHpx to sizeTrack's height() as integer |
| 084 | |
| 085 | log numWpx |
| 086 | log numHpx |
| 087 | |
| 088 | end repeat |
| 089 |
|
| 090 |
|
| 091 | return |