[CURL]CURLヘッダー付きダウンローダー
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos13なので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 refNSMutableArray : a reference to refMe's NSMutableArray
set objFileManager to refMe's NSFileManager's defaultManager()
property refNSPasteboard : a reference to refMe's NSPasteboard
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
if (ocidCurlURL as text) starts with "curl" then
log "処理開始"
set ocidDoSeparateURLArrayM to doSeparateURL(ocidCurlURL)
else
return "CURLとしてコピーしてください"
end if
set strURLwithQuery to (item 1 of ocidDoSeparateURLArrayM)'s absoluteString() as text
set strURL to (item 2 of ocidDoSeparateURLArrayM)'s absoluteString() as text
set strQuery to (item 3 of ocidDoSeparateURLArrayM) as text
set strHeader to (item 4 of ocidDoSeparateURLArrayM) as text
set ocidURL to (item 2 of ocidDoSeparateURLArrayM)
set ocidFileName to ocidURL's lastPathComponent()
set ocidUserDownloadsPath to (objFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidDownLoadFolderPath to item 1 of ocidUserDownloadsPath
set ocidFilePathURL to ocidDownLoadFolderPath's URLByAppendingPathComponent:ocidFileName isDirectory:false
set strFilePath to ocidFilePathURL's |path|() as text
log strFilePath
set strCommandText to "/usr/bin/curl '" & strURL & "' -o '" & strFilePath & "' " & strHeader & "" as text
do shell script strCommandText
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」カテゴリの記事
- [curl]rapid-cloudビデオ・ダウンロードヘルパー(簡易式)(2025.01.16)
- CURLでのURLチェック (404以外の応答があるURLのみ収集)(2024.12.03)
- [CURL]ヘッダー付きダウンロード(2024.11.23)
- 【CURL】基本的な事項(2023.10.24)
- [CURL]リダイレクト先URL(2023.10.19)