« [XML]CDATA(HTML化済みのテキスト)を追加する | トップページ | [NSXMLElement]エレメントのコピー »

[Youtube API]チャンネルIDからチャンネルのアップロードビデオを取得する


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
API
https://developers.google.com/youtube/v3
コンソール
https://console.cloud.google.com/apis/dashboard?pli=1
*)
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use framework "Foundation"
use AppleScript version "2.8"
use scripting additions

property refMe : a reference to current application

############設定項目 
####API ID
property strAPIkey : "XXXXXXXXXXXXXXXXXXXXXXX" as text

####################################
property numMaxResults : 10 as number
####################################

set strURL to ("https://www.youtube.com/channel/UCQ6Br7m6vP61FZvjv4lwR5w") as text

######

set ocidURLString to refMe's NSString's stringWithString:(strURL)
set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
set strChannelID to ocidURL's lastPathComponent() as text

##################################################
#チャンネルIDからアップロードビデオのリストID
set ocidUploadsListID to doChannelId2UploadsListID(strChannelID)
log ocidUploadsListID as text
##################################################
#アップロードビデオのplaylistIDからアップロードビデオの詳細
set ocidItemsArray to doGetPlistID2ItemsArray(ocidUploadsListID)
########################
##HTML生成開始
########################
##Header に渡すエレメント
set ocidSetHeaderElement to refMe's NSXMLElement's elementWithName:("div")
set ocidH3Element to refMe's NSXMLElement's elementWithName:("h3")
set ocidAElement to refMe's NSXMLElement's elementWithName:("a")
set strSetValue to ("https://www.youtube.com/playlist?list=" & (ocidUploadsListID as text)) as text
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strSetValue))
(ocidAElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
(ocidAElement's addAttribute:(ocidAddNode))
set strSetValue to ("YouTUBE PlayList: " & (ocidUploadsListID as text)) as text
(ocidAElement's setStringValue:(strSetValue))
ocidH3Element's addChild:(ocidAElement)
ocidSetHeaderElement's addChild:(ocidH3Element)
########################
#footerに渡すエレメント
set ocidSetFooterElement to refMe's NSXMLElement's elementWithName:("div")
set ocidAElement to refMe's NSXMLElement's elementWithName:("a")
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://quicktimer.cocolog-nifty.com/"))
(ocidAElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
(ocidAElement's addAttribute:(ocidAddNode))
set strContents to ("AppleScriptで生成しました") as text
(ocidAElement's setStringValue:(strContents))
ocidSetFooterElement's addChild:(ocidAElement)
########################
#Articleに渡すエレメント
set ocidSetArticleElement to refMe's NSXMLElement's elementWithName:("div")
set ocidH3Element to refMe's NSXMLElement's elementWithName:("h6")
(ocidH3Element's setStringValue:("ビデオ一覧"))
ocidSetArticleElement's addChild:(ocidH3Element)
########################
#テーブル部生成開始
set ocidTableElement to refMe's NSXMLElement's elementWithName:("table")
#####【caption】
set ocidCaptionElement to refMe's NSXMLElement's elementWithName:("caption")
ocidCaptionElement's setStringValue:("YoutubeApiv3で取得")
ocidTableElement's addChild:(ocidCaptionElement)
#####【colgroup】
set ocidColgroupElement to refMe's NSXMLElement's elementWithName:("colgroup")
#タイトル部の数だけ繰り返し
set listColName to {"LineNO", "Key", "Value"}
repeat with itemColName in listColName
  #######【col】col生成
  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
(ocidColgroupElement's addChild:(ocidAddElement))
end repeat
#テーブルエレメントに追加
ocidTableElement's addChild:(ocidColgroupElement)
#######【thead】
set ocidTheadElement to refMe's NSXMLElement's elementWithName:("thead")
#TR
set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
set listColName to {"\", "Key", "Value"}
#タイトル部の数だけ繰り返し
repeat with itemColName in listColName
  #ここはTDではなくてTHを利用
  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
  #
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:(itemColName))
(ocidAddElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidAddElement's addAttribute:(ocidAddNode))
  #値を入れる
(ocidAddElement's setStringValue:(itemColName))
  #TH→TRにセット
(ocidTrElement's addChild:(ocidAddElement))
end repeat
#TRをTHEADにセット
ocidTheadElement's addChild:(ocidTrElement)
#THEADをテーブルにセット
ocidTableElement's addChild:(ocidTheadElement)
##################################
######【tbody】
set ocidTbodyElement to refMe's NSXMLElement's elementWithName:("tbody")
set CntLineNo to 1 as integer
repeat with itemArray in ocidItemsArray
  
  ##############
  #TRの開始
  set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
  #
  set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("項目番号:" & CntLineNo))
(ocidThElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:("NameID"))
(ocidThElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidThElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("rowspan") stringValue:("4"))
(ocidThElement's addAttribute:(ocidAddNode))
(ocidThElement's setStringValue:(CntLineNo as text))
(ocidTrElement's addChild:(ocidThElement))
  ##################################
  set ocidVideSnippet to (itemArray's objectForKey:("snippet"))
  ##################################
  set ocidResourceId to (ocidVideSnippet's objectForKey:("resourceId"))
  set strVideID to (ocidResourceId's valueForKey:("videoId")) as text
  ##################################
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("videoId"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:("key"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidTdElement's addAttribute:(ocidAddNode))
(ocidTdElement's setStringValue:("videoId"))
(ocidTrElement's addChild:(ocidTdElement))
  #####
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("videoId"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:("key"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidTdElement's addAttribute:(ocidAddNode))
(ocidTdElement's setStringValue:(strVideID))
(ocidTrElement's addChild:(ocidTdElement))
(ocidTbodyElement's addChild:(ocidTrElement))
  
  ##################################
  #TRの開始
  set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
  #
  set strSetValue to (ocidVideSnippet's valueForKey:("title")) as text
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("title"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:("key"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidTdElement's addAttribute:(ocidAddNode))
(ocidTdElement's setStringValue:("title"))
(ocidTrElement's addChild:(ocidTdElement))
  #####
  set strSetValue to (ocidVideSnippet's valueForKey:("title")) as text
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("title"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:("key"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidTdElement's addAttribute:(ocidAddNode))
(ocidTdElement's setStringValue:(strSetValue))
(ocidTrElement's addChild:(ocidTdElement))
(ocidTbodyElement's addChild:(ocidTrElement))
  
  ##################################
  set ocidThumbnails to (ocidVideSnippet's objectForKey:("thumbnails"))
  
  ##################################
  #TRの開始
  set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
  ##
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("thumbnails"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:("key"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidTdElement's addAttribute:(ocidAddNode))
(ocidTdElement's setStringValue:("thumbnails"))
(ocidTrElement's addChild:(ocidTdElement))
  ###
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("thumbnails"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:("key"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidTdElement's addAttribute:(ocidAddNode))
  ####
  set ocidAElement to (refMe's NSXMLElement's elementWithName:("a"))
  set strSetValue to ("https://www.youtube.com/watch?v=" & strVideID) as text
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strSetValue))
(ocidAElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
(ocidAElement's addAttribute:(ocidAddNode))
  ##
  set strSetValue to ((ocidThumbnails's valueForKey:("maxres"))'s valueForKey:("url")) as text
  set ocidImgElement to (refMe's NSXMLElement's elementWithName:("img"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("src") stringValue:(strSetValue))
(ocidImgElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("alt") stringValue:("maxres"))
(ocidImgElement's addAttribute:(ocidAddNode))
  #
(ocidAElement's addChild:(ocidImgElement))
(ocidTdElement's addChild:(ocidAElement))
(ocidTrElement's addChild:(ocidTdElement))
(ocidTbodyElement's addChild:(ocidTrElement))
  
  ##################################
  #TRの開始
  set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
  set ocidSetValue to (ocidVideSnippet's valueForKey:("description"))
  set ocidCdatatValue to (ocidSetValue's stringByReplacingOccurrencesOfString:("\n") withString:("<br>"))
  #TDの開始
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("description"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:("key"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidTdElement's addAttribute:(ocidAddNode))
(ocidTdElement's setStringValue:("description"))
(ocidTrElement's addChild:(ocidTdElement))
  #TDの開始
  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("description"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:("key"))
(ocidTdElement's addAttribute:(ocidAddNode))
  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
(ocidTdElement's addAttribute:(ocidAddNode))
  
  set ocidAddNode to (refMe's NSXMLNode's alloc()'s initWithKind:(refMe's NSXMLTextKind) options:(refMe's NSXMLNodeIsCDATA))
(ocidAddNode's setStringValue:(ocidCdatatValue))
(ocidTdElement's addChild:(ocidAddNode))
(ocidTrElement's addChild:(ocidTdElement))
(ocidTbodyElement's addChild:(ocidTrElement))
  
  
  
  set CntLineNo to CntLineNo + 1 as integer
end repeat
#Tbodyをテーブルにセット
ocidTableElement's addChild:(ocidTbodyElement)

######【tfoot】 TRで
set ocidTfootElement to refMe's NSXMLElement's elementWithName:("tfoot")
set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr")
#項目数を取得して
set numCntCol to (count of ocidItemsArray) as integer
#colspan指定して1行でセット
set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("テーブルの終わり"))
(ocidThElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:(numCntCol as text))
(ocidThElement's addAttribute:(ocidAddNode))
set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row"))
(ocidThElement's addAttribute:(ocidAddNode))
#
set numCntContents to (count of ocidItemsArray) as integer
set strContents to ("項目数 : " & numCntContents) as text
(ocidThElement's setStringValue:(strContents))
#THをTRにセットして
ocidTrElement's addChild:(ocidThElement)
#TRをTFOOTにセット
ocidTfootElement's addChild:(ocidTrElement)
#TFOOTをテーブルにセット
ocidTableElement's addChild:(ocidTfootElement)
ocidSetArticleElement's addChild:(ocidTableElement)

##############################
#HTMLにする
##############################
set ocidHTML to doMakeRootElement({ocidSetHeaderElement, ocidSetArticleElement, ocidSetFooterElement})
#読み取りやすい表示
set ocidXMLdata to ocidHTML's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)


########################################
####出力先/var/folders/XX/(再起動時に削除されます)
set appFileManager to refMe's NSFileManager's defaultManager()
set ocidTemporaryDirPathURL to appFileManager's temporaryDirectory
set ocidVarFoldersDirURL to ocidTemporaryDirPathURL's URLByDeletingLastPathComponent()
set ocidTemporaryItemsPathURL to ocidVarFoldersDirURL's URLByAppendingPathComponent:"TemporaryItems"
##フォルダを作る
set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
set listDone to appFileManager's createDirectoryAtURL:(ocidTemporaryItemsPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
set aliasTemporaryItems to (ocidTemporaryItemsPathURL's absoluteURL()) as alias
##
set strSetValue to ("このディレクトリ内は再起動時に自動で削除されます") as text
set strTmpFileName to ("_起動時削除されるフォルダ") as text
set ocidTmpFileStr to refMe's NSString's stringWithString:(strSetValue)
set ocidTmpFilePathURL to ocidTemporaryItemsPathURL's URLByAppendingPathComponent:(strTmpFileName)
set listDone to ocidTmpFileStr's writeToURL:(ocidTmpFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
##HTML保存先 ファイル名はUUID
set ocidUUID to refMe's NSUUID's alloc()'s init()
set strUUID to ocidUUID's UUIDString
set ocidSaveBaseFilePathURL to ocidTemporaryItemsPathURL's URLByAppendingPathComponent:(strUUID)
set ocidSaveFilePathURL to ocidSaveBaseFilePathURL's URLByAppendingPathExtension:("html")

########################################
set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference)
##Finderで保存先を開く
set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
tell application "Finder"
open location aliasSaveFilePath
end tell



###############################################################
#playlistIDからアップロードビデオのarrayを戻す
to doGetPlistID2ItemsArray(argPlayListID)
  ### 【1】JSONのURL
  set strJsonURL to ("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=" & argPlayListID & "&key=" & strAPIkey & "&maxResults=" & numMaxResults & "") as text
  
  set ocidJsonURLStr to refMe's NSString's stringWithString:(strJsonURL)
  set ocidJsonURL to refMe's NSURL's alloc()'s initWithString:(ocidJsonURLStr)
  ### 【2】URLの内容JSONをNSdataに格納
  set ocidOption to (refMe's NSDataReadingMappedIfSafe)
  set listReadData to refMe's NSData's alloc()'s initWithContentsOfURL:(ocidJsonURL) options:(ocidOption) |error|:(reference)
  set ocidReadData to (item 1 of listReadData)
  ### 【3】NSPropertyListSerializationしてレコードに
  set ocidOption to (refMe's NSJSONReadingMutableContainers)
  set listJSONSerialization to (refMe's NSJSONSerialization's JSONObjectWithData:(ocidReadData) options:(ocidOption) |error|:(reference))
  set ocidPlistDictM to item 1 of listJSONSerialization
  ###
  set ocidItemsArray to ocidPlistDictM's objectForKey:("items")
return ocidItemsArray
end doGetPlistID2ItemsArray




###############################################################
to doChannelId2UploadsListID(toChannelId)
  set jsonChannelsURL to "https://www.googleapis.com/youtube/v3/channels?&part=id,snippet,brandingSettings,contentDetails,statistics,topicDetails&id=" & toChannelId & "&key=" & strAPIkey & ""
  ############コマンド整形
  set strCommandText to "/usr/bin/curl -X GET -H 'Content-Type: application/json;charset=UTF-8' \"" & jsonChannelsURL & "\" --connect-timeout 20"
  ####コマンド実行
  set strResponse to (do shell script strCommandText) as text
  ####戻り値を格納
  set ocidResponse to refMe's NSString's stringWithString:(strResponse)
  ###NSDATA化
  set ocidJsonData to (ocidResponse's dataUsingEncoding:(refMe's NSUTF8StringEncoding))
  ##JSONSiriアライズ
  set listJson to (refMe's NSJSONSerialization's JSONObjectWithData:(ocidJsonData) options:0 |error|:(reference))
  set ocidJson to (item 1 of listJson)
  #DICTに格納
  set ocidJsonDict to (refMe's NSDictionary's alloc()'s initWithDictionary:(ocidJson))
  ####チャンネルの名前を取得
  set ocidItemsArray to ocidJsonDict's objectForKey:("items")
  set ocidItemDict to ocidItemsArray's firstObject()
  set ocidItemContentDetails to ocidItemDict's objectForKey:("contentDetails")
  set ocidrelatedPlaylists to ocidItemContentDetails's objectForKey:("relatedPlaylists")
  set ocidUploadsListID to ocidrelatedPlaylists's valueForKey:("uploads")
return ocidUploadsListID
end doChannelId2UploadsListID


##############################
# 基本的なHTMLの構造
(*
doMakeRootElement({argHeaderContents, argArticleContents, argFooterContents})
HTMLのBODY部
header
article
footerにそれぞれAddchildするデータをリストで渡す
戻り値はRootエレメントにセットされた
NSXMLDocumentを戻すので 保存すればOK
*)
##############################
to doMakeRootElement({argHeaderContents, argArticleContents, argFooterContents})
  #XML初期化
  set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentHTMLKind)
  # DTD付与
  set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
ocidDTD's setName:("html")
ocidXMLDoc's setDTD:(ocidDTD)
  #
  set ocidRootElement to refMe's NSXMLElement's elementWithName:("html")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("lang") stringValue:("ja")
ocidRootElement's addAttribute:(ocidAddNode)
  #
  set ocidHeadElement to refMe's NSXMLElement's elementWithName:("head")
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("title")
ocidAddElement's setStringValue:("ビデオ一覧")
ocidHeadElement's addChild:(ocidAddElement)
  # http-equiv
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/html; charset=UTF-8")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Style-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/css")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Script-Type")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/javascript")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport")
ocidAddElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=720")
ocidAddElement's addAttribute:(ocidAddNode)
ocidHeadElement's addChild:(ocidAddElement)
  #
  set ocidAddElement to refMe's NSXMLElement's elementWithName:("style")
ocidAddElement's setStringValue:("body {margin: 10px;background-color: #FFFFFF;}table {max-width: 720;border-spacing: 0;caption-side: top;font-family: system-ui;}thead th {border: solid 1px #666666;padding: .5ch 1ch;border-block-width: 1px 0;border-inline-width: 1px 0;&:first-of-type {border-start-start-radius: .5em}&:last-of-type {border-start-end-radius: .5em;border-inline-end-width: 1px}}tbody td {word-wrap: break-word;max-width: 420px;border-spacing: 0;border: solid 1px #666666;padding: .5ch 1ch;border-block-width: 1px 0;border-inline-width: 1px 0;&:last-of-type {border-inline-end-width: 1px}}tbody th {border-spacing: 0;border: solid 1px #666666;padding: .5ch 1ch;border-block-width: 1px 0;border-inline-width: 1px 0;}tbody tr:nth-of-type(odd) {background: #F2F2F2;}.kind_string {font-size: 0.75em;}.date_string {font-size: 0.5em;}tfoot th {border: solid 1px #666666;padding: .5ch 1ch;&:first-of-type {border-end-start-radius: .5em}&:last-of-type {border-end-end-radius: .5em;border-inline-end-width: 1px}}img {max-width: 360px;}")
ocidHeadElement's addChild:(ocidAddElement)
ocidRootElement's addChild:(ocidHeadElement)
  #
  #ボディエレメント
  set ocidBodyElement to refMe's NSXMLElement's elementWithName:("body")
  #ヘッダー
  set ocidHeaderElement to refMe's NSXMLElement's elementWithName:("header")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("header")
ocidHeaderElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_header")
ocidHeaderElement's addAttribute:(ocidAddNode)
ocidHeaderElement's addChild:(argHeaderContents)
ocidBodyElement's addChild:(ocidHeaderElement)
  #アーティクル
  set ocidArticleElement to refMe's NSXMLElement's elementWithName:("article")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("article")
ocidArticleElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_article")
ocidArticleElement's addAttribute:(ocidAddNode)
ocidArticleElement's addChild:(argArticleContents)
ocidBodyElement's addChild:(ocidArticleElement)
  #フッター
  set ocidFooterElement to refMe's NSXMLElement's elementWithName:("footer")
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("footer")
ocidFooterElement's addAttribute:(ocidAddNode)
  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_footer")
ocidFooterElement's addAttribute:(ocidAddNode)
ocidFooterElement's addChild:(argFooterContents)
ocidBodyElement's addChild:(ocidFooterElement)
  
ocidRootElement's addChild:(ocidBodyElement)
ocidXMLDoc's setRootElement:(ocidRootElement)
return ocidXMLDoc
end doMakeRootElement

|

« [XML]CDATA(HTML化済みのテキスト)を追加する | トップページ | [NSXMLElement]エレメントのコピー »

YouTube」カテゴリの記事