Download Youtube Video dengan Shell Script V2

  1. Beranda
  2. Free/Open Source
  3. Download Youtube Video dengan Shell Script V2

Aplikasi yang dibuat mas Trio ini (You2Pup) ini adalah aplikasi di Puppy Linux untuk mendownload video dari Youtube. Beberapa hari lalu baru diupdate dengan menggunakan shell script yt-download.sh, padahal script itu lumayan cupu. Jadi ini yang ngebuat saya jadi iseng ngoprek-ngoprek lagi.

Sama seperti aplikasi pendownload youtube yang lain, script yt-download yang lama masih bisa dijalankan mulus. Tapi, bedanya, dia hanya mendownload salah satu video saja (defaultnya), sementara di Youtube, satu video ada berbagai macam ukuran dan format. Ide dari mas Trio, di script yang baru, saya coba tambahkan beberapa fitur.

Shell ini masih sederhana seperti yang lama, hanya jauh lebih banyak barisnya. Ga jauh beda, cuma memanfaatkan fungsi-fungsi regular expression dan string manipulation untuk mendapatkan url video, format, dan ukuran. Variable tersebut ada di source html youtube dengan key “PLAYER_CONFIG” yang berupa array JSON. Dengan mendapatkan nilai “fmt_url_map” dan “fmt_map” sudah cukup menghasilkan url video, format, dan ukurannya. Kalo shell bisa ngebaca JSON, mungkin akan lebih mudah untuk parsingnya.

Script yt-download.sh bisa didownload di sini.

Change log

v2.35 – 2013-04-21

  • Fixed: Change from playerConfig to ytplayer.config.

v2.34 – 2013-01-24

  • Fixed: As always, reported by Abdulla, doraq. Some changes in ${UrlMap} loop.

v2.33 – 2012-11-08

  • Fixed: Youtube’s format changed, reported by ambassador. Reformat “signature”, line 78-83.

v2.32 – 2012-01-31

  • Fixed: Youtube’s format changed, reported by Abdulla. PLAYER_CONFIG to playerConfig, line 54-55.
  • Changed: Added tmp file with timestamp, and deleted as soon as it is processed, to prevent write problems.

v2.3 – 2011-08-29

  • Fixed: Youtube’s format changed. url_encoded_fmt_stream_map & fmt_list.
  • Fixed: Youtube’s url changed. Url decoded, remove some parameters, added ‘title’ parameter.

v2.2

  • Fixed: Youtube’s url changed. Remove o-o.preferred.matrix-cgk1
  • Fixed: Youtube’s url changed. \u0026 replaced with &.
  • Fixed: array sorting problem.

v2.1

  • Added: input for save directory, and some error handling if directory’s not found. (Thanks to Trio).
  • Added: abort option. (Thanks to Trio).
  • Added: wget parameter. (Thanks to Trio).
  • Added: new video format webm. Format list: flv, mp4, 3gp, and webm.
  • Changed: parsing algorithm based on Dougal’s Shell script. (Thanks to Dougal). But problem with array sorting.

v2.0

  • Added: automatic file naming based on page title.
  • Added: some error handling.
  • Added: allow user to choose available size and format. Format list: flv, mp4, and 3gp.
  • Changed: parsed portion. JSON array from youtube HTML source provides various video format. (Thanks to Trio).
  • Reported: problem with title and “/” character. Tested with Debian/Ubuntu & Puppy, no problem.

Mungkin Kamu juga suka

Rehat sejenak…
Codeigniter Helper untuk Modular Extensions-HMVC

37 Komentar. Leave new

  • Halo mas….

    Dioprek lg donk biar jalan lg hehehe

    Balas
  • Halo mas,

    Sdh lama tdk halo halo
    Msh mau oprek utk update lagi?
    Kalo ada waktu

    Trims ya

    Balas
  • Bro Arief,

    Saya sedikit oprek. force wget menggunakan ipv4. nah skrg berfungsi lagi

    Balas
  • Bro Arif,

    Long time no see, hehehe

    Btw, lagi iseng oprek lagi. Coba jalanin script ini, ternyata jalan semua, hanya pas donlot dapet error 403 forbidden. Sepertinya youtube berubah lagi

    Balas
    • Sori Bro,
      Lambat replynya maklum lg sibuk kerjaan.
      Ane emang jarang liat script ini lagi. Coba nanti ane rapiin lagi deh ya. ๐Ÿ˜€

  • if [ $4 ]
    then
    if [ ! -d “$4” ]
    then
    echo “Can not find directory. Please check [save_directory]”
    sleep 1
    exit 0
    fi
    DIR=$4″/”
    else
    DIR=””
    fi

    ….

    wget -O – -t 7 -w 5 –waitretry=14 –random-wait ‘–user-agent=Mozilla/5.0’ -e robots=off “${Url_array[$infmt]}” –limit-rate=$2 -$3 > “$DIR””$fn”

    ….

    echo “Usage: bash/sh yt-download.sh [youtube_video_id] [speed] [background] [save_directory] ”
    echo “Example: sh yt-download.sh jNQXAC9IVRw 100k b”

    Balas
  • Work perfect.
    Thanks pak.

    Balas
  • the script need to be update again with youtube new rules

    Balas
  • the script cant download mp4 anymore it is returen forbidden message also flv some times working some times not

    Balas
    • merge 2.33 script with following part, youtube format changed, again.

      for i in ${UrlMap} ; do
      Fmt=${i#*itag=}
      Fmt=${Fmt%%\\u0026*}

      Sig=${i#*sig=}
      Sig=${Sig%%\\u0026*}

      Url=${i#*url=}
      Url=”$(echo $Url | echo -e $(sed ‘s/itag=/xtag=/g;’))” # double itag=
      Url=”$(echo $Url | echo -e $(sed ‘s/+//g; s/%/\\x/g’))”
      Url=${Url//\\\///}
      Url=${Url//\\\u0026/&}
      Url=${Url%%&sig=*}
      Url=”$(echo $Url | echo -e $(sed ‘s/;codecs=\”.*\”//g’))”
      Url=${Url// /}
      Url=${Url//\%252C/,}
      #Url=”$(echo $Url | sed -e s/\\http:[^\]]*\\.v/http:\\/\\/v/)”

      Url=$Url”&signature=”$Sig”&title=”$titlefn

      Url_array[$j]=$Url
      Fmt_array[$j]=$Fmt
      let j++
      done

    • I tried to replace it but i get error message could you upload it on some url or inform arif to update the new changes, thank you

    • @doraq, @abdulla : Fixed v2.34 –for now… Sorry for the late reply, been busy lately.
      Thanks for the report. ๐Ÿ˜€

  • dont work with all vid id

    ./y jNQXAC9IVRw

    YT-DOWNLOAD.SH v2.32
    ———————————-
    Downloading HTML file and getting video formats, please wait…

    Download site(s) found!
    ———————————-
    Title: Me at the zoo
    ———————————-
    [0] 176×144 flv
    [1] 320×240 flv
    [2] 320×240 flv
    [3] 320×240 flv
    [4] 320×240 flv
    Select video format and press enter or just press enter to abort: 2
    Downloading video…
    ———————————-
    –2012-11-03 16:51:10– http://v2.cache8.c.youtube.com&sig=834565bc4402092f5ff13cee831d69073c53dbc6.3ca143340fbc1160357d209edcb038e30ddd2765&title=me%20at%20the%20zoo/
    Auflรถsen des Hostnamen v2.cache8.c.youtube.com&sig=834565bc4402092f5ff13cee831d69073c53dbc6.3ca143340fbc1160357d209edcb038e30ddd2765&title=me at the zoo… fehlgeschlagen: Der Name oder der Dienst ist nicht bekannt.
    wget: kann die Host-Adresse ยปv2.cache8.c.youtube.com&sig=834565bc4402092f5ff13cee831d69073c53dbc6.3ca143340fbc1160357d209edcb038e30ddd2765&title=me at the zooยซ nicht auflรถsen
    ———————————-

    Balas
  • youtube changed the format & url again, need fix

    Balas
    • I just tested it, works fine.
      Please submit your video id, if still having problems.

      arif@ubuntu:~$ bash yt-download.sh jNQXAC9IVRw

      YT-DOWNLOAD.SH v2.32
      ———————————-
      Downloading HTML file and getting video formats, please wait…

      Download site(s) found!
      ———————————-
      Title: Me at the zoo
      ———————————-
      [0] 320×240 flv
      [1] 320×240 mp4
      [2] 320×240 flv
      [3] 320×240 webm
      Select video format and press enter or just press enter to abort: 0
      Downloading video…
      ———————————-
      –2012-05-16 21:23:56– http://v22.lscache6.c.youtube.com/videoplayback?upn=pBkdfDmjAmM&

      Saving to: `STDOUT’

      100%[===================================================================================================================>] 711,654 81.4K/s in 8.8s

      2012-05-16 21:24:06 (79.3 KB/s) – written to stdout [711654/711654]

      ———————————-

  • Hi Arif the bash file no more working with youtube since 14 Jan i think it is need to be updated with the new changes in youtube

    Balas
    • Hi Abdulla, thanks for reporting the problem. I’ll fix this ASAP.
      [update] A litle fix line 54-55. I did a quick test with Ubuntu, should be ok now.

  • Getting error :
    yt-download.sh: line 105: {: syntax error: operand expected (error token is “{“)

    Code:

    99 echo “———————————-”
    100 # List all the elements in the array.
    101 arr_count=${#Geom_array[@]}
    102 i=0
    103 while [ “$i” -lt “$arr_count” ]
    104 do
    105 echo [$i] ${Geom_array[$i]} ${fmt[${Fmt_array[$i]}]} ${Fmt_array[$i]}
    106 let i++
    107 done

    Please check it

    Balas
  • Wah mas thx buat scriptnya ๐Ÿ™‚ Dari dulu pengguna keepvid nih, soalnya bisa dpt mp4 ๐Ÿ˜€ Sekarang berkat scriptnya sampean, jadi bisa download format mp4 lagi dr youtube ๐Ÿ™‚ Nih juga lagi dibaca2x scriptnya, pusing di regex ๐Ÿ˜›

    Makasih buat upload scriptnya ya mas, ane pingin coba porting trs dibuat online supaya bisa dipake juga buat yg ga pake Linux ๐Ÿ˜€

    Balas
  • Mas Arif,

    Ada laporan, youtube ganti lagi ….. Weleh weleh

    Balas
    • Iya mas. di urlnya di tambahin o-o.preferred.matrix-cg1… cape deh.
      Ntar difix deh.

      Update: dah difix mas. Line 70. Dah ditest, sementara gitu dulu. Coba ditest tempat mas.
      gw jg ga tau ngapain juga dia tambahin ‘o-o.preferred.matrix-cg1’

  • Yup maz,

    you2pup updated, thanks

    Balas
  • Iya tuh mas… Coba gw liat2 dulu yah. Kayaknya perubahannya sedikit doang nih….
    Update: sudah di fix & ditest dipuppy juga. Tinggal nambahin Url=${Url//\\\u0026/&}
    https://danuparta.com/demo/yt-download/yt-download.sh.txt

    Balas
  • Mas,

    Kayaknya youtube ganti url download lagi … coba deh … it stopped working

    Balas
  • Hello Dougal, sorry takes weeks to reply your comments hahaha…, thats because I’m quite busy lately. I have seen your shell codes here murga-linux.com, it’s amazing far more efficient, simple than mine. I did not see it can be parsed like that. Ok, I’m quite a noob in linux and shell scripting, there’s so much to learn. So I’m going to use yours, if you don’t mind. Thanks. ๐Ÿ˜€

    Mas trio: gw udah cobain petnya di puppy. Testing saya biasa di debian/ubuntu, selalu berhasil, blm ketemu error. Apa beda di puppy? Nanti gw coba ubah scriptnya. :D. Yang pasti “rm wget-log*” dan “curl -s” bikin eror di ubuntu (default install).

    Balas
  • sementara ini sy modified hanya:

    1. DL html pake curl -s, jadi silent (agar user ndak bingung, dikira sdh start DL)
    2. Ada pilihan utk lokasi folder Dl
    3. Auto-naming DL file yg anda ndak berhasil (selalu file namenya 0 (mis: 0.360×780.flv), jadi sy gunakan grep utk dapat judulnya sbg nama file

    Trims

    Balas
  • …and your title finding code is broken (the blog swallowed it?):
    grep -o “” $1.tmp

    Balas
  • fmt 34/35 should probably get an extension of f4v:
    http://en.wikipedia.org/wiki/Flash_Video
    hat makes it easier to know if it’s h264 or the old (crap) Sorenson flash.

    Balas
  • Dan seharusnya bs diefisienkan. Regex dan arraynya jg agak2 gmn gitu. Regex expr blm bs kalo yg non-greedy. ๐Ÿ˜›

    Balas
  • Wah cepet jg ๐Ÿ˜€ sep-sep…
    Coba2in ya mas, terutama di format listnya tuh.

    Balas
  • Modified and now used — Thanks!!!

    Balas

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Fill out this field
Fill out this field
Mohon masukan alamat email yang sah.
You need to agree with the terms to proceed

Latest

Tak ditemukan hasil apapun.