[AppleScript]YouTubeビデオダウンローダー【挫折】
ビデオのダウンロードを出来るようにしよう
とおもったんだけど
ちょっと暗礁に乗り上げ挫折。
YouTubeのURLは
http://www.youtube.com/watch?v=1AJmKkU5POA
こんな感じで
この
1AJmKkU5POAが
ビデオIDになっていて
http://gdata.youtube.com/feeds/api/videos/1AJmKkU5POA
で
Feed
http://www.youtube.com/get_video_info?&video_id=1AJmKkU5POA
で
ビデオinfoファイルがダウンロードされるのですが
この
get_video_info
を元にダウンロードしようとおもったんですが
埋め込み禁止にしていると
ビデオファイルのURLを
get_video_infoがかえなさい
トホホ
他の方法を考えます
とりあえず
検討していた段階のスクリプト
set OriginalURL to ""
set VitChrCnt to "11" as number
set nowTime to my DateAndTIme(current date) & ".txt" as Unicode text
tell application "Finder"
activate
display dialog "YouTubeURLをペーストしてください" default answer the OriginalURL with icon 1 with title "URLをペーストしてください"
copy the result as list to {the OriginalURL, BottPressNo}
set ReplaceText to the OriginalURL as Unicode text
end tell
set MyVIDstring to my ref2VidName(ReplaceText)
set VIDcnt to the offset of "v=" in MyVIDstring
set YouTubeVid to characters (VIDcnt + 1) thru VitChrCnt of MyVIDstring as Unicode text
set YouTubeFeed to "http://gdata.youtube.com/feeds/api/videos/" & YouTubeVid as Unicode text
set YouTubeformat5 to "http://www.youtube.com/v/" & YouTubeVid & "?f=videos&app=youtube_gdata" as Unicode text
set YouTubevideoinfo to "http://www.youtube.com/get_video_info?&video_id=" & YouTubeVid as Unicode text
set YouTubeVideoImg to "http://i1.ytimg.com/vi/" & YouTubeVid & "/hqdefault.jpg"
set savetmpfile to "/tmp/" & nowTime as Unicode text
do shell script "curl -o" & " '" & savetmpfile & "'" & " " & "'" & YouTubevideoinfo & "'"
tell application "Jedit X"
open (POSIX path of savetmpfile)
tell document 1
delay 1
replaceAll string "%24" to "$" with select all and case sensitive
replaceAll string "%2D" to "-" with select all and case sensitive
replaceAll string "%5F" to "_" with select all and case sensitive
replaceAll string "%2E" to "." with select all and case sensitive
replaceAll string "%2B" to "+" with select all and case sensitive
replaceAll string "%21" to "!" with select all and case sensitive
replaceAll string "%2A" to "*" with select all and case sensitive
replaceAll string "%22" to "\"" with select all and case sensitive
replaceAll string "%27" to "'" with select all and case sensitive
replaceAll string "%28" to "(" with select all and case sensitive
replaceAll string "%29" to ")" with select all and case sensitive
replaceAll string "%3B" to ";" with select all and case sensitive
replaceAll string "%2F" to "/" with select all and case sensitive
replaceAll string "%3F" to "?" with select all and case sensitive
replaceAll string "%3A" to ":" with select all and case sensitive
replaceAll string "%40" to "@" with select all and case sensitive
replaceAll string "%3D" to "=" with select all and case sensitive
replaceAll string "%26" to "&" with select all and case sensitive
replaceAll string "%7C" to "" with select all and case sensitive
replaceAll string "%2C35" to "" with select all and case sensitive
replaceAll string "%253A" to "%3A" with select all and case sensitive
replaceAll string "%252C" to "%2C" with select all and case sensitive
replaceAll string "" to "" with select all, grep and case sensitive
replaceAll string "^tc.*" to "" with select all, case sensitive, grep and entire word
set theRange to {loc:1, len:1}
set theParaNum to (loc of theRange) + (len of theRange) - 1
delete paragraph theParaNum
set selected paragraph range to theRange
set theData to selected text
tell application "Safari"
activate
open location theData
tell document 1
delay 4
close
end tell
end tell
---close saving no
end tell
end tell
on ref2VidName(MyVID)
set tmp to AppleScript's text item delimiters
set AppleScript's text item delimiters to "V="
set MyVIDstring to last text item of (MyVID as string)
set AppleScript's text item delimiters to tmp
return MyVIDstring
end ref2VidName
--------------------------------------------------#ここからサブルーチン
to DateAndTIme(theDate)
set y to (year of theDate)
set m to my monthNumStr(month of theDate)
set d to day of theDate
set hms to time of theDate
set hh to h of sec2hms(hms)
set mm to m of sec2hms(hms)
set ss to s of sec2hms(hms)
return (y as text) & my zero1(m) & my zero1(d) & "_" & zero1(hh) & zero1(mm) & zero1(ss)
----return (y as text) & my zero1(m) & my zero1(d)
end DateAndTIme
--------------------------------------------------#ここからサブルーチン
to monthNumStr(theMonth)
set monList to {January, February, March, April, May, June, July, August, September, October, November, December}
repeat with i from 1 to 12
if item i of monList is theMonth then exit repeat
end repeat
return i
end monthNumStr
--------------------------------------------------#ここからサブルーチン
to zero1(n)
if n < 10 then
return "0" & n
else
return n as text
end if
end zero1
--------------------------------------------------#ここからサブルーチン
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
--------------------------------------------------#ここからサブルーチン
to sec2hms(sec)
set ret to {h:0, m:0, s:0}
set h of ret to sec div hours
set m of ret to (sec - (h of ret) * hours) div minutes
set s of ret to sec mod minutes
return ret
end sec2hms
これは
おとなしく他の方法を良いですね
Pythonとか
でやった方が良さそうですなぁ〜
遠い目線
| 固定リンク
「YouTube」カテゴリの記事
- 【過去記事フォロー】YouTubeのサムネイル(2022.06.17)
- 【過去記事フォロー】[YouTube]YouTubeのサムネイル画像(default.webp mqdefault.webp hqdefault.webp sddefault.webp maxresdefault.webp)(2016.03.02)
- [MPEG-DASH]YouTubeビデオをダウンロードする。(2014-15版)(2015.04.05)
- [YouTube]YouTubeのサムネイル画像(default.jpg mqdefault.jpg hqdefault.jpg sddefault.jpg maxresdefault.jpg)(2013.08.08)
- [YouTube]Safariを使ってYouTubeのビデオをダウンロードする(2012.01.26)
この記事へのコメントは終了しました。
コメント