tell application "Google Chrome"
activate
set theURL to URL of active tab of window 1 as text
set theTitle to title of active tab of window 1 as text
end tell
set theVidCom to "echo " & quoted form of theURL & "| awk -F \"v=\" '{print($2)}' |awk -F \"&\" '{print($1)}' " as text
set theVid to do shell script theVidCom as text
set theBloggerUrl to "http://www.blogger.com/blog-this.g?"
set theImgUrl to "http://i4.ytimg.com/vi/" & theVid & "/hqdefault.jpg"
set theShortUrl to "http://youtu.be/" & theVid
set theHtmlLine1 to "<div style=\\\"display: block; margin: auto;\\\">"
set theHtmlLine2 to "<a rel=\\\"nofollow\\\" href=\\\"" & theShortUrl & "\\\" class=\\\"youtubelink\\\" title=\\\"" & theTitle & "\\\">"
set theHtmlLine3 to "<img src=\\\"" & theImgUrl & "\\\" border=\\\"0\\\" class=\\\"youtubelinkimg\\\" alt=\\\"" & theTitle & "\\\" /></a>"
set theHtmlLine4 to "</div>"
set theHtmlLine to (theHtmlLine1 & theHtmlLine2 & theHtmlLine3 & theHtmlLine4) as text
set theUrlDecodeHtml to do shell script "php -r 'echo urlencode(\"" & theHtmlLine & "\");'"
set theUrlDecodeImgUrl to do shell script "php -r 'echo urlencode(\"" & theImgUrl & "\");'"
set theUrlDecodeTitle to do shell script "php -r 'echo urlencode(\"" & theTitle & "\");'"
set theHtmlLine to my replace(theHtmlLine, "\\", "") as text
set theBloggerUrl to theBloggerUrl & "n=" & theUrlDecodeTitle & "&b=" & theUrlDecodeHtml & "&eurl=" & theUrlDecodeImgUrl
tell application "Google Chrome"
activate
make new window
tell window 1
tell active tab
open location theBloggerUrl
end tell
end tell
end tell
tell application "Finder"
activate
display dialog "HTMLが出来ました" default answer the theHtmlLine with icon 1 with title "HTMLが出来ました" default button 1
end tell
to replace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end replace