Saludos comunidad, en esta ocasión les presento un método que he estado desarrollando para

poder obtener el enlace de los videos de youtube reales y de cualquier url de sitio de video.

Este método se basa del uso de servicios web de descarga de videos usados inteligentemente para

simular que estamos por el navegador desde la consola. Nos valdremos de la utilidad curl disponible en

todos los repositorios de las distribuciones actuales.

Primero instalamos curl como root:

apt install curl

Salimos de root con exit y luego como usuario normal:

curl -X POST -g –data «url=https://www.youtube.com/watch?v=6xYtURnQfjU» -k https://www.savido.net/download>/tmp/pag.html

% Total % Received % Xferd Average Speed Time Time Time Current

Dload Upload Total Spent Left Speed

100 122k 0 122k 100 47 9630 3 0:00:15 0:00:13 0:00:02 21594

en data se pone la url del video de youtube de interés.

Luego si nos interesa la versión calidad media del video podemos usar:

cat /tmp/pag.html |grep medium

Veremos algo como:

«640×360 (medium)

<a href=»https://r2—sn-5uaeznr6.googlevideo.com/videoplayback?expire=1561213752&ei=2OYNXfquA5Kx4QSw7oeABA&ip=104.128.235.186&id=o-ANfyEqfZu5V8E0ZUHKutC-fT_7IsMCTuOTbyW73YnB2B&itag=43&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5uaeznr6%2Csn-5ualdn76&ms=au%2Crdu&mv=u&pl=27&mime=video%2Fwebm&gir=yes&clen=23334538&ratebypass=yes&dur=0.000&lmt=1398233511210347&mt=1561191141&fvip=2&c=WEB&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=ALgxI2wwRQIhAPn-ibKyDOLveD-XTZeEpfcnFhoWGw7_P_fd3oZDtzljAiA27m2-3SIrS4bmDaJOezGUdXBRCaGJ-QJNTshAySh_YQ%3D%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cpl&lsig=AHylml4wRQIhALssyyY6a13sx60p5NYluImVu3E5ickJjRHF0mIav0ItAiAAgdbUObWn4XQuHTO5MsOR7p6X6iby0_y8dbb9x2wffA%3D%3D&title=Ubuntu+14.04+Aplicaciones+B%26%23225%3bsicas» download=»Ubuntu+14.04+Aplicaciones+B%26%23225%3bsicas_640x360+(medium)» rel=»nofollow» target=»_blank»>

640×360 (medium)

<a href=»https://r2—sn-5uaeznr6.googlevideo.com/videoplayback?expire=1561213752&ei=2OYNXfquA5Kx4QSw7oeABA&ip=104.128.235.186&id=o-ANfyEqfZu5V8E0ZUHKutC-fT_7IsMCTuOTbyW73YnB2B&itag=18&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5uaeznr6%2Csn-5ualdn76&ms=au%2Crdu&mv=u&pl=27&mime=video%2Fmp4&gir=yes&clen=27210482&ratebypass=yes&dur=852.288&lmt=1400121805597570&mt=1561191141&fvip=2&c=WEB&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=ALgxI2wwRQIgcJI9oQzfJTKaIYMcDUz6w2sBiligCxazd-XG80OHp5cCIQDERwxV4sEteznLNS20uL1i51iAXi9ZIiswvC8okctwzw%3D%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cpl&lsig=AHylml4wRQIhALssyyY6a13sx60p5NYluImVu3E5ickJjRHF0mIav0ItAiAAgdbUObWn4XQuHTO5MsOR7p6X6iby0_y8dbb9x2wffA%3D%3D&title=Ubuntu+14.04+Aplicaciones+B%26%23225%3bsicas» download=»Ubuntu+14.04+Aplicaciones+B%26%23225%3bsicas_640x360+(medium)» rel=»nofollow» target=»_blank»>»

Tomamos el enlace de la etiqueta html href hasta donde termina la comilla » que deseamos, eliminamos reemplazamos los & por & y se la pasamos a curl nuevamente puesto que esta es un sitio web que nos dará la url final:

echo ‘https://r2—sn-5uaeznr6.googlevideo.com/videoplayback?expire=1561213752&ei=2OYNXfquA5Kx4QSw7oeABA&ip=104.128.235.186&id=o-ANfyEqfZu5V8E0ZUHKutC-fT_7IsMCTuOTbyW73YnB2B&itag=43&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5uaeznr6%2Csn-5ualdn76&ms=au%2Crdu&mv=u&pl=27&mime=video%2Fwebm&gir=yes&clen=23334538&ratebypass=yes&dur=0.000&lmt=1398233511210347&mt=1561191141&fvip=2&c=WEB&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=ALgxI2wwRQIhAPn-ibKyDOLveD-XTZeEpfcnFhoWGw7_P_fd3oZDtzljAiA27m2-3SIrS4bmDaJOezGUdXBRCaGJ-QJNTshAySh_YQ%3D%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cpl&lsig=AHylml4wRQIhALssyyY6a13sx60p5NYluImVu3E5ickJjRHF0mIav0ItAiAAgdbUObWn4XQuHTO5MsOR7p6X6iby0_y8dbb9x2wffA%3D%3D&title=Ubuntu+14.04+Aplicaciones+B%26%23225%3bsicas’>/tmp/url

Reemplazar los amps por un & simple:

sed -i ‘s/amp;/ /g’ «/tmp/url»

cat /tmp/url |tr » » «\0»>/tmp/url2

Le pasamos la url modificada de url2 a curl:

cat /tmp/url2

Y finalmente obtenemos la URL:

curl -X GET -v ‘https://r2—sn-5uaeznr6.googlevideo.com/videoplayback?expire=1561213752&ei=2OYNXfquA5Kx4QSw7oeABA&ip=104.128.235.186&id=o-ANfyEqfZu5V8E0ZUHKutC-fT_7IsMCTuOTbyW73YnB2B&itag=43&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-5uaeznr6%2Csn-5ualdn76&ms=au%2Crdu&mv=u&pl=27&mime=video%2Fwebm&gir=yes&clen=23334538&ratebypass=yes&dur=0.000&lmt=1398233511210347&mt=1561191141&fvip=2&c=WEB&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=ALgxI2wwRQIhAPn-ibKyDOLveD-XTZeEpfcnFhoWGw7_P_fd3oZDtzljAiA27m2-3SIrS4bmDaJOezGUdXBRCaGJ-QJNTshAySh_YQ%3D%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cpl&lsig=AHylml4wRQIhALssyyY6a13sx60p5NYluImVu3E5ickJjRHF0mIav0ItAiAAgdbUObWn4XQuHTO5MsOR7p6X6iby0_y8dbb9x2wffA%3D%3D&title=Ubuntu+14.04+Aplicaciones+B%26%23225%3bsicas’ 2>&1|grep «Location: http»|cut -d»:» -f2-3

(Si falla volver a correr el comando)

Devuelto:

https://r2—sn-q4flrney.googlevideo.com/videoplayback?expire=1561213752&ei=2OYNXfquA5Kx4QSw7oeABA&ip=104.128.235.186&id=o-ANfyEqfZu5V8E0ZUHKutC-fT_7IsMCTuOTbyW73YnB2B&itag=43&source=youtube&requiressl=yes&mime=video%2Fwebm&gir=yes&clen=23334538&ratebypass=yes&dur=0.000&lmt=1398233511210347&fvip=2&c=WEB&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=ALgxI2wwRQIhAPn-ibKyDOLveD-XTZeEpfcnFhoWGw7_P_fd3oZDtzljAiA27m2-3SIrS4bmDaJOezGUdXBRCaGJ-QJNTshAySh_YQ%3D%3D&title=Ubuntu&redirect_counter=1&cm2rm=sn-5uarz7l&req_id=a51c75eac47ea3ee&cms_redirect=yes&mip=152.207.174.212&mm=34&mn=sn-q4flrney&ms=ltu&mt=1561192787&mv=m&pl=17&lsparams=mip,mm,mn,ms,mv,pl&lsig=AHylml4wRAIgFMxSBjlECRWrJsxeQSts3NXMk_h8yMuYsr2ZXjAEbkACIASb_8sbG5tNbdhO5NnQDbE37MqgY8t-M4LQkBQ19R42

Luego podemos descargar el video:

wget -c ‘https://r2—sn-q4flrney.googlevideo.com/videoplayback?expire=1561213752&ei=2OYNXfquA5Kx4QSw7oeABA&ip=104.128.235.186&id=o-ANfyEqfZu5V8E0ZUHKutC-fT_7IsMCTuOTbyW73YnB2B&itag=43&source=youtube&requiressl=yes&mime=video%2Fwebm&gir=yes&clen=23334538&ratebypass=yes&dur=0.000&lmt=1398233511210347&fvip=2&c=WEB&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=ALgxI2wwRQIhAPn-ibKyDOLveD-XTZeEpfcnFhoWGw7_P_fd3oZDtzljAiA27m2-3SIrS4bmDaJOezGUdXBRCaGJ-QJNTshAySh_YQ%3D%3D&title=Ubuntu&redirect_counter=1&cm2rm=sn-5uarz7l&req_id=a51c75eac47ea3ee&cms_redirect=yes&mip=152.207.174.212&mm=34&mn=sn-q4flrney&ms=ltu&mt=1561192787&mv=m&pl=17&lsparams=mip,mm,mn,ms,mv,pl&lsig=AHylml4wRAIgFMxSBjlECRWrJsxeQSts3NXMk_h8yMuYsr2ZXjAEbkACIASb_8sbG5tNbdhO5NnQDbE37MqgY8t-M4LQkBQ19R42’ -O /tmp/video.mp4

–2019-06-22 04:42:57– (intento: 3) https://r2—sn-q4flrney.googlevideo.com/videoplayback?expire=1561213752&ei=2OYNXfquA5Kx4QSw7oeABA&ip=104.128.235.186&id=o-ANfyEqfZu5V8E0ZUHKutC-fT_7IsMCTuOTbyW73YnB2B&itag=43&source=youtube&requiressl=yes&mime=video%2Fwebm&gir=yes&clen=23334538&ratebypass=yes&dur=0.000&lmt=1398233511210347&fvip=2&c=WEB&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=ALgxI2wwRQIhAPn-ibKyDOLveD-XTZeEpfcnFhoWGw7_P_fd3oZDtzljAiA27m2-3SIrS4bmDaJOezGUdXBRCaGJ-QJNTshAySh_YQ%3D%3D&title=Ubuntu&redirect_counter=1&cm2rm=sn-5uarz7l&req_id=a51c75eac47ea3ee&cms_redirect=yes&mip=152.207.174.212&mm=34&mn=sn-q4flrney&ms=ltu&mt=1561192787&mv=m&pl=17&lsparams=mip,mm,mn,ms,mv,pl&lsig=AHylml4wRAIgFMxSBjlECRWrJsxeQSts3NXMk_h8yMuYsr2ZXjAEbkACIASb_8sbG5tNbdhO5NnQDbE37MqgY8t-M4LQkBQ19R42

Conectando con r2—sn-q4flrney.googlevideo.com (r2—sn-q4flrney.googlevideo.com)[172.217.131.39]:443… conectado.

Petición HTTP enviada, esperando respuesta… 200 OK

Longitud: 23334538 (22M)

Grabando a: “/tmp/video.mp4”

/tmp/video.mp4 0%[ ] 24,00K 22,1KB/s

¿Te resultó interesante? Compártelo ... Google+ facebook twitter pinterest linkedin delicious reddit tumblr Whatsapp Imprimir