AppleScript Video

[ビデオダウンロード]VOEビデオダウンロード

 

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

#!/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 framework "AppKit"
use scripting additions
property refMe : a reference to current application

########################
## クリップボードの中身取り出し
########################
##クリップボードにテキストが無い場合
set strMes to ("URLをペーストしてください") as text
###初期化
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
set ocidPastBoardTypeArray to ocidPasteboard's types
###テキストがあれば
set boolContain to ocidPastBoardTypeArray's containsObject:"public.utf8-plain-text"
if boolContain = true then
  ###値を格納する
  tell application "Finder"
    set strDefaultAnswer to (the clipboard as text) as text
  end tell
  ###Finderでエラーしたら
else
  set boolContain to ocidPastBoardTypeArray's containsObject:"NSStringPboardType"
  if boolContain = true then
    set ocidReadString to ocidPasteboard's readObjectsForClasses:({refMe's NSString}) options:(missing value)
    set strDefaultAnswer to ocidReadString as text
  else
    log "テキストなし"
    set strDefaultAnswer to strMes as text
  end if
end if

##############################
#####ダイアログ
##############################
set strMes to ("TSファイルのURLをペースト") as text
##前面に出す
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 aliasIconPath to POSIX file "/System/Applications/Calculator.app/Contents/Resources/AppIcon.icns" as alias
try
  set recordResult to (display dialog strMes with title "入力してください" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" with icon aliasIconPath giving up after 20 without hidden answer) as record
on error
  log "エラーしました"
return "キャンセル"
end try

if "OK" is equal to (button returned of recordResult) then
  set strReturnedText to (text returned of recordResult) as text
else if (gave up of recordResult) is true then
return "時間切れです"
else
return "キャンセル"
end if
##############################
#####URLの分離
##############################
##テキスト
set ocidURLString to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidURLString's setString:(strReturnedText)
###改行を取る
set ocidCurlLength to ocidURLString's |length|()
set ocidCurlRange to {location:0, |length|:ocidCurlLength}
ocidURLString's replaceOccurrencesOfString:("\n") withString:("") options:(refMe's NSRegularExpressionSearch) range:(ocidCurlRange)
set ocidCurlLength to ocidURLString's |length|()
set ocidCurlRange to {location:0, |length|:ocidCurlLength}
ocidURLString's replaceOccurrencesOfString:("\r") withString:("") options:(refMe's NSRegularExpressionSearch) range:(ocidCurlRange)
##httpならURLコピー
if strReturnedText starts with "http" then
  set ocidHeaderText to ("") as text
  ###CURLならヘッダー付きコピー
else if strReturnedText starts with "curl" then
  set ocidCurl to ocidURLString
  ###『'』でリスト化して2番目がURL
  set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:("'")
  set ocidURLArray to ocidCurl's componentsSeparatedByCharactersInSet:(ocidDelimiters)
  set ocidURLString to ocidURLArray's objectAtIndex:1
  ###ヘッダー部取り出し
  set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:"\\"
  set ocidHeaderArray to ocidCurl's componentsSeparatedByCharactersInSet:(ocidDelimiters)
  set ocidHeaderArrayLength to ocidHeaderArray's |count|()
  set ocidHeaderRange to refMe's NSMakeRange(1, (ocidHeaderArrayLength - 1))
  set ocidSubbArray to ocidHeaderArray's subarrayWithRange:(ocidHeaderRange)
  set ocidHeaderText to (ocidSubbArray's componentsJoinedByString:"")
end if
set strHeaderText to ocidHeaderText as text
##############################
#####クエリーの分離
##############################
##NSURL
set ocidURL to refMe's NSURL's URLWithString:(ocidURLString)
##NSURLComponents
set ocidURLComponents to refMe's NSURLComponents's componentsWithURL:(ocidURL) resolvingAgainstBaseURL:(false)
##クエリーの値
set ocidQuery to ocidURLComponents's query()
set strQuery to ocidQuery as text
##クエリーにNULL=クエリー削除
ocidURLComponents's setQuery:(missing value)
set ocidURL to ocidURLComponents's |URL|()
##############################
##### URL部からファイル名を除く
##############################
set ocidBaseURL to ocidURL's URLByDeletingLastPathComponent()
set strBaseURL to ocidBaseURL's absoluteString() as text
##############################
#####保存先
##############################
##日付時間番号
set ocidDate to refMe's NSDate's |date|()
set ocidNSDateFormatter to refMe's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setDateFormat:("yyyyMMddhhmmss")
set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:(ocidDate)
#####保存先のファイルパス
set strTempPath to ("/private/tmp/" & (ocidDateAndTime as text) & "") as text
#####ファイルパス
set ocidDirPath to (refMe's NSString's stringWithString:(strTempPath))
#####フォルダを作っておく
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listBoolMakeDir to appFileManager's createDirectoryAtPath:(ocidDirPath) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference)
##############################
##### ダウンロード
##############################
set numCnt to 0 as integer
set numSaveFileNo to 10000 as integer
set numMaxRepeat to 10000
###numMaxRepeatで指定した回数々
repeat numMaxRepeat times
  ##URL
  set numCnt to numCnt + 1 as integer
  ##ダウンロードするファイル名を連番で整形
  set strFileName to ("seg-" & numCnt & "-v1-a1.ts") as text
  #ファイル名+クエリーでURLに
  set strURL to (strBaseURL & strFileName & "?" & strQuery) as text
  ##保存ファイル
  set numSaveFileNo to numSaveFileNo + 1 as integer
  ##ファイル名連番のみ
  set strTsFileName to (numSaveFileNo & ".ts")
  set strTsDownPath to (strTempPath & "/" & strTsFileName) as text
  ##コマンド整形
  set strCommandText to "/usr/bin/curl '" & strURL & "' -o '" & strTsDownPath & "' " & strHeaderText & "" as text
  ##コマンド実行
  do shell script strCommandText
  ###ダウンロードしたファイルのファイルサイズを調べる
  set ocidDownFilePath to refMe's NSString's stringWithString:(strTsDownPath)
  set ocidTsFilePath to ocidDownFilePath's stringByStandardizingPath
  set ocidAttributes to appFileManager's attributesOfItemAtPath:(ocidTsFilePath) |error|:(missing value)
  set numFileSize to ocidAttributes's NSFileSize as integer
  ###200b以下ならエラーしたとしてリピート抜けて終了にする
  if numFileSize < 200 then
    ##最後の1コはエラーのHTMLなので削除しておく
    ##コマンド整形
    set strCommandText to "/bin/rm -f '" & strTsDownPath & "'" as text
    ##コマンド実行
    do shell script strCommandText
    exit repeat
  end if
  
end repeat
###ダウンロードしたTSファイルを結合して1つのファイルにする
do shell script "cat " & strTempPath & "/* >> ~/Desktop/" & (ocidDateAndTime as text) & ".ts"

return






|

[Fairlight]音声・出力チャンネル

Screen_20231119_18_03_40

|

ok.ruビデオダウンロード

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

#!/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 scripting additions


property refMe : a reference to current application

set appFileManager to refMe's NSFileManager's defaultManager()

## 1時間 320程度
set numMaxRepeat to 10000 as number
set numSaveFileNo to 10000 as number


###クリックボードの中のURLを取得
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
###クリックボードの中のURLを取得
set ocidPasteboardTypeString to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeString)
set ocidCurlURL to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidCurlURL's setString:ocidPasteboardTypeString
##可変テキスト形式で格納
set ocidCurlURL to refMe's NSMutableString's alloc()'s initWithCapacity:0
ocidCurlURL's setString:ocidPasteboardTypeString

############################
###CURLとしてコピーしているか?
############################
if (ocidCurlURL as text) starts with "curl" then
  log "処理開始"
  #############################
  ###URL を分解
  #############################
  set ocidDoSeparateURLArrayM to doSeparateURL(ocidCurlURL)
  set strM3uURL to ocidCurlURL as text
else
  return "CURLとしてコピーしてください"
end if
#############################
###分解したURLの各種値
#############################
set strCopyURL to (item 1 of ocidDoSeparateURLArrayM)'s absoluteString() as text
set ocidCopyURL to (item 2 of ocidDoSeparateURLArrayM)
set ocidQuiery to (item 3 of ocidDoSeparateURLArrayM) as text
set strHeaderText to (item 4 of ocidDoSeparateURLArrayM) as text
#####ファイル名
set ocidContainerCopyURL to ocidCopyURL's URLByDeletingLastPathComponent()
set strBaseURL to ocidContainerCopyURL's absoluteString() as text
#####保存パス用の日付番号
set ocidDate to refMe's NSDate's |date|()
set ocidNSDateFormatter to refMe's NSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setDateFormat:"yyyyMMddhhmmss"
set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
#####保存先のファイルパス
set strTempPath to ("/private/tmp/" & (ocidDateAndTime as text) & "") as text
#####NSStringファイルパス
set ocidDirPath to (refMe's NSString's stringWithString:strTempPath)
#####FileManager
######保存用のフォルダを作る
set listBoolMakeDir to appFileManager's createDirectoryAtPath:(ocidDirPath) withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
set boolMakeDir to (item 1 of listBoolMakeDir) as boolean
if boolMakeDir is false then
  error "フォルダ作成に失敗しました" number -2753 from "フォルダ作成に失敗しました"
  return
end if
#####################################
#####繰り返し
#####################################
###ファイル番号用のカウンタ
set numCnt to 0 as number
####最大繰り返し数を一応設定
repeat numMaxRepeat times
  ###最初にカウントアップ
  set numCnt to numCnt + 1 as number
  set numSaveFileNo to numSaveFileNo + 1 as number
  ####ゼロサプレスあり
  
  set strZero to "0000" as text
  set strCnt to numCnt as text
  set strZeroSupp to (strZero & strCnt) as text
  set strCnt to (text -5 through -1 of strZeroSupp) as text
  
  if strCopyURL contains "MOBILE" then
    set strFileName to ("MOBILE" & strCnt & ".ts") as text
  else if strCopyURL contains "LOWEST" then
    set strFileName to ("LOWEST" & strCnt & ".ts") as text
  else if strCopyURL contains "LOW" then
    
    set strFileName to ("LOW" & strCnt & ".ts") as text
  else if strCopyURL contains "MEDIUM" then
    set strFileName to ("MEDIUM" & strCnt & ".ts") as text
  else if strCopyURL contains "HIGH" then
    set strFileName to ("HIGH" & strCnt & ".ts") as text
  else if strCopyURL contains "FULLHD" then
    set strFileName to ("FULLHD" & strCnt & ".ts") as text
  end if
  
  
  
  ####ファイル番号
  set strURL to (strBaseURL & strFileName) as text
  set strTsFileName to (numSaveFileNo & ".ts")
  set strTsDownPath to (strTempPath & "/" & strTsFileName) as text
  ####コマンド実行(ヘッダー付き)
  try
    set strCommandText to "/usr/bin/curl  '" & strURL & "' -o '" & strTsDownPath & "' " & strHeaderText & "" as text
    do shell script strCommandText
  on error
    try
      set strCommandText to "/bin/rm  -f ''" & strTsDownPath & "'" as text
      do shell script strCommandText
      set strCommandText to "/usr/bin/curl  '" & strURL & "' -o '" & strTsDownPath & "' " & strHeaderText & "" as text
      do shell script strCommandText
    on error
      set strCommandText to "/bin/rm -f ''" & strTsDownPath & "'" as text
      do shell script strCommandText
      set strCommandText to "/usr/bin/curl  '" & strURL & "' -o '" & strTsDownPath & "' " & strHeaderText & "" as text
      do shell script strCommandText
    end try
  end try
  ####ファイルサイズを調べて
  set ocidDownFilePath to refMe's NSString's stringWithString:strTsDownPath
  set ocidTsFilePath to ocidDownFilePath's stringByStandardizingPath
  set ocidAttributes to appFileManager's attributesOfItemAtPath:ocidTsFilePath |error|:(missing value)
  set numFileSize to ocidAttributes's NSFileSize as integer
  ####1KB以下なら終了
  if numFileSize < 1024 then
    set strCommandText to "/bin/rm  '" & strTsDownPath & "'" as text
    do shell script strCommandText
    exit repeat
  end if
  
end repeat

do shell script "cat  " & strTempPath & "/* >> ~/Desktop/" & (ocidDateAndTime as text) & ".ts"




to doSeparateURL(ocidCurlURL)
  ###戻り値用のリスト
  set ocidDoSeparateURLArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:0
  
  ###改行を取る
  set ocidCurlURLLength to ocidCurlURL's |length|()
  set ocidCurlURLRange to {location:0, |length|:ocidCurlURLLength}
  ocidCurlURL's replaceOccurrencesOfString:("\n") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidCurlURLRange
  ###'』でリスト化して2番目がURL
  set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:"'"
  set ocidCurlURLArray to ocidCurlURL's componentsSeparatedByCharactersInSet:ocidDelimiters
  
  ###URL確定(クエリー入り)
  set ocidURLString to ocidCurlURLArray's objectAtIndex:1
  set ocidURL to refMe's NSURL's URLWithString:ocidURLString
  log ocidURL's absoluteString() as text
  ocidDoSeparateURLArrayM's addObject:ocidURL
  
  ###URL部分(クエリー無し)
  set ocidURLComponents to (refMe's NSURLComponents)'s componentsWithURL:ocidURL resolvingAgainstBaseURL:true
  ocidURLComponents's setQueryItems:(missing value)
  set ocidBaseURL to ocidURLComponents's |URL|
  log ocidBaseURL's absoluteString() as text
  ocidDoSeparateURLArrayM's addObject:ocidBaseURL
  
  ###クエリー部分
  set ocidQueryName to ocidURL's query()
  log ocidQueryName as text
  if ocidQueryName is missing value then
    ocidDoSeparateURLArrayM's addObject:""
  else
    ocidDoSeparateURLArrayM's addObject:ocidQueryName
  end if
  ###ヘッダー部処理
  set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:"\\"
  set ocidHeaderArray to ocidCurlURL's componentsSeparatedByCharactersInSet:ocidDelimiters
  set ocidHeaderArrayLength to ocidHeaderArray's |count|()
  set ocidHeaderRange to refMe's NSMakeRange(1, (ocidHeaderArrayLength - 1))
  set ocidSubbArray to ocidHeaderArray's subarrayWithRange:ocidHeaderRange
  set ocidHeaderText to (ocidSubbArray's componentsJoinedByString:"")
  
  log ocidHeaderText as text
  ocidDoSeparateURLArrayM's addObject:ocidHeaderText
  ###値を戻す
  return ocidDoSeparateURLArrayM
  
end doSeparateURL

|

[m3u]M3UからのTSダウンロード改良版

#!/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 scripting additions

property refMe : a reference to current application

property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL
property refNSMutableString : a reference to refMe's NSMutableString
property refNSMutableArray : a reference to refMe's NSMutableArray

property refNSCharacterSet : a reference to refMe's NSCharacterSet

property refNSPasteboard : a reference to refMe's NSPasteboard

set objFileManager to refMe's NSFileManager's defaultManager()

######################################
######## ペーストボード関連
######################################

###ペーストボードの定義
set ocidPasteboard to refNSPasteboard's generalPasteboard()
###ペーストボードの中身をテキストで取得
set ocidPasteboardTypeString to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeString)
###格納用の可変テキスト
set ocidCurlURL to refNSMutableString's alloc()'s initWithCapacity:0
###ペーストボードのテキストを可変テキストに格納
ocidCurlURL's setString:ocidPasteboardTypeString

######################################
######## URLの分解
######################################
####内容判定(CURLとしてコピーした物か?セッションIDがあるか?)
if (ocidCurlURL as text) starts with "curl" then
if (ocidCurlURL as text) contains "Session" then
log "処理開始"
#####URLをヘッダーと分ける
set ocidDoSeparateURLArrayM to doSeparateURL(ocidCurlURL)
else
return "セッションIDがある方のURLをコピーしてください"
end if
else
return "CURLとしてコピーしてください"
end if

####元のcURLのテキスト(コマンド形式)
set strCurlCommandText to ocidCurlURL as text
###クエリー(あれば)付きURLのテキスト
set strCopyURL to (item 1 of ocidDoSeparateURLArrayM)'s absoluteString() as text
###クエリー(あれば)付きURLNSURL
set ocidURL to (item 1 of ocidDoSeparateURLArrayM)
###クエリー無しのNSURL
set ocidM3UURL to (item 2 of ocidDoSeparateURLArrayM)
set strM3UURL to ocidM3UURL's absoluteString() as text
###クエリー部のNSURL
set ocidQueryURL to (item 3 of ocidDoSeparateURLArrayM)
###ヘッダー部
set ocidHeaderText to (item 4 of ocidDoSeparateURLArrayM)
###ヘッダーテキスト
set strHeaderText to ocidHeaderText as text

###ダウンロード用
##m3uファイル名を取って
set ocidContainerCopyURL to ocidM3UURL's URLByDeletingLastPathComponent()
###テキストにしておく
set strBaseURL to ocidContainerCopyURL's absoluteString() as text


######################################
######## ダウンロードフォルダ作成
######################################
###フォルダ名にUUIDを使う
set ocidUUID to refMe's NSUUID's UUID()
set ocidUUIDString to ocidUUID's UUIDString()
set strUUID to ocidUUIDString as text

#####保存先のファイルパス
set strTempPath to ("/private/tmp/" & strUUID & "") as text
#####NSStringファイルパス
set ocidTmempPath to refNSString's stringWithString:strTempPath
#####NSURL
set ocidTmempPathURL to refNSURL's alloc()'s initFileURLWithPath:ocidTmempPath

#####FileManagerでフォルダを作る
set listBoolMakeDir to objFileManager's createDirectoryAtURL:(ocidTmempPathURL) withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
###フォルダ作成の結果
set boolMakeDir to (item 1 of listBoolMakeDir) as boolean
log boolMakeDir
if boolMakeDir is false then
error "フォルダ作成に失敗しました" number -2753 from "フォルダ作成に失敗しました"
return
end if


######################################
######## URLの内容を取得
######################################

set listDownLoadData to refNSString's stringWithContentsOfURL:ocidURL encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
####データ部
set ocidGetDataString to (item 1 of listDownLoadData)
####エラー情報(不要な場合は削除可)
set ocidNSErrorData to item 2 of listDownLoadData
if ocidNSErrorData is not (missing value) then
doGetErrorData(ocidNSErrorData)
return "エラー"
end if

#####並び替え用のリストの初期化
set ocidM3UArray to refNSMutableArray's alloc()'s initWithCapacity:0
#####改行を区切り文字に
set ocidNewlineCharacterSett to refNSCharacterSet's newlineCharacterSet()
#####取得したテキストを改行でリストに格納
set ocidM3UArray to ocidGetDataString's componentsSeparatedByCharactersInSet:ocidNewlineCharacterSett


######################################
######## 本処理
######################################
#####ダウンロードエラーになったコマンドの格納用のリスト
set ocidErrorURLArray to refNSMutableArray's alloc()'s initWithCapacity:0
####ファイル番号の初期化
set numSaveFileNo to 10000 as number
####リストの内容だけ繰り返し
repeat with objm3uArrayItem in ocidM3UArray
###取り出したテキスト行
set strLineText to objm3uArrayItem as text
############################
####から始まるのはコメント行
if strLineText starts with "#" then
####コメント行は処理しない
set strURLText to ""
else if strLineText is "" then
####空行(最後)は処理しない
set strURLText to ""
else if strLineText starts with "http" then
###httpから始まる場合はURLはそのまま使う
set strURLText to strLineText
else
###ファイル名だけ記載されている場合はURLを結合しておく
set strURLText to (strBaseURL & strLineText) as text
end if
############################
####コマンド実行
if strURLText is not "" then
###ダウンロードするファイル名
set strTsFileName to (numSaveFileNo & ".ts")
###ダウンロードパス
set strTsDownPath to (strTempPath & "/" & strTsFileName) as text
####コマンド整形
set strCommandTextA to "/usr/bin/curl '" & strURLText & "' -o '" & strTsDownPath & "' " & strHeaderText & "" as text
set strCommandTextB to "/usr/bin/curl '" & strURLText & "' -o '" & strTsDownPath & "' " & strHeaderText & " --http1.1" as text

try
####http2で実行
do shell script strCommandTextA
###エラーしたら
on error
####エラーファイルをゴミ箱に
###NSString
set objGoToTrashDir to (refNSString's stringWithString:strTsDownPath)
####URL
set objGotoTrashDirUrl to (refNSURL's fileURLWithPath:objGoToTrashDir)
set boolGoToTrash to (objFileManager's trashItemAtURL:objGotoTrashDirUrl resultingItemURL:(missing value) |error|:(reference))
###コマンドをエラーリストに格納
(ocidErrorURLArray's addObject:strCommandTextA)
###コマンドB http1.1で再実行
do shell script strCommandTextB
####エラーファイルをゴミ箱に
###NSString
set objGoToTrashDir to (refNSString's stringWithString:strTsDownPath)
####URL
set objGotoTrashDirUrl to (refNSURL's fileURLWithPath:objGoToTrashDir)
set boolGoToTrash to (objFileManager's trashItemAtURL:objGotoTrashDirUrl resultingItemURL:(missing value) |error|:(reference))
end try
###ファイル名番号のカウントアップ
set numSaveFileNo to numSaveFileNo + 1 as number
end if
end repeat

####エラーしたコマンドを再実行する
repeat with ocidErrorURLArrayItem in ocidErrorURLArray
set strCommandText to ocidErrorURLArrayItem as text
try
do shell script strCommandText
end try
end repeat

######ダウンロードしたファイルの結合
do shell script "cat " & strTempPath & "/* >> ~/Desktop/" & strUUID & ".ts"




######################################
######## ヘッダー分割のサブ
######################################

to doSeparateURL(ocidCurlURL)
###戻り値用のリスト
set ocidDoSeparateURLArrayM to refNSMutableArray's alloc()'s initWithCapacity:0

###改行を取る
set ocidCurlURLLength to ocidCurlURL's |length|()
set ocidCurlURLRange to {location:0, |length|:ocidCurlURLLength}
ocidCurlURL's replaceOccurrencesOfString:("\n") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidCurlURLRange
set ocidCurlURLLength to ocidCurlURL's |length|()
set ocidCurlURLRange to {location:0, |length|:ocidCurlURLLength}
ocidCurlURL's replaceOccurrencesOfString:("\r") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidCurlURLRange

###'』でリスト化して2番目がURL
set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:"'"
set ocidCurlURLArray to ocidCurlURL's componentsSeparatedByCharactersInSet:ocidDelimiters

###URL確定(クエリー入り)
set ocidURLString to ocidCurlURLArray's objectAtIndex:1
set ocidURL to refNSURL's URLWithString:ocidURLString
log ocidURL's absoluteString() as text
ocidDoSeparateURLArrayM's addObject:ocidURL

###URL部分(クエリー無し)
set ocidURLComponents to (refMe's NSURLComponents)'s componentsWithURL:ocidURL resolvingAgainstBaseURL:true
ocidURLComponents's setQueryItems:(missing value)
set ocidBaseURL to ocidURLComponents's |URL|
#log ocidBaseURL's absoluteString() as text
ocidDoSeparateURLArrayM's addObject:ocidBaseURL

###クエリー部分
set ocidQueryName to ocidURL's query()
#log ocidQueryName as text
if ocidQueryName is missing value then
ocidDoSeparateURLArrayM's addObject:""
else
ocidDoSeparateURLArrayM's addObject:ocidQueryName
end if
###ヘッダー部処理
set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:"\\"
set ocidHeaderArray to ocidCurlURL's componentsSeparatedByCharactersInSet:ocidDelimiters
set ocidHeaderArrayLength to ocidHeaderArray's |count|()
set ocidHeaderRange to refMe's NSMakeRange(1, (ocidHeaderArrayLength - 1))
set ocidSubbArray to ocidHeaderArray's subarrayWithRange:ocidHeaderRange
set ocidHeaderText to (ocidSubbArray's componentsJoinedByString:"")

#log ocidHeaderText as text
ocidDoSeparateURLArrayM's addObject:ocidHeaderText
###値を戻す
return ocidDoSeparateURLArrayM

end doSeparateURL

|

[dizigom]ビデオダウンロード

デベロッパーツールからビデオのURLをCURLでコピーして
クリップボードにURLが入った状態で実行する
(ヘッダーのSession-Idが必要なため)


#!/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 scripting additions


property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSURL : a reference to refMe's NSURL
property refNSData : a reference to refMe's NSData
property refNSMutableString : a reference to refMe's NSMutableString
property refNSUTF8StringEncoding : a reference to refMe's NSUTF8StringEncoding
property refNSMutableArray : a reference to refMe's NSMutableArray
property refNSArray : a reference to refMe's NSArray
property refNSDate : a reference to refMe's NSDate
property refNSDateFormatter : a reference to refMe's NSDateFormatter

property refNSCharacterSet : a reference to refMe's NSCharacterSet
property refNSRegularExpressionSearch : a reference to refMe's NSRegularExpressionSearch

property refNSNotFound : a reference to 9.22337203685477E+18 + 5807

set objFileManager to refMe's NSFileManager's defaultManager()
property refNSPasteboard : a reference to refMe's NSPasteboard







###クリックボードの中のURLを取得
set ocidPasteboard to refNSPasteboard's generalPasteboard()
###クリックボードの中のURLを取得
set ocidPasteboardTypeString to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeString)
set ocidCurlURL to refNSMutableString's alloc()'s initWithCapacity:0
ocidCurlURL's setString:ocidPasteboardTypeString
##可変テキスト形式で格納
set ocidCurlURL to refNSMutableString's alloc()'s initWithCapacity:0
ocidCurlURL's setString:ocidPasteboardTypeString

if (ocidCurlURL as text) starts with "curl" then
log "処理開始"
set ocidDoSeparateURLArrayM to doSeparateURL(ocidCurlURL)
set strM3uURL to ocidCurlURL as text
else
return "CURLとしてコピーしてください"
end if

set strCopyURL to (item 1 of ocidDoSeparateURLArrayM)'s absoluteString() as text
set ocidCopyURL to (item 2 of ocidDoSeparateURLArrayM)

set strHeaderText to (item 4 of ocidDoSeparateURLArrayM) as text

set ocidContainerCopyURL to ocidCopyURL's URLByDeletingLastPathComponent()
set strBaseURL to ocidContainerCopyURL's absoluteString() as text



set ocidDate to refNSDate's |date|()
set ocidNSDateFormatter to refNSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setDateFormat:"yyyyMMddhhmmss"
set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate

#####保存先のファイルパス
set strTempPath to ("/private/tmp/" & (ocidDateAndTime as text) & "") as text
#####NSStringファイルパス
set ocidDirPath to (refNSString's stringWithString:strTempPath)
#####FileManager
set listBoolMakeDir to objFileManager's createDirectoryAtPath:(ocidDirPath) withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
log class of (item 1 of listBoolMakeDir) as text
set boolMakeDir to (item 1 of listBoolMakeDir) as boolean
log boolMakeDir
if boolMakeDir is false then
error "フォルダ作成に失敗しました" number -2753 from "フォルダ作成に失敗しました"
return
end if



set numCnt to 0 as number

set numMaxRepeat to 310 as number
set numSaveFileNo to 10000 as number

repeat 300 times

set numCnt to numCnt + 1 as number
set numSaveFileNo to numSaveFileNo + 1 as number
if numCnt < 10 then
set strCnt to numCnt as text
set strCnt to "0" & strCnt as text
set strFileName to ("gomplayer-" & strCnt & ".jpeg") as text
else
set strFileName to ("gomplayer-" & numCnt & ".jpeg") as text
end if

set strURL to (strBaseURL & strFileName) as text
set strTsFileName to (numSaveFileNo & ".ts")
set strTsDownPath to (strTempPath & "/" & strTsFileName) as text


set strCommandText to "/usr/bin/curl '" & strURL & "' -o '" & strTsDownPath & "' " & strHeaderText & "" as text

do shell script strCommandText
end repeat

do shell script "cat " & strTempPath & "/* >> ~/Desktop/" & (ocidDateAndTime as text) & ".ts"




to doSeparateURL(ocidCurlURL)
###戻り値用のリスト
set ocidDoSeparateURLArrayM to refNSMutableArray's alloc()'s initWithCapacity:0

###改行を取る
set ocidCurlURLLength to ocidCurlURL's |length|()
set ocidCurlURLRange to {location:0, |length|:ocidCurlURLLength}
ocidCurlURL's replaceOccurrencesOfString:("\n") withString:("") options:(refMe's NSRegularExpressionSearch) range:ocidCurlURLRange
###'』でリスト化して2番目がURL
set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:"'"
set ocidCurlURLArray to ocidCurlURL's componentsSeparatedByCharactersInSet:ocidDelimiters

###URL確定(クエリー入り)
set ocidURLString to ocidCurlURLArray's objectAtIndex:1
set ocidURL to refNSURL's URLWithString:ocidURLString
log ocidURL's absoluteString() as text
ocidDoSeparateURLArrayM's addObject:ocidURL

###URL部分(クエリー無し)
set ocidURLComponents to (refMe's NSURLComponents)'s componentsWithURL:ocidURL resolvingAgainstBaseURL:true
ocidURLComponents's setQueryItems:(missing value)
set ocidBaseURL to ocidURLComponents's |URL|
log ocidBaseURL's absoluteString() as text
ocidDoSeparateURLArrayM's addObject:ocidBaseURL

###クエリー部分
set ocidQueryName to ocidURL's query()
log ocidQueryName as text
if ocidQueryName is missing value then
ocidDoSeparateURLArrayM's addObject:""
else
ocidDoSeparateURLArrayM's addObject:ocidQueryName
end if
###ヘッダー部処理
set ocidDelimiters to (refMe's NSCharacterSet)'s characterSetWithCharactersInString:"\\"
set ocidHeaderArray to ocidCurlURL's componentsSeparatedByCharactersInSet:ocidDelimiters
set ocidHeaderArrayLength to ocidHeaderArray's |count|()
set ocidHeaderRange to refMe's NSMakeRange(1, (ocidHeaderArrayLength - 1))
set ocidSubbArray to ocidHeaderArray's subarrayWithRange:ocidHeaderRange
set ocidHeaderText to (ocidSubbArray's componentsJoinedByString:"")

log ocidHeaderText as text
ocidDoSeparateURLArrayM's addObject:ocidHeaderText
###値を戻す
return ocidDoSeparateURLArrayM

end doSeparateURL

|

[CURL]CRLとしてコピーしたURLをダウンロードする

セッションID等が必要な場合にダウンロードできる『こと』があります

#!/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 scripting additions



property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSMutableString : a reference to refMe's NSMutableString
property refNSUTF8StringEncoding : a reference to refMe's NSUTF8StringEncoding
property refNSMutableArray : a reference to refMe's NSMutableArray
property refNSArray : a reference to refMe's NSArray
property refNSDate : a reference to refMe's NSDate
property refNSDateFormatter : a reference to refMe's NSDateFormatter

property refNSCharacterSet : a reference to refMe's NSCharacterSet
property refNSRegularExpressionSearch : a reference to refMe's NSRegularExpressionSearch

property refNSNotFound : a reference to 9.22337203685477E+18 + 5807

set objFileManager to refMe's NSFileManager's defaultManager()

###クリックボードの中のURLを取得
tell application "Finder"
set strCURL2URL to the clipboard as text
end tell


###日付
set ocidDate to refNSDate's |date|()
log ocidDate as date
log className() of ocidDate as text
set ocidNSDateFormatter to refNSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setDateFormat:"yyyyMMddhhmmss"
set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
log ocidDateAndTime as text
log className() of ocidDateAndTime as text




#####保存先のファイルパス
set strTempPath to ("~/Downloads/" & (ocidDateAndTime as text) & "") as text
#####NSStringファイルパス
set ocidRelativePath to refNSString's stringWithString:strTempPath
set ocidFullPath to ocidRelativePath's stringByStandardizingPath()
set ocidDirPath to (refNSString's stringWithString:ocidFullPath)
set strTempPath to ocidFullPath as text
#####FileManager
set listBoolMakeDir to objFileManager's createDirectoryAtPath:(ocidDirPath) withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
log class of (item 1 of listBoolMakeDir) as text
set boolMakeDir to (item 1 of listBoolMakeDir) as boolean
log boolMakeDir
if boolMakeDir is false then
error "フォルダ作成に失敗しました" number -2753 from "フォルダ作成に失敗しました"
return
end if



###初期化 空の可変テキストを作成
set ocidNSMutableString to refNSMutableString's alloc()'s initWithCapacity:0
log className() of ocidNSMutableString as text
###可変テキスト
set ocidNSMutableString to refNSMutableString's stringWithString:strCURL2URL
log ocidNSMutableString as text
log className() of ocidNSMutableString as text
#########################
###↑文字数を数える
set numCntNSMutableString to ocidNSMutableString's |length|()
###↑文字数全部でレンジにする
set ocidNsRange to {location:0, |length|:numCntNSMutableString}
log class of ocidNsRange
log ocidNsRange as record
###改行除去
ocidNSMutableString's replaceOccurrencesOfString:("
") withString:("") options:(refNSRegularExpressionSearch) range:ocidNsRange
log ocidNSMutableString as text
log className() of ocidNSMutableString as text
#########################
###↑文字数を数える
set numCntNSMutableString to ocidNSMutableString's |length|()
###↑文字数全部でレンジにする
set ocidNsRange to {location:0, |length|:numCntNSMutableString}
log class of ocidNsRange
log ocidNsRange as record
###改行除去
ocidNSMutableString's replaceOccurrencesOfString:("
") withString:("") options:(refNSRegularExpressionSearch) range:ocidNsRange
log ocidNSMutableString as text
log className() of ocidNSMutableString as text

#########################
###↑文字数を数える
set numCntNSMutableString to ocidNSMutableString's |length|()
###↑文字数全部でレンジにする
set ocidNsRange to {location:0, |length|:numCntNSMutableString}
log class of ocidNsRange
log ocidNsRange as record
###バックスラッシュ除去
ocidNSMutableString's replaceOccurrencesOfString:("curl ") withString:("") options:0 range:ocidNsRange
log ocidNSMutableString as text
log className() of ocidNSMutableString as text
#########################
###区切り文字を定義
set ocidNSCFCharacterSet to refNSCharacterSet's characterSetWithCharactersInString:" "
log className() of ocidNSCFCharacterSet as text
###置き換え文字でArray=リスト化
set ocidNsArrayList to ocidNSMutableString's componentsSeparatedByCharactersInSet:ocidNSCFCharacterSet
log ocidNsArrayList as list
log className() of ocidNsArrayList as text
####URL部分を取り出す
###初期化 空の可変テキストを作成
set ocidUrlText to refNSMutableString's alloc()'s initWithCapacity:0
set ocidUrlText to refNSMutableString's stringWithString:(ocidNsArrayList's objectAtIndex:0)
log ocidUrlText as text


#########################
###区切り文字を定義
set ocidNSCFCharacterSet to refNSCharacterSet's characterSetWithCharactersInString:"\\"
log className() of ocidNSCFCharacterSet as text
###置き換え文字でArray=リスト化
set ocidNsArrayHeader to ocidNSMutableString's componentsSeparatedByCharactersInSet:ocidNSCFCharacterSet
log ocidNsArrayHeader as list
log className() of ocidNsArrayHeader as text


log className() of ocidNSMutableString as text
set ocidHeaderText to (ocidNsArrayHeader's componentsJoinedByString:"")
log className() of ocidUrlText as text
log className() of ocidHeaderText as text

########################
###
set strUrlText to ocidUrlText as text
###ヘッダーテキスト
set strHeaderText to ocidHeaderText as text
####日時テキスト
set strDateAndTime to ocidDateAndTime as text
###FileName
set strDownloadsFileName to ("" & strDateAndTime & ".mp4")
####
set strDownloadsFilePath to ("" & strTempPath & "/" & strDownloadsFileName & "") as text
try
set strCommandText to "/usr/bin/curl " & strUrlText & " -o '" & strDownloadsFilePath & "' " & strHeaderText & "" as text
do shell script strCommandText
on error
log "エラーが発生しました。"
end try

|

[VK]VKビデオダウンロード

VK(ロシアのSNS)に上がっているビデオをダウンロードします
m3u8ファイルが3種類あって
今回はvideo.m3u8からダウンロードします
video.m3u8の解像度別のURLから最高解像度のm3u8をダウンロードして
TSファイルをダウンロードします



対象のビデオを再生中にm3u8のURLを取得します。
↓この値をクリップボードに入れた状態でスタートしてください
20220924110113_1862x988x1440



#!/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 scripting additions

######ログ表示
doLogView()

property refMe : a reference to current application
property refNSString : a reference to refMe's NSString
property refNSMutableString : a reference to refMe's NSMutableString
property refNSUTF8StringEncoding : a reference to refMe's NSUTF8StringEncoding
property refNSMutableArray : a reference to refMe's NSMutableArray
property refNSArray : a reference to refMe's NSArray
property refNSDate : a reference to refMe's NSDate
property refNSDateFormatter : a reference to refMe's NSDateFormatter

property refNSCharacterSet : a reference to refMe's NSCharacterSet
property refNSRegularExpressionSearch : a reference to refMe's NSRegularExpressionSearch

property refNSNotFound : a reference to 9.22337203685477E+18 + 5807

set objFileManager to refMe's NSFileManager's defaultManager()

###クリックボードの中のURLを取得
tell application "Finder"
set strM3uURL to the clipboard as text
end tell

###Session-Idが含まれている方が必要なため
if strM3uURL contains "X-Playback-Session-Id" then
###日付
set ocidDate to refNSDate's |date|()
log ocidDate as date
log className() of ocidDate as text
set ocidNSDateFormatter to refNSDateFormatter's alloc()'s init()
ocidNSDateFormatter's setDateFormat:"yyyyMMddhhmmss"
set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate
log ocidDateAndTime as text
log className() of ocidDateAndTime as text
else
error "Session-Idが含まれていません" number -2753 from "Session-Idが含まれていません"
return
end if



#####保存先のファイルパス
set strTempPath to ("/private/tmp/" & (ocidDateAndTime as text) & "") as text
#####NSStringファイルパス
set ocidDirPath to (refNSString's stringWithString:strTempPath)
#####FileManager
set listBoolMakeDir to objFileManager's createDirectoryAtPath:(ocidDirPath) withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
log class of (item 1 of listBoolMakeDir) as text
set boolMakeDir to (item 1 of listBoolMakeDir) as boolean
log boolMakeDir
if boolMakeDir is false then
error "フォルダ作成に失敗しました" number -2753 from "フォルダ作成に失敗しました"
return
end if


set strM3uDir to ("/private/tmp/" & (ocidDateAndTime as text) & "m3u") as text
#####保存先のファイルパス
set ocidM3uDirPath to (refNSString's stringWithString:strM3uDir)
set listBoolMakeDir to objFileManager's createDirectoryAtPath:(ocidM3uDirPath) withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
log class of (item 1 of listBoolMakeDir) as text
set boolMakeDir to (item 1 of listBoolMakeDir) as boolean
log boolMakeDir

if boolMakeDir is false then
error "フォルダ作成に失敗しました" number -2753 from "フォルダ作成に失敗しました"
return
end if


set strM3u8Dir to ("/private/tmp/" & (ocidDateAndTime as text) & "m3u8") as text
#####保存先のファイルパス
set ocidM3u8DirPath to (refNSString's stringWithString:strM3u8Dir)
set listBoolMakeDir to objFileManager's createDirectoryAtPath:(ocidM3u8DirPath) withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
log class of (item 1 of listBoolMakeDir) as text
set boolMakeDir to (item 1 of listBoolMakeDir) as boolean
log boolMakeDir

if boolMakeDir is false then
error "フォルダ作成に失敗しました" number -2753 from "フォルダ作成に失敗しました"
return
end if


###初期化 空の可変テキストを作成
set ocidNSMutableString to refNSMutableString's alloc()'s initWithCapacity:0
log className() of ocidNSMutableString as text
###可変テキスト
set ocidNSMutableString to refNSMutableString's stringWithString:strM3uURL
log ocidNSMutableString as text
log className() of ocidNSMutableString as text
#########################
###↑文字数を数える
set numCntNSMutableString to ocidNSMutableString's |length|()
###↑文字数全部でレンジにする
set ocidNsRange to {location:0, |length|:numCntNSMutableString}
log class of ocidNsRange
log ocidNsRange as record
###改行除去
ocidNSMutableString's replaceOccurrencesOfString:("\n") withString:("") options:(refNSRegularExpressionSearch) range:ocidNsRange
log ocidNSMutableString as text
log className() of ocidNSMutableString as text
#########################
###↑文字数を数える
set numCntNSMutableString to ocidNSMutableString's |length|()
###↑文字数全部でレンジにする
set ocidNsRange to {location:0, |length|:numCntNSMutableString}
log class of ocidNsRange
log ocidNsRange as record
###改行除去
ocidNSMutableString's replaceOccurrencesOfString:("\r") withString:("") options:(refNSRegularExpressionSearch) range:ocidNsRange
log ocidNSMutableString as text
log className() of ocidNSMutableString as text

#########################
###↑文字数を数える
set numCntNSMutableString to ocidNSMutableString's |length|()
###↑文字数全部でレンジにする
set ocidNsRange to {location:0, |length|:numCntNSMutableString}
log class of ocidNsRange
log ocidNsRange as record
###バックスラッシュ除去
ocidNSMutableString's replaceOccurrencesOfString:("curl ") withString:("") options:0 range:ocidNsRange
log ocidNSMutableString as text
log className() of ocidNSMutableString as text
#########################
###区切り文字を定義
set ocidNSCFCharacterSet to refNSCharacterSet's characterSetWithCharactersInString:" "
log className() of ocidNSCFCharacterSet as text
###置き換え文字でArray=リスト化
set ocidNsArrayList to ocidNSMutableString's componentsSeparatedByCharactersInSet:ocidNSCFCharacterSet
log ocidNsArrayList as list
log className() of ocidNsArrayList as text
####URL部分を取り出す
###初期化 空の可変テキストを作成
set ocidUrlText to refNSMutableString's alloc()'s initWithCapacity:0
set ocidUrlText to refNSMutableString's stringWithString:(ocidNsArrayList's objectAtIndex:0)
log ocidUrlText as text


#########################
###区切り文字を定義
set ocidNSCFCharacterSet to refNSCharacterSet's characterSetWithCharactersInString:"\\"
log className() of ocidNSCFCharacterSet as text
###置き換え文字でArray=リスト化
set ocidNsArrayHeader to ocidNSMutableString's componentsSeparatedByCharactersInSet:ocidNSCFCharacterSet
log ocidNsArrayHeader as list
log className() of ocidNsArrayHeader as text


log className() of ocidNSMutableString as text
set ocidHeaderText to (ocidNsArrayHeader's componentsJoinedByString:"")
log className() of ocidUrlText as text
log className() of ocidHeaderText as text

########################
###
set strUrlText to ocidUrlText as text
###ヘッダーテキスト
set strHeaderText to ocidHeaderText as text
####日時テキスト
set strDateAndTime to ocidDateAndTime as text
###M3uFileName
set strM3uFileName to ("" & strDateAndTime & ".m3u8")
####
set strM3uSavePath to ("" & strM3uDir & "/" & strM3uFileName & "") as text

log strM3uFileName
log strM3uSavePath

set strCommandText to "/usr/bin/curl " & strUrlText & " -o '" & strM3uSavePath & "' " & strHeaderText & "" as text
log strCommandText

do shell script strCommandText
################################################
################################################

####ファイルを読み取る
set ocidReadData to (refNSString's stringWithContentsOfFile:strM3uSavePath encoding:(refNSUTF8StringEncoding) |error|:(missing value))
log ocidReadData as text
log className() of ocidReadData as text

######Arrayの初期化
set ocidM3uArray to (refNSMutableArray's alloc()'s initWithCapacity:0)
log ocidM3uArray as list
log className() of ocidM3uArray as text
###区切り文字を定義
set ocidNSCFCharacterSet to (refMe's NSCharacterSet's characterSetWithCharactersInString:"\n")
log className() of ocidNSCFCharacterSet as text
###ocidNSCFCharacterSetArray=リスト化
set ocidM3uArray to (ocidReadData's componentsSeparatedByCharactersInSet:ocidNSCFCharacterSet)
log ocidM3uArray as list
log className() of ocidM3uArray as text


#####URL判定用の値の初期化
set strM3U8urlmobile to "" as text
set strM3U8urllowest to "" as text
set strM3U8urllow to "" as text
set strM3U8urlsd to "" as text
set strM3U8urlhd to "" as text
set strM3U8urlfull to "" as text
set numCntLineNo to 0 as number
####読み込んだファイルデータの行分だけ繰り返し
repeat with objM3uArray in ocidM3uArray

set strM3uArray to objM3uArray as text
set numCntURL to numCntLineNo + 1 as number
###それぞれのURLを格納する
if strM3uArray contains "QUALITY=mobile" then
set strM3U8urlmobile to (ocidM3uArray's objectAtIndex:numCntURL) as text
end if
if strM3uArray contains "QUALITY=lowest" then
set strM3U8urllowest to (ocidM3uArray's objectAtIndex:numCntURL) as text
end if
if strM3uArray contains "QUALITY=low" then
set strM3U8urllow to (ocidM3uArray's objectAtIndex:numCntURL) as text
end if
if strM3uArray contains "QUALITY=sd" then
set strM3U8urlsd to (ocidM3uArray's objectAtIndex:numCntURL) as text
end if
if strM3uArray contains "QUALITY=hd" then
set strM3U8urlhd to (ocidM3uArray's objectAtIndex:numCntURL) as text
end if
if strM3uArray contains "QUALITY=full" then
set strM3U8urlfull to (ocidM3uArray's objectAtIndex:numCntURL) as text
end if

set numCntLineNo to numCntLineNo + 1 as number
end repeat

######高解像度のURLを優先する
if strM3U8urlmobile is not "" then
set strM3U8url to strM3U8urlmobile as text
end if
if strM3U8urllowest is not "" then
set strM3U8url to strM3U8urllowest as text
end if
if strM3U8urllow is not "" then
set strM3U8url to strM3U8urllow as text
end if
if strM3U8urlsd is not "" then
set strM3U8url to strM3U8urlsd as text
end if
if strM3U8urlhd is not "" then
set strM3U8url to strM3U8urlhd as text
end if
if strM3U8urlfull is not "" then
set strM3U8url to strM3U8urlfull as text
end if
###取得したURL
log strM3U8url
###ダウンロードパス
set strM3u8Dir to ("/private/tmp/" & (ocidDateAndTime as text) & "m3u8") as text
####ファイル名
set strM3u8SavePath to ("" & strM3u8Dir & "/" & strM3uFileName & "") as text
####ダウンロード
set strCommandText to "/usr/bin/curl '" & strM3U8url & "' -o '" & strM3u8SavePath & "' " & strHeaderText & "" as text
log strCommandText
do shell script strCommandText

##################################################
##################################################
####ダウンロードしたURLはデイレクトリなのでそのまま利用
set strBaseUrl to strM3U8url as text

####ファイルを読み取る
set ocidM3u8ReadData to (refNSString's stringWithContentsOfFile:strM3u8SavePath encoding:(refNSUTF8StringEncoding) |error|:(missing value))
log ocidM3u8ReadData as text
log className() of ocidM3u8ReadData as text

######Arrayの初期化
set ocidM3u8Array to (refNSMutableArray's alloc()'s initWithCapacity:0)
log ocidM3u8Array as list
log className() of ocidM3u8Array as text
###区切り文字を定義
set ocidNSCFCharacterSet to (refMe's NSCharacterSet's characterSetWithCharactersInString:"\n")
log className() of ocidNSCFCharacterSet as text
###ocidNSCFCharacterSetArray=リスト化
set ocidM3u8Array to (ocidM3u8ReadData's componentsSeparatedByCharactersInSet:ocidNSCFCharacterSet)
log ocidM3u8Array as list
log className() of ocidM3u8Array as text
###Arrayの数を数える
set numReadFileText to count of ocidM3u8Array
###ファイル名
set numFileName to 10000 as number
###ファイル番号のカウントアップ
set numFileCnt to 0 as number

####読み込んだデータの行数だけ々
repeat with objM3u8Array in ocidM3u8Array
###テキストに
set strM3u8Array to objM3u8Array as text
#####
#####set cntHas to the offset of "#" in strM3u8Array
##### #で始まるのはコメント行
if strM3u8Array starts with "#" then
log "コメント行"
else
###URLが格納されているので整形
set numFileName to numFileName + 1 as number
set strTsURL to strBaseUrl & strM3u8Array as text
set strTsFileName to (numFileName & ".ts")
set strTsDownPath to (strTempPath & "/" & strTsFileName) as text
####ダウンロード
set strCommandText to "/usr/bin/curl '" & strTsURL & "' -o '" & strTsDownPath & "' " & strHeaderText & "" as text
log strCommandText
do shell script strCommandText
end if

end repeat

####終わったら ダウンロードしたデータをデスクトップに結合して終了
do shell script "cat " & strTempPath & "/* >> ~/Desktop/" & (ocidDateAndTime as text) & ".ts"

#########################ログ表示
to doLogView()

tell application "System Events"
set listAppList to title of (every process where background only is false)
end tell
repeat with objAppList in listAppList
set strAppList to objAppList as text
if strAppList is "スクリプトエディタ" then
tell application "Script Editor"
if frontmost is true then
try
tell application "System Events" to click menu item "ログを表示" of menu "表示" of menu bar item "表示" of menu bar 1 of application process "Script Editor"
end try
end if
end tell
tell application "Script Editor"
tell application "System Events"
tell process "Script Editor"
tell window 1
tell splitter group 1
tell splitter group 1
tell group 1
tell checkbox "返された値"
set boolValue to value as boolean
end tell
if boolValue is false then
click checkbox "返された値"
end if
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end if
end repeat

end doLogView
#########################

|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom