
【ffmpeg】インストールヘルパ(ffmpeg.martin-riedl.de用)
| ソース | |
|---|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 004 | (* |
| 005 | 管理者権限不要の |
| 006 | ユーザーインストール |
| 007 | /Users/ユーザーID/Library/Application Support/bin/ffmpeg |
| 008 | に |
| 009 | インストールします |
| 010 | |
| 011 | ffmpegの公式リンクのバイナリーがインテル用なので |
| 012 | https://evermeet.cx/ffmpeg/ |
| 013 | ARM用にMAKEされている |
| 014 | ダウンロードサイトはドイツの『野良サイト』を利用しています |
| 015 | https://ffmpeg.martin-riedl.de/ |
| 016 | |
| 017 | 品質について私は保証しません(でも、まぁ大丈夫じゃないか?な?) |
| 018 | |
| 019 | 現在あるバイナリーはゴミ箱に入れてからダウンロードしますので |
| 020 | 置き換え・アップデートになります |
| 021 | |
| 022 | v1 初回作成 |
| 023 | v2 ffmepgのバージョンが上がったのでURLを更新した |
| 024 | v2.1 ffmepgのバージョンが上がったのでURLを更新した v8版 |
| 025 | 20250830 ffmpegのv8版 このffmpegはwhisper文字起こし機能を含んでいません |
| 026 | v2.1.1 ffmepgのバージョンが上がったのでURLを更新した v8.0.1版 |
| 027 | v2.2 リンボリックリンクによってバージョン管理できるようにした |
| 028 | v2.2.1 アトリビュートを削除しておくように変更 |
| 029 | |
| 030 | com.cocolog-nifty.quicktimer.icefloe *) |
| 031 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 032 | use AppleScript version "2.8" |
| 033 | use framework "Foundation" |
| 034 | use framework "AppKit" |
| 035 | use scripting additions |
| 036 | property refMe : a reference to current application |
| 037 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 038 | |
| 039 | ############################## |
| 040 | #【設定項目】 |
| 041 | #Version |
| 042 | set strVerSion to ("8.1") as text |
| 043 | #スナップショット=TRUE リリースビルド=FALSE |
| 044 | set boolSnap to true as boolean |
| 045 | |
| 046 | ############################## |
| 047 | #メタ文字 |
| 048 | set strLF to ("" & linefeed & "") as text |
| 049 | set strCR to ("" & return & "") as text |
| 050 | set strCRLF to ("" & return & linefeed & "") as text |
| 051 | set strSpace to ("" & space & "") as text |
| 052 | set strTab to ("" & tab & "") as text |
| 053 | ############################## |
| 054 | #インストールチェック |
| 055 | set refResponse to doChkInstall("ffmpeg") |
| 056 | if refResponse is false then |
| 057 | log "未インストール" & strCR & "インストールします" |
| 058 | else |
| 059 | if refResponse contains "Support/bin/ffmpeg" then |
| 060 | log "インストール済みです" & strCR & "アップデートします" |
| 061 | else |
| 062 | log "ローカルインストール済みです" & strCR & "処理を中止します" |
| 063 | return false |
| 064 | end if |
| 065 | end if |
| 066 | |
| 067 | ############################## |
| 068 | #ダウンロードサイト |
| 069 | set strURL to ("https://ffmpeg.martin-riedl.de") as text |
| 070 | set ocidURLString to refMe's NSString's stringWithString:(strURL) |
| 071 | set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString) |
| 072 | #NSDATA |
| 073 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
| 074 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error|:(reference) |
| 075 | if (last item of listResponse) = (missing value) then |
| 076 | log "initWithContentsOfURL 正常処理" |
| 077 | set ocidReadData to (first item of listResponse) |
| 078 | else if (item 2 of listResponse) ≠ (missing value) then |
| 079 | set strErrorNO to (last item of listResponse)'s code() as text |
| 080 | set strErrorMes to (last item of listResponse)'s localizedDescription() as text |
| 081 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 082 | return "initWithContentsOfURL エラーしました" & strErrorNO & strErrorMes |
| 083 | end if |
| 084 | #XML |
| 085 | set ocidOption to (refMe's NSXMLNodePreserveAll) + (refMe's NSXMLDocumentTidyHTML) |
| 086 | set listResponse to refMe's NSXMLDocument's alloc()'s initWithData:(ocidReadData) options:(ocidOption) |error|:(reference) |
| 087 | set ocidReadXML to (first item of listResponse) |
| 088 | |
| 089 | set ocidRoorElement to ocidReadXML's rootElement() |
| 090 | ######################################## |
| 091 | #インストールURL (Apple Silicon/arm64) |
| 092 | ######################################## |
| 093 | set listResponse to (ocidRoorElement's nodesForXPath:("//a[contains(@href, 'macos/arm64') and contains(text(), 'FFmpeg (ZIP)')]") |error|:(reference)) |
| 094 | if boolSnap is true then |
| 095 | set ocidAelement to (first item of listResponse)'s firstObject() |
| 096 | else |
| 097 | set ocidAelement to (first item of listResponse)'s lastObject() |
| 098 | end if |
| 099 | if ocidAelement = (missing value) then |
| 100 | set strZip1 to ("https://ffmpeg.martin-riedl.de/download/macos/arm64/1774549676_8.1/ffmpeg.zip") as text |
| 101 | else |
| 102 | set ocidAttar to ocidAelement's attributeForName:("href") |
| 103 | set ocidZip1 to ocidAttar's stringValue() |
| 104 | set ocidZip1URL to ocidURLString's stringByAppendingString:(ocidZip1) |
| 105 | set strZip1 to ocidZip1URL as text |
| 106 | end if |
| 107 | log strZip1 as text |
| 108 | ################################### |
| 109 | set listResponse to (ocidRoorElement's nodesForXPath:("//a[contains(@href, 'macos/arm64') and contains(text(), 'FFprobe (ZIP)')]") |error|:(reference)) |
| 110 | if boolSnap is true then |
| 111 | set ocidAelement to (first item of listResponse)'s firstObject() |
| 112 | else |
| 113 | set ocidAelement to (first item of listResponse)'s lastObject() |
| 114 | end if |
| 115 | if ocidAelement = (missing value) then |
| 116 | set strZip2 to ("https://ffmpeg.martin-riedl.de/download/macos/arm64/1774549676_8.1/ffprobe.zip") as text |
| 117 | else |
| 118 | set ocidAttar to ocidAelement's attributeForName:("href") |
| 119 | set ocidZip2 to ocidAttar's stringValue() |
| 120 | set ocidZip2URL to ocidURLString's stringByAppendingString:(ocidZip2) |
| 121 | set strZip2 to ocidZip2URL as text |
| 122 | end if |
| 123 | log strZip2 as text |
| 124 | ################################### |
| 125 | set listResponse to (ocidRoorElement's nodesForXPath:("//a[contains(@href, 'macos/arm64') and contains(text(), 'FFplay (ZIP)')]") |error|:(reference)) |
| 126 | if boolSnap is true then |
| 127 | set ocidAelement to (first item of listResponse)'s firstObject() |
| 128 | else |
| 129 | set ocidAelement to (first item of listResponse)'s lastObject() |
| 130 | end if |
| 131 | if ocidAelement = (missing value) then |
| 132 | set strZip3 to ("https://ffmpeg.martin-riedl.de/download/macos/arm64/1774549676_8.1/ffplay.zip") as text |
| 133 | else |
| 134 | set ocidAttar to ocidAelement's attributeForName:("href") |
| 135 | set ocidZip3 to ocidAttar's stringValue() |
| 136 | set ocidZip3URL to ocidURLString's stringByAppendingString:(ocidZip3) |
| 137 | set strZip3 to ocidZip3URL as text |
| 138 | end if |
| 139 | log strZip3 as text |
| 140 | |
| 141 | |
| 142 | ################################### |
| 143 | #リストに |
| 144 | set listURL to {strZip1, strZip2, strZip3} as list |
| 145 | |
| 146 | #保存先 |
| 147 | set ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser() |
| 148 | set strSetSubePath to ("Library/Application Support/bin/ffmpeg/" & strVerSion & "") as text |
| 149 | set ocidDistDirPathURL to ocidHomeDirURL's URLByAppendingPathComponent:(strSetSubePath) isDirectory:(true) |
| 150 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init() |
| 151 | ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions) |
| 152 | set ocidDistDirPath to ocidDistDirPathURL's |path|() |
| 153 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidDistDirPath) isDirectory:(true) |
| 154 | if boolDirExists is false then |
| 155 | set listDone to appFileManager's createDirectoryAtURL:(ocidDistDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference) |
| 156 | if (item 1 of listDone) is false then |
| 157 | set strErrorNO to (item 2 of listDone)'s code() as text |
| 158 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
| 159 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 160 | log "createDirectoryAtURL エラーしました" & strErrorNO & strErrorMes |
| 161 | return false |
| 162 | end if |
| 163 | end if |
| 164 | #解凍するためのレンポラリー(再起動時に自動で削除されます) |
| 165 | set ocidTempDirURL to appFileManager's temporaryDirectory() |
| 166 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
| 167 | set ocidUUIDString to ocidUUID's UUIDString |
| 168 | set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true) |
| 169 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init() |
| 170 | ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions) |
| 171 | set ocidMakeDirPath to ocidSaveDirPathURL's |path|() |
| 172 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidMakeDirPath) isDirectory:(true) |
| 173 | if boolDirExists is false then |
| 174 | set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference) |
| 175 | if (item 1 of listDone) is false then |
| 176 | set strErrorNO to (item 2 of listDone)'s code() as text |
| 177 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
| 178 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 179 | log "createDirectoryAtURL エラーしました" & strErrorNO & strErrorMes |
| 180 | return false |
| 181 | end if |
| 182 | end if |
| 183 | |
| 184 | #順番に処理 |
| 185 | repeat with itemURL in listURL |
| 186 | # |
| 187 | set ocidSourceFilePath to (refMe's NSString's stringWithString:(itemURL)) |
| 188 | set ocidSourceFilePathURL to (refMe's NSURL's alloc()'s initWithString:(ocidSourceFilePath)) |
| 189 | set ocidFileName to ocidSourceFilePathURL's lastPathComponent() |
| 190 | # |
| 191 | set ocidZipFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false)) |
| 192 | set ocidZipFilePath to ocidZipFilePathURL's |path|() |
| 193 | ##NSDATAダウンロード |
| 194 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
| 195 | set listResponse to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidSourceFilePathURL) options:(ocidOption) |error|:(reference)) |
| 196 | if (item 2 of listResponse) = (missing value) then |
| 197 | log "initWithContentsOfURL 正常処理" |
| 198 | set ocidSaveData to (item 1 of listResponse) |
| 199 | else if (item 2 of listResponse) ≠ (missing value) then |
| 200 | set strErrorNO to (item 2 of listResponse)'s code() as text |
| 201 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
| 202 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 203 | log ocidSource1FilePathURL's |path|() as text |
| 204 | return "initWithContentsOfURL エラーしました" & strErrorNO & strErrorMes |
| 205 | end if |
| 206 | |
| 207 | ##NSDATAテンポラリーへ保存 |
| 208 | set ocidOption to (refMe's NSDataWritingAtomic) |
| 209 | set listDone to (ocidSaveData's writeToURL:(ocidZipFilePathURL) options:(ocidOption) |error|:(reference)) |
| 210 | if (item 1 of listDone) is true then |
| 211 | log "writeToURL 正常処理" |
| 212 | else if (item 2 of listDone) ≠ (missing value) then |
| 213 | set strErrorNO to (item 2 of listDone)'s code() as text |
| 214 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
| 215 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 216 | log ocidZip1FilePathURL's |path|() as text |
| 217 | return "writeToURL エラーしました" & strErrorNO & strErrorMes |
| 218 | end if |
| 219 | #古いバイナリーはゴミ箱に |
| 220 | set ocidFileName to ocidFileName's stringByDeletingPathExtension() |
| 221 | set ocidDistFilePathURL to (ocidDistDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false)) |
| 222 | set listDone to (appFileManager's trashItemAtURL:(ocidDistFilePathURL) resultingItemURL:(missing value) |error|:(reference)) |
| 223 | ######################## |
| 224 | #解凍 |
| 225 | set strCmd to ("/usr/bin/unzip \"" & ocidZipFilePath & "\" -d \"" & ocidDistDirPath & "\"") as text |
| 226 | set strResponse to doZshShellScript(strCmd) |
| 227 | if strResponse is false then |
| 228 | return "解凍に失敗しました" |
| 229 | end if |
| 230 | end repeat |
| 231 | |
| 232 | ######################## |
| 233 | ##シンボリックリンク処理 |
| 234 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 235 | set ocidAppSupportDirPathURL to ocidURLsArray's firstObject() |
| 236 | set ocidExecDirPathURL to ocidAppSupportDirPathURL's URLByAppendingPathComponent:("bin/ffmpeg") isDirectory:(true) |
| 237 | |
| 238 | set listBinName to {"ffmpeg", "ffplay", "ffprobe"} as list |
| 239 | |
| 240 | repeat with itemBinName in listBinName |
| 241 | #シンボリックリンクを |
| 242 | set ocidLinkFilePathURL to (ocidExecDirPathURL's URLByAppendingPathComponent:(itemBinName) isDirectory:(false)) |
| 243 | #ゴミ箱に入れて |
| 244 | set listDone to (appFileManager's trashItemAtURL:(ocidLinkFilePathURL) resultingItemURL:(ocidLinkFilePathURL) |error|:(reference)) |
| 245 | #バイナリー |
| 246 | set strSubePath to ("" & strVerSion & "/" & itemBinName & "") as text |
| 247 | set ocidBinFilePathURL to (ocidExecDirPathURL's URLByAppendingPathComponent:(strSubePath) isDirectory:(false)) |
| 248 | set listDone to (appFileManager's createSymbolicLinkAtURL:(ocidLinkFilePathURL) withDestinationURL:(ocidBinFilePathURL) |error|:(reference)) |
| 249 | set strBinFilePath to ocidBinFilePathURL's |path|() as text |
| 250 | do shell script ("/usr/bin/xattr -c '" & strBinFilePath & "'") |
| 251 | end repeat |
| 252 | |
| 253 | ######################## |
| 254 | #解凍前のファイルをゴミ箱へ |
| 255 | set listDone to (appFileManager's trashItemAtURL:(ocidSaveDirPathURL) resultingItemURL:(ocidSaveDirPathURL) |error|:(reference)) |
| 256 | |
| 257 | |
| 258 | ######################## |
| 259 | #保存先を開く |
| 260 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
| 261 | set boolDone to appSharedWorkspace's openURL:(ocidDistDirPathURL) |
| 262 | log "処理終了" |
| 263 | return boolDone |
| 264 | |
| 265 | |
| 266 | |
| 267 | ########################## |
| 268 | # 【N】ZSH 実行 |
| 269 | to doZshShellScript(argCommandText) |
| 270 | set strCommandText to argCommandText as text |
| 271 | log "コマンド開始" & return & strCommandText & return |
| 272 | set strExec to ("/bin/zsh -c '" & strCommandText & "'") as text |
| 273 | ########## |
| 274 | #コマンド実行 |
| 275 | try |
| 276 | set strResnponse to (do shell script strExec) as text |
| 277 | log "コマンド終了" |
| 278 | on error |
| 279 | return false |
| 280 | end try |
| 281 | return strResnponse |
| 282 | end doZshShellScript |
| 283 | |
| 284 | |
| 285 | ############################## |
| 286 | #すでにインストール済みで |
| 287 | #ユーザーがRC設定している場合は |
| 288 | #パスが通るのでこれがエラーにならない |
| 289 | to doChkInstall(argBinName) |
| 290 | try |
| 291 | #ランチD |
| 292 | set strCmd to ("/bin/zsh -c '/usr/bin/which " & argBinName & "'") |
| 293 | set strResponse to (do shell script strCmd) as text |
| 294 | return strResponse |
| 295 | on error strErrMsg number numErrNo |
| 296 | set strCmd to ("/bin/zsh -c \"[[ -f '/usr/local/bin/" & argBinName & "' ]] && echo \\\"TRUE\\\" || echo \\\"FALSE\\\"\"") |
| 297 | set strResponse to (do shell script strCmd) as text |
| 298 | if strResponse is "FALSE" then |
| 299 | return false |
| 300 | else if strResponse is "TRUE" then |
| 301 | set strResponse to ("/usr/local/bin/" & argBinName & "") |
| 302 | end if |
| 303 | end try |
| 304 | end doChkInstall |
| AppleScriptで生成しました | |
| ソース | |
|---|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 004 | (* |
| 005 | 管理者権限不要の |
| 006 | ユーザーインストール |
| 007 | /Users/ユーザーID/Library/Application Support/bin/ffmpeg |
| 008 | に |
| 009 | インストールします |
| 010 | |
| 011 | ffmpegの公式リンクのバイナリーがインテル用なので |
| 012 | https://evermeet.cx/ffmpeg/ |
| 013 | ARM用にMAKEされている |
| 014 | ダウンロードサイトはドイツの『野良サイト』を利用しています |
| 015 | https://ffmpeg.martin-riedl.de/ |
| 016 | |
| 017 | 品質について私は保証しません(でも、まぁ大丈夫じゃないか?な?) |
| 018 | |
| 019 | 現在あるバイナリーはゴミ箱に入れてからダウンロードしますので |
| 020 | 置き換え・アップデートになります |
| 021 | |
| 022 | v1 初回作成 |
| 023 | v2 ffmepgのバージョンが上がったのでURLを更新した |
| 024 | v2.1 ffmepgのバージョンが上がったのでURLを更新した v8版 |
| 025 | 20250830 ffmpegのv8版 このffmpegはwhisper文字起こし機能を含んでいません |
| 026 | v2.1.1 ffmepgのバージョンが上がったのでURLを更新した v8.0.1版 |
| 027 | v2.2 リンボリックリンクによってバージョン管理できるようにした |
| 028 | v2.2.1 アトリビュートを削除しておくように変更 |
| 029 | |
| 030 | com.cocolog-nifty.quicktimer.icefloe *) |
| 031 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 032 | use AppleScript version "2.8" |
| 033 | use framework "Foundation" |
| 034 | use framework "AppKit" |
| 035 | use scripting additions |
| 036 | property refMe : a reference to current application |
| 037 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 038 | |
| 039 | ############################## |
| 040 | #【設定項目】 |
| 041 | #Version |
| 042 | set strVerSion to ("8.1") as text |
| 043 | #スナップショット=TRUE リリースビルド=FALSE |
| 044 | set boolSnap to true as boolean |
| 045 | |
| 046 | ############################## |
| 047 | #メタ文字 |
| 048 | set strLF to ("" & linefeed & "") as text |
| 049 | set strCR to ("" & return & "") as text |
| 050 | set strCRLF to ("" & return & linefeed & "") as text |
| 051 | set strSpace to ("" & space & "") as text |
| 052 | set strTab to ("" & tab & "") as text |
| 053 | ############################## |
| 054 | #インストールチェック |
| 055 | set refResponse to doChkInstall("ffmpeg") |
| 056 | if refResponse is false then |
| 057 | log "未インストール" & strCR & "インストールします" |
| 058 | else |
| 059 | if refResponse contains "Support/bin/ffmpeg" then |
| 060 | log "インストール済みです" & strCR & "アップデートします" |
| 061 | else |
| 062 | log "ローカルインストール済みです" & strCR & "処理を中止します" |
| 063 | return false |
| 064 | end if |
| 065 | end if |
| 066 | |
| 067 | ############################## |
| 068 | #ダウンロードサイト |
| 069 | set strURL to ("https://ffmpeg.martin-riedl.de") as text |
| 070 | set ocidURLString to refMe's NSString's stringWithString:(strURL) |
| 071 | set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString) |
| 072 | #NSDATA |
| 073 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
| 074 | set listResponse to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error|:(reference) |
| 075 | if (last item of listResponse) = (missing value) then |
| 076 | log "initWithContentsOfURL 正常処理" |
| 077 | set ocidReadData to (first item of listResponse) |
| 078 | else if (item 2 of listResponse) ≠ (missing value) then |
| 079 | set strErrorNO to (last item of listResponse)'s code() as text |
| 080 | set strErrorMes to (last item of listResponse)'s localizedDescription() as text |
| 081 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 082 | return "initWithContentsOfURL エラーしました" & strErrorNO & strErrorMes |
| 083 | end if |
| 084 | #XML |
| 085 | set ocidOption to (refMe's NSXMLNodePreserveAll) + (refMe's NSXMLDocumentTidyHTML) |
| 086 | set listResponse to refMe's NSXMLDocument's alloc()'s initWithData:(ocidReadData) options:(ocidOption) |error|:(reference) |
| 087 | set ocidReadXML to (first item of listResponse) |
| 088 | |
| 089 | set ocidRoorElement to ocidReadXML's rootElement() |
| 090 | ######################################## |
| 091 | #インストールURL (Apple Silicon/arm64) |
| 092 | ######################################## |
| 093 | set listResponse to (ocidRoorElement's nodesForXPath:("//a[contains(@href, 'macos/arm64') and contains(text(), 'FFmpeg (ZIP)')]") |error|:(reference)) |
| 094 | if boolSnap is true then |
| 095 | set ocidAelement to (first item of listResponse)'s firstObject() |
| 096 | else |
| 097 | set ocidAelement to (first item of listResponse)'s lastObject() |
| 098 | end if |
| 099 | if ocidAelement = (missing value) then |
| 100 | set strZip1 to ("https://ffmpeg.martin-riedl.de/download/macos/arm64/1766430132_8.0.1/ffmpeg.zip") as text |
| 101 | else |
| 102 | set ocidAttar to ocidAelement's attributeForName:("href") |
| 103 | set ocidZip1 to ocidAttar's stringValue() |
| 104 | set ocidZip1URL to ocidURLString's stringByAppendingString:(ocidZip1) |
| 105 | set strZip1 to ocidZip1URL as text |
| 106 | end if |
| 107 | log strZip1 as text |
| 108 | ################################### |
| 109 | set listResponse to (ocidRoorElement's nodesForXPath:("//a[contains(@href, 'macos/arm64') and contains(text(), 'FFprobe (ZIP)')]") |error|:(reference)) |
| 110 | if boolSnap is true then |
| 111 | set ocidAelement to (first item of listResponse)'s firstObject() |
| 112 | else |
| 113 | set ocidAelement to (first item of listResponse)'s lastObject() |
| 114 | end if |
| 115 | if ocidAelement = (missing value) then |
| 116 | set strZip2 to ("https://ffmpeg.martin-riedl.de/download/macos/arm64/1766430132_8.0.1/ffprobe.zip") as text |
| 117 | else |
| 118 | set ocidAttar to ocidAelement's attributeForName:("href") |
| 119 | set ocidZip2 to ocidAttar's stringValue() |
| 120 | set ocidZip2URL to ocidURLString's stringByAppendingString:(ocidZip2) |
| 121 | set strZip2 to ocidZip2URL as text |
| 122 | end if |
| 123 | log strZip2 as text |
| 124 | ################################### |
| 125 | set listResponse to (ocidRoorElement's nodesForXPath:("//a[contains(@href, 'macos/arm64') and contains(text(), 'FFplay (ZIP)')]") |error|:(reference)) |
| 126 | if boolSnap is true then |
| 127 | set ocidAelement to (first item of listResponse)'s firstObject() |
| 128 | else |
| 129 | set ocidAelement to (first item of listResponse)'s lastObject() |
| 130 | end if |
| 131 | if ocidAelement = (missing value) then |
| 132 | set strZip3 to ("https://ffmpeg.martin-riedl.de/download/macos/arm64/1766430132_8.0.1/ffplay.zip") as text |
| 133 | else |
| 134 | set ocidAttar to ocidAelement's attributeForName:("href") |
| 135 | set ocidZip3 to ocidAttar's stringValue() |
| 136 | set ocidZip3URL to ocidURLString's stringByAppendingString:(ocidZip3) |
| 137 | set strZip3 to ocidZip3URL as text |
| 138 | end if |
| 139 | log strZip3 as text |
| 140 | |
| 141 | |
| 142 | ################################### |
| 143 | #リストに |
| 144 | set listURL to {strZip1, strZip2, strZip3} as list |
| 145 | |
| 146 | #保存先 |
| 147 | set ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser() |
| 148 | set strSetSubePath to ("Library/Application Support/bin/ffmpeg/" & strVerSion & "") as text |
| 149 | set ocidDistDirPathURL to ocidHomeDirURL's URLByAppendingPathComponent:(strSetSubePath) isDirectory:(true) |
| 150 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init() |
| 151 | ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions) |
| 152 | set ocidDistDirPath to ocidDistDirPathURL's |path|() |
| 153 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidDistDirPath) isDirectory:(true) |
| 154 | if boolDirExists is false then |
| 155 | set listDone to appFileManager's createDirectoryAtURL:(ocidDistDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference) |
| 156 | if (item 1 of listDone) is false then |
| 157 | set strErrorNO to (item 2 of listDone)'s code() as text |
| 158 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
| 159 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 160 | log "createDirectoryAtURL エラーしました" & strErrorNO & strErrorMes |
| 161 | return false |
| 162 | end if |
| 163 | end if |
| 164 | #解凍するためのレンポラリー(再起動時に自動で削除されます) |
| 165 | set ocidTempDirURL to appFileManager's temporaryDirectory() |
| 166 | set ocidUUID to refMe's NSUUID's alloc()'s init() |
| 167 | set ocidUUIDString to ocidUUID's UUIDString |
| 168 | set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true) |
| 169 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init() |
| 170 | ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions) |
| 171 | set ocidMakeDirPath to ocidSaveDirPathURL's |path|() |
| 172 | set boolDirExists to appFileManager's fileExistsAtPath:(ocidMakeDirPath) isDirectory:(true) |
| 173 | if boolDirExists is false then |
| 174 | set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference) |
| 175 | if (item 1 of listDone) is false then |
| 176 | set strErrorNO to (item 2 of listDone)'s code() as text |
| 177 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
| 178 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 179 | log "createDirectoryAtURL エラーしました" & strErrorNO & strErrorMes |
| 180 | return false |
| 181 | end if |
| 182 | end if |
| 183 | |
| 184 | #順番に処理 |
| 185 | repeat with itemURL in listURL |
| 186 | # |
| 187 | set ocidSourceFilePath to (refMe's NSString's stringWithString:(itemURL)) |
| 188 | set ocidSourceFilePathURL to (refMe's NSURL's alloc()'s initWithString:(ocidSourceFilePath)) |
| 189 | set ocidFileName to ocidSourceFilePathURL's lastPathComponent() |
| 190 | # |
| 191 | set ocidZipFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false)) |
| 192 | set ocidZipFilePath to ocidZipFilePathURL's |path|() |
| 193 | ##NSDATAダウンロード |
| 194 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
| 195 | set listResponse to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidSourceFilePathURL) options:(ocidOption) |error|:(reference)) |
| 196 | if (item 2 of listResponse) = (missing value) then |
| 197 | log "initWithContentsOfURL 正常処理" |
| 198 | set ocidSaveData to (item 1 of listResponse) |
| 199 | else if (item 2 of listResponse) ≠ (missing value) then |
| 200 | set strErrorNO to (item 2 of listResponse)'s code() as text |
| 201 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
| 202 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 203 | log ocidSource1FilePathURL's |path|() as text |
| 204 | return "initWithContentsOfURL エラーしました" & strErrorNO & strErrorMes |
| 205 | end if |
| 206 | |
| 207 | ##NSDATAテンポラリーへ保存 |
| 208 | set ocidOption to (refMe's NSDataWritingAtomic) |
| 209 | set listDone to (ocidSaveData's writeToURL:(ocidZipFilePathURL) options:(ocidOption) |error|:(reference)) |
| 210 | if (item 1 of listDone) is true then |
| 211 | log "writeToURL 正常処理" |
| 212 | else if (item 2 of listDone) ≠ (missing value) then |
| 213 | set strErrorNO to (item 2 of listDone)'s code() as text |
| 214 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
| 215 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 216 | log ocidZip1FilePathURL's |path|() as text |
| 217 | return "writeToURL エラーしました" & strErrorNO & strErrorMes |
| 218 | end if |
| 219 | #古いバイナリーはゴミ箱に |
| 220 | set ocidFileName to ocidFileName's stringByDeletingPathExtension() |
| 221 | set ocidDistFilePathURL to (ocidDistDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false)) |
| 222 | set listDone to (appFileManager's trashItemAtURL:(ocidDistFilePathURL) resultingItemURL:(missing value) |error|:(reference)) |
| 223 | ######################## |
| 224 | #解凍 |
| 225 | set strCmd to ("/usr/bin/unzip \"" & ocidZipFilePath & "\" -d \"" & ocidDistDirPath & "\"") as text |
| 226 | set strResponse to doZshShellScript(strCmd) |
| 227 | if strResponse is false then |
| 228 | return "解凍に失敗しました" |
| 229 | end if |
| 230 | end repeat |
| 231 | |
| 232 | ######################## |
| 233 | ##シンボリックリンク処理 |
| 234 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 235 | set ocidAppSupportDirPathURL to ocidURLsArray's firstObject() |
| 236 | set ocidExecDirPathURL to ocidAppSupportDirPathURL's URLByAppendingPathComponent:("bin/ffmpeg") isDirectory:(true) |
| 237 | |
| 238 | set listBinName to {"ffmpeg", "ffplay", "ffprobe"} as list |
| 239 | |
| 240 | repeat with itemBinName in listBinName |
| 241 | #シンボリックリンクを |
| 242 | set ocidLinkFilePathURL to (ocidExecDirPathURL's URLByAppendingPathComponent:(itemBinName) isDirectory:(false)) |
| 243 | #ゴミ箱に入れて |
| 244 | set listDone to (appFileManager's trashItemAtURL:(ocidLinkFilePathURL) resultingItemURL:(ocidLinkFilePathURL) |error|:(reference)) |
| 245 | #バイナリー |
| 246 | set strSubePath to ("" & strVerSion & "/" & itemBinName & "") as text |
| 247 | set ocidBinFilePathURL to (ocidExecDirPathURL's URLByAppendingPathComponent:(strSubePath) isDirectory:(false)) |
| 248 | set listDone to (appFileManager's createSymbolicLinkAtURL:(ocidLinkFilePathURL) withDestinationURL:(ocidBinFilePathURL) |error|:(reference)) |
| 249 | set strBinFilePath to ocidBinFilePathURL's |path|() as text |
| 250 | do shell script ("/usr/bin/xattr -c '" & strBinFilePath & "'") |
| 251 | end repeat |
| 252 | |
| 253 | ######################## |
| 254 | #解凍前のファイルをゴミ箱へ |
| 255 | set listDone to (appFileManager's trashItemAtURL:(ocidSaveDirPathURL) resultingItemURL:(ocidSaveDirPathURL) |error|:(reference)) |
| 256 | |
| 257 | |
| 258 | ######################## |
| 259 | #保存先を開く |
| 260 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
| 261 | set boolDone to appSharedWorkspace's openURL:(ocidDistDirPathURL) |
| 262 | log "処理終了" |
| 263 | return boolDone |
| 264 | |
| 265 | |
| 266 | |
| 267 | ########################## |
| 268 | # 【N】ZSH 実行 |
| 269 | to doZshShellScript(argCommandText) |
| 270 | set strCommandText to argCommandText as text |
| 271 | log "コマンド開始" & return & strCommandText & return |
| 272 | set strExec to ("/bin/zsh -c '" & strCommandText & "'") as text |
| 273 | ########## |
| 274 | #コマンド実行 |
| 275 | try |
| 276 | set strResnponse to (do shell script strExec) as text |
| 277 | log "コマンド終了" |
| 278 | on error |
| 279 | return false |
| 280 | end try |
| 281 | return strResnponse |
| 282 | end doZshShellScript |
| 283 | |
| 284 | |
| 285 | ############################## |
| 286 | #すでにインストール済みで |
| 287 | #ユーザーがRC設定している場合は |
| 288 | #パスが通るのでこれがエラーにならない |
| 289 | to doChkInstall(argBinName) |
| 290 | try |
| 291 | #ランチD |
| 292 | set strCmd to ("/bin/zsh -c '/usr/bin/which " & argBinName & "'") |
| 293 | set strResponse to (do shell script strCmd) as text |
| 294 | return strResponse |
| 295 | on error strErrMsg number numErrNo |
| 296 | set strCmd to ("/bin/zsh -c \"[[ -f '/usr/local/bin/" & argBinName & "' ]] && echo \\\"TRUE\\\" || echo \\\"FALSE\\\"\"") |
| 297 | set strResponse to (do shell script strCmd) as text |
| 298 | if strResponse is "FALSE" then |
| 299 | return false |
| 300 | else if strResponse is "TRUE" then |
| 301 | set strResponse to ("/usr/local/bin/" & argBinName & "") |
| 302 | end if |
| 303 | end try |
| 304 | end doChkInstall |
| AppleScriptで生成しました | |
