用python做youtube自動化下載器 思路
阿新 • • 發佈:2021-01-11
[TOC](用python做youtube自動化下載器)
> 根據 [savefrom條例](https://en.savefrom.net/terms.html)
> 本例項及教程只用於學習交流用,權利歸**savefrom.net**所有
# 0. 思路
使用python從savefrom平臺上獲取指定youtube視訊下載連結進行下載,不過savefrom的資料是用javascript加密的,這也是難度所在
本教程主要介紹製作思路,下一篇會介紹製作python
本教程根據[stakoverflow 回答](https://stackoverflow.com/questions/65443895/how-to-input-data-via-a-post-request-using-requests-in-python/65650186#65650186)製作
# 1.準備
## i.savfrom.net
一個網站可以免費下載youtube視訊
# 2. 探索並規劃獲取方式
## i.總覽
開啟[https://en.savefrom.net/1-youtube-video-downloader-4/](https://en.savefrom.net/1-youtube-video-downloader-4/)可以看見頁面主要就一個from表單輸入框和提交按鈕組成
![video](https://img-blog.csdnimg.cn/2021011118231815.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwODMyOTYw,size_16,color_FFFFFF,t_70)
## ii. 獲取該網頁取到下載url的請求
在chrome或其他瀏覽器按`F12`開啟開發者控制檯,點開`Network`選項卡
![Network](https://img-blog.csdnimg.cn/20210111183949483.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwODMyOTYw,size_16,color_FFFFFF,t_70)
接下來模擬正常的使用者流程,在輸入框輸入一個youtube視訊地址,比如這個`https://www.youtube.com/watch?v=IjJmTeBSEzU`,然後點選`Download`提交url獲取下載url,然後我們可以發現下面已經出現了下載連結。然後我們在`network`選項卡內可以發現一個特殊的申請`saveform.php`(如果沒發現可以多提交幾次,就會發現每次提交都有這個請求或者看html裡的form元素的src地址就是`savform.php`)
![saveform](https://img-blog.csdnimg.cn/20210111184405898.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwODMyOTYw,size_16,color_FFFFFF,t_70)
我們就可以確定關於下載連結會出現在這個請求的返回值內。
## iii. 在本地獲取請求
在本地用IDE的http工具或者python構建出post請求程式碼,筆者用的是pycharm的`httpClient`(按2下左`Shift`,然後輸入`Tools`,然後回車進入選單,然後點選`httpClient`下的第一個)
![httpclient](https://img-blog.csdnimg.cn/20210111185059155.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwODMyOTYw,size_16,color_FFFFFF,t_70)
把請求裡第二個`headers`的內容全部複製然後格式化然後構建post請求
![headers](https://img-blog.csdnimg.cn/20210111185528413.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwODMyOTYw,size_16,color_FFFFFF,t_70)
然後把下面的`formdata`的引數也複製進來,記得和`headers`換行
![formdata](https://img-blog.csdnimg.cn/20210111185702329.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwODMyOTYw,size_16,color_FFFFFF,t_70)
```
POST https://en.savefrom.net/savefrom.php
cache-Control: no-cache
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
accept-encoding: gzip, deflate, br
accept-language: zh-CN,zh;q=0.9,en;q=0.8
content-type: application/x-www-form-urlencoded
cookie: lang=en; country=CN; uid=fd94a82a406a8dd4; sfHelperDist=72; reference=14; clickads-e2=90; poropellerAdsPush-e=63; promoBlock=64; helperWidget=92; helperBanner=42; framelessHdConverter=68; inpagePush2=68; popupInOutput=9; _ga=GA1.2.799702638.1610248969; _gid=GA1.2.628904587.1610248969; PHPSESSID=4aojkm49oj7h3de65pekqii337; x-requested-with=; PHPSESSUD=122fb7e10af37e23d99e896fd188744f; _gat_helperWidget=1; _gat_inpagePush2=1
origin: https://en.savefrom.net
pragma: no-cache
referer: https://en.savefrom.net/1-youtube-video-downloader-4/
sec-ch-ua: "Google Chrome";v="87", " Not;A Brand";v="99", "Chromium";v="87"
sec-ch-ua-mobile: ?0
sec-fetch-dest: iframe
sec-fetch-mode: navigate
sec-fetch-site: same-origin
sec-fetch-user: ?1
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
sf_url=https://www.youtube.com/watch?v=YPvtz1lHRiw&sf_submit=&new=1&lang=en&app=&country=cn&os=Windows&browser=Chrome
```
如果配置沒錯,這個時候你執行後會顯示出和在瀏覽器裡一樣的結果,然後可以發現引數裡的`sf_url`就是需要下載的youtube地址
## iv.解析請求結果
把取到的結果儲存在本地然後在瀏覽器開啟儲存的本地檔案,然後彈出一個彈窗後會發現這個頁面什麼都沒有,但其實如果你在`console`輸入`window`會發現有很多變數和函式,其中就有我們需要的加密後的url和解密函式
![window](https://img-blog.csdnimg.cn/20210111190704519.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwODMyOTYw,size_16,color_FFFFFF,t_70)
經過彈窗提示我們可以發現是這個html的js發現了我們不在他的網站上然後刪除了顯示下載url的程式碼所以我們才什麼都看不到,開啟`source`選項卡或者用IDE開啟原始碼檢視
![sources](https://img-blog.csdnimg.cn/20210111191030803.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwODMyOTYw,size_16,color_FFFFFF,t_70)
掃一下這個原始碼,我們可以看見一些加密解密函式,被加密的亂碼資訊,雜湊對照表,和一些奇怪的賦值操作,如圖
![code](https://img-blog.csdnimg.cn/20210111191252764.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwODMyOTYw,size_16,color_FFFFFF,t_70)
我們可以看見,js部分由一個大閉包組成
- 第3行到第9行是宣告函式
- 第10行是給`$b`賦值`this`也就是`window`
- 第11到第13行是賦值3個變數
- 第14,15行是對變數執行一些操作,這個也是我們重點關注的,畢竟執行加密,解密方法只可能在這
第14,15行格式化後如下
```javascript
this.$d = $d;
this.$a = $a;
this.$e = $e;
this.$k = $k;
this.$c = $c;
$c = _q($c);
$c = _b($c);
_m($b, $c);
```
去掉前5行沒有意義的變數互換值,加密解密函式存在的範圍就在最後3行
```javascript
$c = _q($c);
$c = _b($c);
_m($b, $c);
```
然後開始一個個試
先在`console`裡輸入第一行
![console](https://img-blog.csdnimg.cn/20210111191900960.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwODMyOTYw,size_16,color_FFFFFF,t_70)
然後就出現了明文,所以我們就確定這個是我們需要的解密函式
接下來輸入第二行
![console2](https://img-blog.csdnimg.cn/20210111192029210.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwODMyOTYw,size_16,color_FFFFFF,t_70)
發現出現了和上面一模一樣的明文,所以這個也是解密函式
接下來輸入第三行
發現這個執行了那段程式碼,這個應該是執行函式,所以我們現在就找到了解密函式位於js部分的最後幾行
## v.解析解密後的結果
把`console`裡用解密函式解密出的結果複製出來會得到一個JavaScript指令碼
```javascript
(function(){
function del(){while(document.body.firstChild){document.body.removeChild(document.body.firstChild);}};
if(window.location.hostname.search(/(?:^|\.|@)(savefrom\.net|sfrom\.net|savefrom\.com\.au|51\.159\.57\.158|(?:fe\d*|test)-front\.sf-apps\.com)$/i) == -1)
{
alert('Please go to http://savefrom.net/ to get direct links');
del();
return;
}
function showResult(){
var success = false;
try
{
var d = window.parent.document;
if(d && d.getElementById)
{
var e = d.getElementById('sf_result');
if(e && e.innerHTML)
{
window.parent.sf.finishRequest(true);;
e.innerHTML = '';
window.parent.sf.videoResult.show({"id":"YPvtz1lHRiw","cipher":false,"meta":{"title":"The Most Genius Plays in Football","source":"https:\/\/www.youtube.com\/watch?v=YPvtz1lHRiw","duration":"7:03","tags":"lionel messi,football tiki taka,football highlight,football team plays,kevin de bruyne,mesut \u00f6zil,paul pogba,cristiano ronaldo,adama traore,luka modric,toni kroos,andres iniesta,kylian mbappe,neymar jr,zlatan ibrahimovic,franck ribery,paulo dybala,philippe coutinho,robert lewandowski,barcelona,real madrid,liverpool,manchester city"},"thumb":"https:\/\/i.ytimg.com\/vi\/YPvtz1lHRiw\/hqdefault.jpg","itags":["18","22","133","134","135","136","137","140","160","242","243","244","247","248","249","250","251","278"],"video_quality":["1080","720","480","360","240","144"],"url":[{"url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=18&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fmp4&ns=H2IuXFgrekwcd2kUgtraypIF&gir=yes&clen=35202709&ratebypass=yes&dur=423.137&lmt=1603720879883261&mt=1610277156&fvip=4&c=WEB&txp=5531422&n=9544-WEiIwBMq_&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIgN_iBsjO6zSiW9dcOYYExfjeVuy1YCXtWcKT0cz2kMcECIQCMre2rssbqkWdohk9K4Ej8B8r9gARVc0-kAHVqhV1teQ%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","name":"MP4","subname":"360","info_url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=18&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fmp4&ns=H2IuXFgrekwcd2kUgtraypIF&gir=yes&clen=35202709&ratebypass=yes&dur=423.137&lmt=1603720879883261&mt=1610277156&fvip=4&c=WEB&txp=5531422&n=9544-WEiIwBMq_&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIgN_iBsjO6zSiW9dcOYYExfjeVuy1YCXtWcKT0cz2kMcECIQCMre2rssbqkWdohk9K4Ej8B8r9gARVc0-kAHVqhV1teQ%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","type":"mp4","ext":"mp4","downloadable":false,"quality":"360","audio":false,"no_audio":false,"itag":"18","filesize":35202709,"attr":{"title":"video format: 360","class":""},"info_token":"0c41b67f74ccb97e50f2e64fe5f4625a"},{"url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=22&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fmp4&ns=H2IuXFgrekwcd2kUgtraypIF&ratebypass=yes&dur=423.137&lmt=1603723118280830&mt=1610277156&fvip=4&c=WEB&txp=5535432&n=9544-WEiIwBMq_&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIgWg_KEKuXDFH-OcphoOxU2tjE9B0WnidilKpa-vtbmigCIQD-eJlhFHZMi1VzRYI_jh0RZaMiLkkXYWnwGM2TJp0bLA%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D&title=The%20Most%20Genius%20Plays%20in%20Football","name":"MP4","subname":"720","info_url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=22&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fmp4&ns=H2IuXFgrekwcd2kUgtraypIF&ratebypass=yes&dur=423.137&lmt=1603723118280830&mt=1610277156&fvip=4&c=WEB&txp=5535432&n=9544-WEiIwBMq_&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIgWg_KEKuXDFH-OcphoOxU2tjE9B0WnidilKpa-vtbmigCIQD-eJlhFHZMi1VzRYI_jh0RZaMiLkkXYWnwGM2TJp0bLA%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","type":"mp4","ext":"mp4","downloadable":true,"quality":"720","audio":false,"no_audio":false,"itag":"22","attr":{"title":"video format: 720","class":""},"info_token":"674fa89ee246148990b3f36e750a5d32"},{"url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=137&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fmp4&ns=QmTnf2BHCkCLm1nUC3OlqIwF&gir=yes&clen=177708494&dur=422.999&lmt=1603723164407782&mt=1610277156&fvip=4&keepalive=yes&c=WEB&txp=5535432&n=TD5jnO4_esWW9m&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRQIhANMFMA1ypwGQjiGT_DlqlYwfqcqu1IlKZGoCrdIqWmzHAiAyOJJHIzUBcMQ6WBeEnepV4UlD3TY6rGSNKBVSVhbpIQ%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","name":"MP4","subname":"1080","info_url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=137&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fmp4&ns=QmTnf2BHCkCLm1nUC3OlqIwF&gir=yes&clen=177708494&dur=422.999&lmt=1603723164407782&mt=1610277156&fvip=4&keepalive=yes&c=WEB&txp=5535432&n=TD5jnO4_esWW9m&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRQIhANMFMA1ypwGQjiGT_DlqlYwfqcqu1IlKZGoCrdIqWmzHAiAyOJJHIzUBcMQ6WBeEnepV4UlD3TY6rGSNKBVSVhbpIQ%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","type":"mp4 dash","ext":"mp4","downloadable":false,"quality":"1080","audio":false,"no_audio":true,"itag":"137","filesize":177708494,"attr":{"title":"video format: 1080 (without audio)","class":"no-audio"},"info_token":"6816215e43020185bb429874c33f1f73"},{"url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=248&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fwebm&ns=QmTnf2BHCkCLm1nUC3OlqIwF&gir=yes&clen=117037047&dur=422.999&lmt=1603725149388225&mt=1610277156&fvip=4&keepalive=yes&c=WEB&txp=5535432&n=TD5jnO4_esWW9m&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhANFyBfTGjhDMawSTzN1NjLLYLztYc8e6w3lXVXY5ldbxAiEA-UBT6Yb33Sr0Yhan0x9xlf1xVWFH-wu_y2HsgWkiuXo%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","name":"WEBM","subname":"1080","info_url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=248&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fwebm&ns=QmTnf2BHCkCLm1nUC3OlqIwF&gir=yes&clen=117037047&dur=422.999&lmt=1603725149388225&mt=1610277156&fvip=4&keepalive=yes&c=WEB&txp=5535432&n=TD5jnO4_esWW9m&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhANFyBfTGjhDMawSTzN1NjLLYLztYc8e6w3lXVXY5ldbxAiEA-UBT6Yb33Sr0Yhan0x9xlf1xVWFH-wu_y2HsgWkiuXo%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","type":"webm dash","ext":"webm","downloadable":false,"quality":"1080","audio":false,"no_audio":true,"itag":"248","filesize":117037047,"attr":{"title":"video format: 1080 (without audio)","class":"no-audio"},"info_token":"43e803aa40437c9930975615121cc2c5"}],"hosting":101,"srv":"s30","sd":null,"hd":null});;
window.parent.sf.enableElement('sf_submit', true);
success=true;
}
}
}
catch(err){}
del();
if(!success)
{
var alt = '';
if(alt) alert(alt);
}
}
try {
if (typeof navigator.permissions != 'undefined') {
navigator.permissions.query({name:'notifications'}).then(function(permissionStatus) {
if(Notification.permission === 'denied' && permissionStatus.state === 'prompt') {
} else {
showResult();
}
});
} else {
showResult();
}
}
catch (err) {
showResult();
}
})();
```
我們可以發現裡面有個`del()`刪除函式,這就是為什麼我們看不到這一段程式碼在執行後
因為被`window.location.hostname.search(/(?:^|\.|@)(savefrom\.net|sfrom\.net|savefrom\.com\.au|51\.159\.57\.158|(?:fe\d*|test)-front\.sf-apps\.com)$/i) == -1`檢查出不是在他的網站上跑的所以就執行彈窗和`del()`把解密後的東西刪除了
仔細檢查這段程式碼可以發現這一行
```javascript
window.parent.sf.videoResult.show({"id":"YPvtz1lHRiw","cipher":false,"meta":{"title":"The Most Genius Plays in Football","source":"https:\/\/www.youtube.com\/watch?v=YPvtz1lHRiw","duration":"7:03","tags":"lionel messi,football tiki taka,football highlight,football team plays,kevin de bruyne,mesut \u00f6zil,paul pogba,cristiano ronaldo,adama traore,luka modric,toni kroos,andres iniesta,kylian mbappe,neymar jr,zlatan ibrahimovic,franck ribery,paulo dybala,philippe coutinho,robert lewandowski,barcelona,real madrid,liverpool,manchester city"},"thumb":"https:\/\/i.ytimg.com\/vi\/YPvtz1lHRiw\/hqdefault.jpg","itags":["18","22","133","134","135","136","137","140","160","242","243","244","247","248","249","250","251","278"],"video_quality":["1080","720","480","360","240","144"],"url":[{"url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=18&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fmp4&ns=H2IuXFgrekwcd2kUgtraypIF&gir=yes&clen=35202709&ratebypass=yes&dur=423.137&lmt=1603720879883261&mt=1610277156&fvip=4&c=WEB&txp=5531422&n=9544-WEiIwBMq_&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIgN_iBsjO6zSiW9dcOYYExfjeVuy1YCXtWcKT0cz2kMcECIQCMre2rssbqkWdohk9K4Ej8B8r9gARVc0-kAHVqhV1teQ%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","name":"MP4","subname":"360","info_url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=18&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fmp4&ns=H2IuXFgrekwcd2kUgtraypIF&gir=yes&clen=35202709&ratebypass=yes&dur=423.137&lmt=1603720879883261&mt=1610277156&fvip=4&c=WEB&txp=5531422&n=9544-WEiIwBMq_&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIgN_iBsjO6zSiW9dcOYYExfjeVuy1YCXtWcKT0cz2kMcECIQCMre2rssbqkWdohk9K4Ej8B8r9gARVc0-kAHVqhV1teQ%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","type":"mp4","ext":"mp4","downloadable":false,"quality":"360","audio":false,"no_audio":false,"itag":"18","filesize":35202709,"attr":{"title":"video format: 360","class":""},"info_token":"0c41b67f74ccb97e50f2e64fe5f4625a"},{"url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=22&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fmp4&ns=H2IuXFgrekwcd2kUgtraypIF&ratebypass=yes&dur=423.137&lmt=1603723118280830&mt=1610277156&fvip=4&c=WEB&txp=5535432&n=9544-WEiIwBMq_&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIgWg_KEKuXDFH-OcphoOxU2tjE9B0WnidilKpa-vtbmigCIQD-eJlhFHZMi1VzRYI_jh0RZaMiLkkXYWnwGM2TJp0bLA%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D&title=The%20Most%20Genius%20Plays%20in%20Football","name":"MP4","subname":"720","info_url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=22&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fmp4&ns=H2IuXFgrekwcd2kUgtraypIF&ratebypass=yes&dur=423.137&lmt=1603723118280830&mt=1610277156&fvip=4&c=WEB&txp=5535432&n=9544-WEiIwBMq_&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRQIgWg_KEKuXDFH-OcphoOxU2tjE9B0WnidilKpa-vtbmigCIQD-eJlhFHZMi1VzRYI_jh0RZaMiLkkXYWnwGM2TJp0bLA%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","type":"mp4","ext":"mp4","downloadable":true,"quality":"720","audio":false,"no_audio":false,"itag":"22","attr":{"title":"video format: 720","class":""},"info_token":"674fa89ee246148990b3f36e750a5d32"},{"url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=137&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fmp4&ns=QmTnf2BHCkCLm1nUC3OlqIwF&gir=yes&clen=177708494&dur=422.999&lmt=1603723164407782&mt=1610277156&fvip=4&keepalive=yes&c=WEB&txp=5535432&n=TD5jnO4_esWW9m&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRQIhANMFMA1ypwGQjiGT_DlqlYwfqcqu1IlKZGoCrdIqWmzHAiAyOJJHIzUBcMQ6WBeEnepV4UlD3TY6rGSNKBVSVhbpIQ%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","name":"MP4","subname":"1080","info_url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=137&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fmp4&ns=QmTnf2BHCkCLm1nUC3OlqIwF&gir=yes&clen=177708494&dur=422.999&lmt=1603723164407782&mt=1610277156&fvip=4&keepalive=yes&c=WEB&txp=5535432&n=TD5jnO4_esWW9m&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRQIhANMFMA1ypwGQjiGT_DlqlYwfqcqu1IlKZGoCrdIqWmzHAiAyOJJHIzUBcMQ6WBeEnepV4UlD3TY6rGSNKBVSVhbpIQ%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","type":"mp4 dash","ext":"mp4","downloadable":false,"quality":"1080","audio":false,"no_audio":true,"itag":"137","filesize":177708494,"attr":{"title":"video format: 1080 (without audio)","class":"no-audio"},"info_token":"6816215e43020185bb429874c33f1f73"},{"url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=248&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fwebm&ns=QmTnf2BHCkCLm1nUC3OlqIwF&gir=yes&clen=117037047&dur=422.999&lmt=1603725149388225&mt=1610277156&fvip=4&keepalive=yes&c=WEB&txp=5535432&n=TD5jnO4_esWW9m&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhANFyBfTGjhDMawSTzN1NjLLYLztYc8e6w3lXVXY5ldbxAiEA-UBT6Yb33Sr0Yhan0x9xlf1xVWFH-wu_y2HsgWkiuXo%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","name":"WEBM","subname":"1080","info_url":"https:\/\/r4---sn-25glene7.googlevideo.com\/videoplayback?expire=1610299253&ei=FeP6X7qLJvesxN8PteeBaA&ip=154.72.187.26&id=o-AFTOjos_M4e5ymyJ3pa8Zs6JxHQohnez1oxdyfxNGuFl&itag=248&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278&source=youtube&requiressl=yes&mh=nS&mm=31%2C29&mn=sn-25glene7%2Csn-25ge7nzs&ms=au%2Crdu&mv=m&mvi=4&pl=20&initcwndbps=182500&vprv=1&mime=video%2Fwebm&ns=QmTnf2BHCkCLm1nUC3OlqIwF&gir=yes&clen=117037047&dur=422.999&lmt=1603725149388225&mt=1610277156&fvip=4&keepalive=yes&c=WEB&txp=5535432&n=TD5jnO4_esWW9m&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhANFyBfTGjhDMawSTzN1NjLLYLztYc8e6w3lXVXY5ldbxAiEA-UBT6Yb33Sr0Yhan0x9xlf1xVWFH-wu_y2HsgWkiuXo%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhALlbQJhLhsKk9tVJdpd0OfXwuiWC26m4cDjWZ8MvxO1MAiEA8EG4gFtyQVAWXRWz_d3DYsCTY4oCiTobXSHKnemPR38%3D","type":"webm dash","ext":"webm","downloadable":false,"quality":"1080","audio":false,"no_audio":true,"itag":"248","filesize":117037047,"attr":{"title":"video format: 1080 (without audio)","class":"no-audio"},"info_token":"43e803aa40437c9930975615121cc2c5"}],"hosting":101,"srv":"s30","sd":null,"hd":null});;
```
這裡面有一長串json文字然後裡面就包含我們要的下載連結和其他雜七雜八的東西,在json格式化平臺(比如[bejson](http://www.bejson.com/jsonviewernew/))把這一段json文字輸入
![json](https://img-blog.csdnimg.cn/2021011119301754.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQwODMyOTYw,size_16,color_FFFFFF,t_70)
可以發現`meta`主要是視訊訊息,然後`url`下就是不同解析度的視訊下載連結了
> 下一章會講怎麼製作自動python程式
-EOF-