[JS] Facebook 影片一鍵下載,按一下即可!

其實從以前就很討厭為了抓影片要開這個軟體開那個軟體的,一些影片下載網頁也會失聯、失效,自從開始摸索JavaScript後就喜歡直接寫一小段來下載影片XDDD

Facebook 的影片也是使用Flash播放器,所以影片的實體位置也是能在原始碼中發現的...
老規矩~文章看不懂得請直接跳到最後取連結囉XD


部分資料參考: http://tchlog.blogspot.tw/2013/03/facebook.html


這是FB影片播放器部分的原始碼:
<embed type="application/x-shockwave-flash" src="https://fbstatic-a.akamaihd.net/rsrc.php/v1/yM/r/314RdiNN3BM.swf" width="720" height="405" style="display: block;" id="swf_id_5176a249963bd8057769145" name="swf_id_5176a249963bd8057769145" bgcolor="#000000" quality="high" allowfullscreen="true" allowscriptaccess="always" salign="tl" scale="noscale" wmode="opaque" flashvars="params=%7B%22autoplay%22%3Afalse%2C%22autorewind%22%3Atrue%2C%22default_hd%22%3Afalse%2C%22dtsg%22%3A%22AQAJ0mVh%22%2C%22embedded%22%3Afalse%2C%22permalink_url%22%3A%22https%3A%5C%2F%5C%2Fwww.facebook.com%5C%2Fphoto.php%3Fv%3D518832681473257%22%2C%22source%22%3A%22permalink%22%2C%22start_index%22%3A0%2C%22start_muted%22%3Afalse%2C%22video_data%22%3A%5B%7B%22hd_src%22%3A%22https%3A%5C%2F%5C%2Ffbcdn-video-a.akamaihd.net%5C%2Fhvideo-ak-prn1%5C%2Fv%5C%2F725272_518834294806429_63420_n.mp4%3Foh%3Dc95fb78d5216f99a8042a1a8e97828d2%26oe%3D5176BD81%26__gda__%3D1366737116_bed2ab9b641ff6675542041c27ae9cf2%22%2C%22index%22%3A0%2C%22rotation%22%3A0%2C%22sd_src%22%3A%22https%3A%5C%2F%5C%2Ffbcdn-video-a.akamaihd.net%5C%2Fhvideo-ak-frc1%5C%2Fv%5C%2F763405_518834291473096_44059_n.mp4%3Foh%3D8c14904e74172750d8442b0cfbf11dae%26oe%3D5176C299%26__gda__%3D1366736990_521f95e2b18ba8427b935b60f60bee93%22%2C%22thumbnail_src%22%3A%22https%3A%5C%2F%5C%2Ffbcdn-vthumb-a.akamaihd.net%5C%2Fhvthumb-ak-prn1%5C%2F50761_518834331473092_518832681473257_43437_1033_b.jpg%22%2C%22video_duration%22%3A79%2C%22video_id%22%3A%22518832681473257%22%7D%5D%7D&amp;width=720&amp;height=405&amp;user=100000426102420&amp;log=no&amp;div_id=id_5176a249963bd8057769145&amp;swf_id=swf_id_5176a249963bd8057769145&amp;browser=Chrome+24.0.1312.56&amp;tracking_domain=https%3A%2F%2Fpixel.facebook.com&amp;post_form_id=&amp;string_table=https%3A%2F%2Fwww.facebook.com%2Fflash_strings.php%2Ft13667292896%2Fzh_TW">

decodeURIComponent(document.getElementsByTagName('embed')[0].getAttribute('flashvars'));

經過上面這段的URL Decode之後顯示的大概是這樣:
"params={"autoplay":false,"autorewind":true,"default_hd":false,"dtsg":"AQAJ0mVh","embedded":false,"permalink_url":"https:\/\/www.facebook.com\/photo.php?v=518832681473257","source":"permalink","start_index":0,"start_muted":false,"video_data":[{"hd_src":"https:\/\/fbcdn-video-a.akamaihd.net\/hvideo-ak-prn1\/v\/725272_518834294806429_63420_n.mp4?oh=7621502c24864420014b98bd13ba70f8&oe=5176D041&__gda__=1366741916_801ba08e84fb19203283637426de0cae","index":0,"rotation":0,"sd_src":"https:\/\/fbcdn-video-a.akamaihd.net\/hvideo-ak-frc1\/v\/763405_518834291473096_44059_n.mp4?oh=cf289dc7f71936eacf4c26410d04c412&oe=5176D559&__gda__=1366741790_80320fa3067a82ad8a34c7c80bccd0c7","thumbnail_src":"https:\/\/fbcdn-vthumb-a.akamaihd.net\/hvthumb-ak-prn1\/50761_518834331473092_518832681473257_43437_1033_b.jpg","video_duration":79,"video_id":"518832681473257"}]}&width=720&height=405&user=100000426102420&log=no&div_id=id_5176b1c28f90d3d83545511&swf_id=swf_id_5176b1c28f90d3d83545511&browser=Chrome+24.0.1312.56&tracking_domain=https://pixel.facebook.com&post_form_id=&string_table=https://www.facebook.com/flash_strings.php/t13667332506/zh_TW"

然後再對字串進行處理,最後取得HD畫質影片網址:
var params = decodeURIComponent(document.getElementsByTagName('embed')[0].getAttribute('flashvars'));
while( params.indexOf("\\") != -1)
params = params.replace("\\","");
params = params .substr(params.search("hd_src")+9,params.search('","index"')-(params.search("hd_src")+9));

將下面這個連結直接拉到書籤列或者存成我的最愛即可一鍵下載FaceBook Video囉XD!
Download FB Video

本文僅供技術討論分享,由於FaceBook時常改版,如果該連結無法順利下載影片,敬請告知!

留言

  1. 大大 我對照了祤痕論壇按了F12 選擇了Consoe
    輸入了指令 可是輸入後卻沒他說的會有影片網址跑出來'
    不知道是否輸入的指令過期了呢? @@

    回覆刪除
    回覆
    1. 後來發現,FB有些影片沒有HD畫質,導致文章那個指令有小錯誤
      var params = decodeURIComponent(document.getElementsByTagName('embed')[0].getAttribute('flashvars'));
      while( params.indexOf("\\") != -1)
      params = params.replace("\\","");
      params = params .substr(params.search("sd_src")+9,params.search('","thumbnail_src')-(params.search('sd_src')+9));
      location.assign(params );

      刪除

張貼留言

本月最夯