« QRバーコードデコード (QRコードファイルの内容をテキストにする) ちょっと修正 | トップページ | [python3]フォントのファミリー名のフォルダを作って中にフォント入れる(フォントファイル整理用) »

[mediaInfo] mediaInfoのHTML出力


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
# mediainfoのHTML出力をブラウザに表示
# mediainfoのインストール付きです
#mediainfoをインストールしたくない人は実行しないでください
# 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 "AppKit"
use scripting additions
property refMe : a reference to current application

#############################
# mediaInfoインストールチェック
log doChkBinInstall()

#起動時に削除される項目
set ocidSaveDirPathURL to doMakeTmpDir()

#############################
# ダイアログ
doActivate()
set appFileManager to refMe's NSFileManager's defaultManager()
# デフォルトロケーション
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.item"}
set strMes to ("ファイルを選んでください") as text
set strPrompt to ("ファイルを選んでください") as text
try
  ### ファイル選択時
  set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDefaultLocation of type listUTI with invisibles, multiple selections allowed and showing package contents) as list
on error
log "エラーしました"
return "エラーしました"
end try
if listAliasFilePath is {} then
return "選んでください"
end if


repeat with itemAliasFilePath in listAliasFilePath
  set strFilePath to POSIX path of itemAliasFilePath as text
  set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath))
  set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
  #
  set ocidFileName to (ocidFilePath's lastPathComponent())
  set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName))
  set ocidSaveFilePathURL to (ocidSaveFilePathURL's URLByAppendingPathExtension:("html"))
  set strSaveFilePath to ocidSaveFilePathURL's |path| as text
  #
  set strCommandText to ("$HOME/bin/mediaInfo/mediainfo \"" & strFilePath & "\" --Output=HTML > \"" & strSaveFilePath & "\"") as text
do shell script strCommandText
  #
  set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
  tell application "Finder"
    
open location aliasSaveFilePath
  end tell
  
end repeat


to doActivate()
  #############################
  ###ダイアログを前面に出す
  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
end doActivate


to doMakeTmpDir()
  #############################
  set appFileManager to refMe's NSFileManager's defaultManager()
  #起動時に削除される項目
  set ocidTempDirURL to appFileManager's temporaryDirectory()
  set ocidUUID to refMe's NSUUID's alloc()'s init()
  set ocidUUIDString to ocidUUID's UUIDString
  set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true)
  set strSaveDirPath to (ocidSaveDirPathURL's |path|) as text
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
  set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
return ocidSaveDirPathURL
end doMakeTmpDir




to doChkBinInstall()
  #####################
  set appFileManager to refMe's NSFileManager's defaultManager()
  ###インストールチェック(システム)
  set strDefaultPath to ("/usr/local/bin/mediaInfo") as text
  set ocidDefaultPathStr to refMe's NSString's stringWithString:(strDefaultPath)
  set ocidDefaultPath to ocidDefaultPathStr's stringByStandardizingPath()
  set boolExists to appFileManager's fileExistsAtPath:(ocidDefaultPath) isDirectory:(false)
  if boolExists = true then
    set strCommandText to ("/bin/mkdir -p $HOME/bin/mediaInfo") as text
do shell script strCommandText
    set strCommandText to ("/bin/chmod 700 $HOME/bin") as text
do shell script strCommandText
    set strCommandText to ("/bin/ln -s \"" & strDefaultPath & "\" $HOME/bin/mediaInfo") as text
do shell script strCommandText
return "インストール済みなので処理しない"
  else if boolExists = false then
    ###インストールチェック(ユーザー)
    set strDefaultPath to ("~/bin/mediaInfo/mediaInfo") as text
    set ocidDefaultPathStr to refMe's NSString's stringWithString:(strDefaultPath)
    set ocidDefaultPath to ocidDefaultPathStr's stringByStandardizingPath()
    set boolExists to appFileManager's fileExistsAtPath:(ocidDefaultPath) isDirectory:(false)
    if boolExists = true then
log "インストール済み"
    else if boolExists = false then
log "インストールします"
return doInstall()
    end if
  end if
end doChkBinInstall



to doInstall()
  #####################
  set appFileManager to refMe's NSFileManager's defaultManager()
  ###設定項目
  set strURL to ("https://mediaarea.net/download/binary/mediainfo/24.01.1/MediaInfo_CLI_24.01.1_Mac.dmg") as text
  set strInstallDirName to ("mediaInfo") as text
  #####################
  ###インストール先確保
  set ocidUserName to refMe's NSUserName()
  set ocidHomeDirURL to appFileManager's homeDirectoryForUser:(ocidUserName)
  set ocidBinDirPathURL to ocidHomeDirURL's URLByAppendingPathComponent:("bin") isDirectory:(true)
  set ocidInstallDirPathURL to ocidBinDirPathURL's URLByAppendingPathComponent:(strInstallDirName) isDirectory:(true)
  ###
  set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidInstallDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  #####################
  ###ダウンロードディレクトリ
  set ocidTempDirURL to appFileManager's temporaryDirectory()
  set ocidUUID to refMe's NSUUID's alloc()'s init()
  set ocidUUIDString to ocidUUID's UUIDString
  set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true)
  set strSaveDirPath to ocidSaveDirPathURL's |path| as text
  ###
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  #####################
  #ダウンロードするファイル名を確定させる
  set strCommandText to ("/usr/bin/curl -s -L -I -o /dev/null -w '%{url_effective}' \"" & strURL & "\" | /usr/bin/rev | /usr/bin/cut -d'/' -f1 | /usr/bin/rev") as text
  set strInstallerFileName to (do shell script strCommandText) as text
  #
  set ocidInstallerFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strInstallerFileName) isDirectory:(false)
  set strInstallerFilePath to (ocidInstallerFilePathURL's |path|) as text
  #####################
  #ダウンロード
  set strCommandText to ("/usr/bin/curl -L -o \"" & strInstallerFilePath & "\" \"" & strURL & "\" --http1.1 --connect-timeout 20") as text
do shell script strCommandText
  #####################
  #DMGをシャドウでマウント
  #マウントポイントを作成
  set ocidMountPointDirPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("MountPoint/DmgMount") isDirectory:(true)
  set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidMountPointDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
  set strMountPointDirPath to (ocidMountPointDirPathURL's |path|) as text
  #マウント
  set strCommandText to ("/usr/bin/hdiutil attach \"" & strInstallerFilePath & "\" -noverify -nobrowse -noautoopen -mountpoint \"" & strMountPointDirPath & "\"") as text
do shell script strCommandText
  #####################
  #マウントされたディスクからPKGのパスを取得
  set ocidOption to (refMe's NSDirectoryEnumerationSkipsSubdirectoryDescendants)
  set ocidPropertiesForKeysArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidPropertiesForKeysArray's addObject:(refMe's NSURLNameKey)
ocidPropertiesForKeysArray's addObject:(refMe's NSURLPathKey)
  set listDone to appFileManager's contentsOfDirectoryAtURL:(ocidMountPointDirPathURL) includingPropertiesForKeys:(ocidPropertiesForKeysArray) options:(ocidOption) |error|:(reference)
  set ocidContentsURLArray to (item 1 of listDone)
  repeat with itemArray in ocidContentsURLArray
    #
    set strExtension to itemArray's pathExtension() as text
    if strExtension is "pkg" then
      set ocidPkgFilePathURL to itemArray
      exit repeat
    end if
  end repeat
  ##
  set strPkgFilePathURL to ocidPkgFilePathURL's |path| as text
  #####################
  set ocidExpandDirPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("Expand") isDirectory:(true)
  set strExpandDirPath to (ocidExpandDirPathURL's |path|) as text
  #PKGを解凍
  set theComandText to ("/usr/sbin/pkgutil --expand \"" & strPkgFilePathURL & "\" \"" & strExpandDirPath & "\"") as text
do shell script theComandText
  #####################
  #ディスクをアンマウント
  set theComandText to ("/usr/bin/hdiutil detach \"" & strMountPointDirPath & "\" -force") as text
do shell script theComandText
  #####################
  set ocidPayloadFilePathURL to ocidExpandDirPathURL's URLByAppendingPathComponent:("Payload") isDirectory:(true)
  set strPayloadFilePath to (ocidPayloadFilePathURL's |path|) as text
  #
  set ocidExtractDirPathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("Extract") isDirectory:(true)
  set strExtractDirPath to (ocidExtractDirPathURL's |path|) as text
  #Payloadを解凍
  set theComandText to ("/usr/bin/ditto -xz \"" & strPayloadFilePath & "\" \"" & strExtractDirPath & "\"") as text
do shell script theComandText
  #####################
  #ここからは案件毎にカスタマイズ
  set ocidOriginalPathURL to ocidExtractDirPathURL's URLByAppendingPathComponent:("usr/local/bin/mediainfo") isDirectory:(false)
  set strOriginalPath to (ocidOriginalPathURL's |path|) as text
  #
  set ocidBinDistPathURL to ocidInstallDirPathURL's URLByAppendingPathComponent:("mediainfo") isDirectory:(false)
  set strBinDistPath to (ocidBinDistPathURL's |path|) as text
  #
  try
    set theComandText to ("/bin/mv -f \"" & strOriginalPath & "\" \"" & strBinDistPath & "\"") as text
do shell script theComandText
return true
  on error
return false
  end try
end doInstall




|

« QRバーコードデコード (QRコードファイルの内容をテキストにする) ちょっと修正 | トップページ | [python3]フォントのファミリー名のフォルダを作って中にフォント入れる(フォントファイル整理用) »

AppleScript EXIFData」カテゴリの記事