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()
tell application "Finder"
set strM3uURL to the clipboard as text
end tell
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
set ocidDirPath to (refNSString's stringWithString:strTempPath)
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
set ocidNsArrayList to ocidNSMutableString's componentsSeparatedByCharactersInSet:ocidNSCFCharacterSet
log ocidNsArrayList as list
log className() of ocidNsArrayList as text
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
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
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
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
set ocidM3uArray to (ocidReadData's componentsSeparatedByCharactersInSet:ocidNSCFCharacterSet)
log ocidM3uArray as list
log className() of ocidM3uArray as text
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
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
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
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
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
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
set ocidM3u8Array to (ocidM3u8ReadData's componentsSeparatedByCharactersInSet:ocidNSCFCharacterSet)
log ocidM3u8Array as list
log className() of ocidM3u8Array as text
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
if strM3u8Array starts with "#" then
log "コメント行"
else
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