[Google Chrome]YouTubeのRSS feedを登録するAppleScript
set theURL to "" as Unicode text
set theUserID to "" as Unicode text
set theFLSerRes to "" as Unicode text
set thePLSerRes to "" as Unicode text
set theUserRssURL to "" as Unicode text
set theGoogleReaderURL to "http://www.google.com/reader/view/feed/" as Unicode text
---httpsの場合はこちら---set theGoogleReaderURL to "https://www.google.com/reader/view/feed/" as Unicode text
set theGoogleApiURL to "http://gdata.youtube.com/feeds/base/users/" as Unicode text
---httpsの場合はこちら---set theGoogleApiURL to "http://gdata.youtube.com/feeds/base/users/" as Unicode text
--------------------------全面のURLを取得
tell application "Google Chrome"
activate
set theURL to URL of active tab of window 1 as Unicode text
end tell
------URLに含まれる文字列で種類を判定するための値を作成
set theSearch to "/user/" as Unicode text
set theSerRes to (offset in theURL of theSearch) as integer
set theFLSearch to "list=FL"
set theFLSerRes to (offset in theURL of theFLSearch) as integer
set thePLSearch to "list=PL"
set thePLSerRes to (offset in theURL of thePLSearch) as integer
set theWaSearch to "watch"
set theWaSerRes to (offset in theURL of theWaSearch) as integer
-------------古いタイプのチャンネル判定用
set theOLDFLgSearch to "g/f"
set theOLDFLgSerRes to (offset in theURL of theOLDFLgSearch) as integer
set theOLDFLpSearch to "p/f"
set theOLDFLpSerRes to (offset in theURL of theOLDFLpSearch) as integer
set theOLDFLpafSearch to "p/a/f"
set theOLDFLpafSerRes to (offset in theURL of theOLDFLpafSearch) as integer
set theOLDPLgSearch to "g/c"
set theOLDPLgSerRes to (offset in theURL of theOLDPLgSearch) as integer
set theOLDPLpSearch to "p/c"
set theOLDPLpSerRes to (offset in theURL of theOLDPLpSearch) as integer
set theOLDPLgrSearch to "grid/user/"
set theOLDPLgrSerRes to (offset in theURL of theOLDPLgrSearch) as integer
----------URLの文字数
set theURLlength to the (length of theURL) as integer
-------URLにuserが入っていない場合は新しいプレイリストか個別ページ
if theSerRes is 0 then
-----------------個別のページなら新しいタイプ-USERIDの取得の処理(watch付きURLの場合はプレイリストからの呼び出しは無視)
if theWaSerRes > 1 then
set theVidSearch to "v="
set theVidSerRes to (offset in theURL of theVidSearch) as integer
set theVideoID to characters (theVidSerRes + 2) thru (theVidSerRes + 12) of theURL as Unicode text
set theURL to "http://www.youtube.com/watch?v=" & theVideoID as Unicode text
set theListFLIDcom to "curl " & "'http://www.youtube.com/oembed?url=" & theURL & "&format=json'" & " | awk -F\"author_name\" '{print $2}'| awk -F, '{print $1}' | tr -d '\" :'" as Unicode text
set theUserID to do shell script theListFLIDcom
set theUserRssURL to theGoogleReaderURL & theGoogleApiURL & theUserID & "/uploads"
--------------------------プレイリストがFavorite videosの場合
else if theFLSerRes > 1 then
set theListFLcom to "curl " & "'http://www.youtube.com/oembed?url=" & theURL & "&format=json'" & " | awk -F\"author_name\" '{print $2}'| awk -F, '{print $1}' | tr -d '\" :'" as Unicode text
set theUserID to do shell script theListFLcom
set theUserRssURL to theGoogleReaderURL & "http://gdata.youtube.com/feeds/api/users/" & theUserID & "/favorites"
--------------------------プレイリストが新しいプレイリストIDの場合
else if thePLSerRes > 1 then
set theListID to characters (thePLSerRes + 7) thru (thePLSerRes + 22) of theURL as Unicode text
set theUserRssURL to theGoogleReaderURL & "https://gdata.youtube.com/feeds/api/playlists/" & theListID & "?v=2"
else
set theOLDPLSearch to "list="
set theOLDPLSerRes to offset in theURL of theOLDPLSearch
--------------------------プレイリストが古いプレイリストIDの場合
if theOLDPLSearch > 1 then
set theListID to characters (theOLDPLSerRes + 5) thru (theOLDPLSerRes + 20) of theURL as Unicode text
set theUserRssURL to theGoogleReaderURL & "http://gdata.youtube.com/feeds/api/playlists/" & theListID & "?v=2"
else
-----------------新しいタイプ-USERIDの取得の処理
set theListFLIDcom to "curl " & "'http://www.youtube.com/oembed?url=" & theURL & "&format=json'" & " | awk -F\"author_name\" '{print $2}'| awk -F, '{print $1}' | tr -d '\" :'" as Unicode text
set theUserID to do shell script theListFLIDcom
set theUserRssURL to theGoogleReaderURL & theGoogleApiURL & theUserID & "/uploads"
end if
end if
-----------------ここから旧タイプのチャンネル処理
else
--------------------------古いチャンネルタイプのプレイリストがFavorite videosの場合
if theOLDFLgSerRes > 1 then
set theUserChCom to "echo " & theURL & " | awk -F/ '{print $5}'| awk -F# '{print $1}' | sed -e 's/#g//'"
set theUserID to do shell script theUserChCom
set theUserRssURL to theGoogleReaderURL & "http://gdata.youtube.com/feeds/api/users/" & theUserID & "/favorites"
else if theOLDFLpSerRes > 1 then
set theUserChCom to "echo " & theURL & " | awk -F/ '{print $5}'| awk -F? '{print $1}'| sed -e 's/#p//'"
set theUserID to do shell script theUserChCom
set theUserRssURL to theGoogleReaderURL & "http://gdata.youtube.com/feeds/api/users/" & theUserID & "/favorites"
else if theOLDFLpafSerRes > 1 then
set theUserChCom to "echo " & theURL & " | awk -F/ '{print $5}'| awk -F? '{print $1}'| sed -e 's/#p//'"
set theUserID to do shell script theUserChCom
set theUserRssURL to theGoogleReaderURL & "http://gdata.youtube.com/feeds/api/users/" & theUserID & "/favorites"
--------------------------古いチャンネルタイプのプレイリストの場合
else if theOLDPLgSerRes > 1 then
set theListID to characters (theURLlength - 15) thru (theURLlength) of theURL as Unicode text
set theUserRssURL to theGoogleReaderURL & "http://gdata.youtube.com/feeds/api/playlists/" & theListID & "?v=2"
else if theOLDPLpSerRes > 1 then
set theListID to characters (theURLlength - 15) thru (theURLlength) of theURL as Unicode text
set theUserRssURL to theGoogleReaderURL & "http://gdata.youtube.com/feeds/api/playlists/" & theListID & "?v=2"
else if theOLDPLgrSerRes > 1 then
set theListID to characters (theURLlength - 15) thru (theURLlength) of theURL as Unicode text
set theUserRssURL to theGoogleReaderURL & "http://gdata.youtube.com/feeds/api/playlists/" & theListID & "?v=2"
else
-----------------古いタイプのチャンネルやプレイリストからUSERIDを取得する場合
set theUserChCom to "echo " & theURL & " | awk -F/ '{print $5}'| awk -F# '{print $1}'"
set theUserID to do shell script theUserChCom
set theUserRssURL to theGoogleReaderURL & theGoogleApiURL & theUserID & "/uploads"
end if
end if
--------------------------GoogleReader用のURLを開きます
tell application "Google Chrome"
make new window
tell window 1
tell active tab
open location theUserRssURL
end tell
end tell
end tell
「GetYouTubeFeedsGoogleChrome.scpt.zip」をダウンロード
「GetYouTubeFeedsGoogleChrome.rtf」をダウンロード
スクリプトメニューに入れて使います。
スクリプトメニューの出し方はこちら
| 固定リンク
「AppleScript」カテゴリの記事
- 濁音 半濁音 置換用レコード(2023.08.21)
- [AppleScript]キーノートの書類サイズを指定して作成(2022.01.09)
- [awk]行頭のスペースを削除する(subで置き換え)(2021.11.16)
- [SpotLight]選択範囲でSpotLight検索(2021.11.03)
- [AppleScript]リソースフォーク(カスタムアイコン)削除(2021.10.12)
「YouTube Rss」カテゴリの記事
- YouTubeのユーザーチャンネルアップロードFEEDを取得する(2012.01.20)
- [Google Chrome]YouTubeのRSS feedを登録するAppleScript(2012.01.20)
- [Safari]YouTubeのユーザーチャンネルのRSSを登録するAppleScript 新旧混在版(2012.01.19)
- [Safari]YouTubeのユーザーチャンネルのRSSを登録するAppleScriptその2(2012.01.19)
- [Safari]YouTubeのユーザーチャンネルのRSSを登録するAppleScript(2012.01.18)