2010年1月13日水曜日

YouTubeからFLVファイルを取得

スズキです。

ちょっと調べてみました。(FireBugの"接続"を見ながら...)

まずは適当な動画表示画面にある「埋込みタグ」から、以下のようなURLを抽出します。
http://www.youtube.com/v/i6_Xi5H_3Pg&hl=ja_JP&fs=1

このURLを表示すると、プレーヤー込みの動画が表示されるのですが、
動画を再生すると、FireBugの"接続"に下記のようなURLが表示されます。
http://www.youtube.com/get_video_info?&video_id=i6_Xi5H_3Pg&el=embedded&ps=default&eurl=&hl=ja_JP

このURLの内容は以下の通りです。

--------
status=ok&vq=1&fmt_list=22%2F2000000%2F9%2F0%2F115%2C35%2F640000%2F9%2F0%2F115%2C34%2F0%2F9%2F0%2F115%2C5%2F0%2F7%2F0%2F0&author=Google&watermark=http%3A%2F%2Fs.ytimg.com%2Fyt%2Fswf%2Flogo-vfl106645.swf%2Chttp%3A%2F%2Fs.ytimg.com%2Fyt%2Fswf%2Fhdlogo-vfl100714.swf&muted=0&avg_rating=4.85185185185&video_id=i6_Xi5H_3Pg&length_seconds=16&allow_embed=1&fmt_url_map=22%7Chttp%3A%2F%2Fv24.lscache6.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Cratebypass%26itag%3D22%26ipbits%3D0%26sver%3D3%26ratebypass%3Dyes%26expire%3D1263387600%26key%3Dyt1%26signature%3DD3103501F7FA38392FCA190032F7EE1311969A03.2DF460578FD5A5E928FC10AEFA82A3E3A456923E%26id%3D8bafd78b91ffdcf8%2C35%7Chttp%3A%2F%2Fv3.lscache4.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%26algorithm%3Dthrottle-factor%26itag%3D35%26ipbits%3D0%26burst%3D40%26sver%3D3%26expire%3D1263387600%26key%3Dyt1%26signature%3D59F59404937EB1F516C7A8770258C794B8933664.4448156958A3C1C7A9A9A004CEF96EB8A4D31180%26factor%3D1.25%26id%3D8bafd78b91ffdcf8%2C34%7Chttp%3A%2F%2Fv22.lscache1.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%26algorithm%3Dthrottle-factor%26itag%3D34%26ipbits%3D0%26burst%3D40%26sver%3D3%26expire%3D1263387600%26key%3Dyt1%26signature%3D1332CF7CECCEB9E6C51862524500A8EC9F636AEC.B2A619D57C215E9699922EE60DAF6A0DA2B384E8%26factor%3D1.25%26id%3D8bafd78b91ffdcf8%2C5%7Chttp%3A%2F%2Fv12.lscache8.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%26algorithm%3Dthrottle-factor%26itag%3D5%26ipbits%3D0%26burst%3D40%26sver%3D3%26expire%3D1263387600%26key%3Dyt1%26signature%3DB510FC1B80C090A8683E37D39E02AB3661D5090F.0E13F9F55B3DC4D8C412B37D61923680D38870AB%26factor%3D1.25%26id%3D8bafd78b91ffdcf8&fmt_stream_map=22%7Chttp%3A%2F%2Fv24.lscache6.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Cratebypass%26itag%3D22%26ipbits%3D0%26sver%3D3%26ratebypass%3Dyes%26expire%3D1263387600%26key%3Dyt1%26signature%3DD3103501F7FA38392FCA190032F7EE1311969A03.2DF460578FD5A5E928FC10AEFA82A3E3A456923E%26id%3D8bafd78b91ffdcf8%2C35%7Chttp%3A%2F%2Fv3.lscache4.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%26algorithm%3Dthrottle-factor%26itag%3D35%26ipbits%3D0%26burst%3D40%26sver%3D3%26expire%3D1263387600%26key%3Dyt1%26signature%3D59F59404937EB1F516C7A8770258C794B8933664.4448156958A3C1C7A9A9A004CEF96EB8A4D31180%26factor%3D1.25%26id%3D8bafd78b91ffdcf8%2C34%7Chttp%3A%2F%2Fv22.lscache1.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%26algorithm%3Dthrottle-factor%26itag%3D34%26ipbits%3D0%26burst%3D40%26sver%3D3%26expire%3D1263387600%26key%3Dyt1%26signature%3D1332CF7CECCEB9E6C51862524500A8EC9F636AEC.B2A619D57C215E9699922EE60DAF6A0DA2B384E8%26factor%3D1.25%26id%3D8bafd78b91ffdcf8%2C5%7Chttp%3A%2F%2Fv12.lscache8.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%26algorithm%3Dthrottle-factor%26itag%3D5%26ipbits%3D0%26burst%3D40%26sver%3D3%26expire%3D1263387600%26key%3Dyt1%26signature%3DB510FC1B80C090A8683E37D39E02AB3661D5090F.0E13F9F55B3DC4D8C412B37D61923680D38870AB%26factor%3D1.25%26id%3D8bafd78b91ffdcf8&token=vjVQa1PpcFOx9GSRmMUYe4r_PmgPx_WlmYfx_t4Y88U%3D&thumbnail_url=http%3A%2F%2Fi2.ytimg.com%2Fvi%2Fi6_Xi5H_3Pg%2Fdefault.jpg&fmt_map=22%2F2000000%2F9%2F0%2F115%2C35%2F640000%2F9%2F0%2F115%2C34%2F0%2F9%2F0%2F115%2C5%2F0%2F7%2F0%2F0&allow_ratings=1&plid=AAR9Bb-6gyn9p9Co&keywords=Google%2Csearch%2Ctip&title=15+second+search+tip%3A+Weather&ftoken=&track_embed=0
--------

この中の、以下の部分がFLVのURLエンコードされたURLになってます。

※ 他にも似たようなURLがありますが、ダウンロードしてみると、
フォーマットがMP4だったりして、いまいちルールはわかっていません...

--------
http%3A%2F%2Fv12.lscache8.c.youtube.com%2Fvideoplayback%3Fip%3D0.0.0.0%26sparams%3Did%252Cexpire%252Cip%252Cipbits%252Citag%252Calgorithm%252Cburst%252Cfactor%26algorithm%3Dthrottle-factor%26itag%3D5%26ipbits%3D0%26burst%3D40%26sver%3D3%26expire%3D1263387600%26key%3Dyt1%26signature%3DB510FC1B80C090A8683E37D39E02AB3661D5090F.0E13F9F55B3DC4D8C412B37D61923680D38870AB%26factor%3D1.25%26id%3D8bafd78b91ffdcf8&fmt_stream_map=22
--------

これを次のサイトなどでURLデコードすると、
http://home.kendomo.net/board/decode/decode.php
次のようなFLVがダウンロードできるURLができあがります。
http://v12.lscache4.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Calgorithm%2Cburst%2Cfactor&algorithm=throttle-factor&itag=34&ipbits=0&burst=40&sver=3&expire=1263387600&key=yt1&signature=CC76039244F5BAD5EAF65ECE327ED0088DD63BEC.96826CBCB1DC41A6DBA0EF67DD5AC06B32BA3B07&factor=1.25&id=2d6e973bb2b8d655&

この仕様が変わるのも、時間の問題か...

--------
http://www.suz-lab.com

0 コメント: