Updated
ตอนนี้สคริปต์ One Manga Downloader เวอร์ชันล่าสุด อยู่บน GitHub ครับ
The latest version of One Manga Downloader is now hosted on GitHub.
ไม่ค่อยได้อัพบล็อก อัพมันที 2 อันในวันเดียวเลยละกัน xD
อัพเดตสคริปต์จากของเดิมเล็กน้อยครับ พอดีมี request ว่าให้มันโหลด chapter ล่าสุดมาเลยได้มั้ย ขี้เกียจใส่เลข chapter เลยแก้สคริปต์เพิ่มอีกหน่อย แล้วก็แก้ให้ wget กะ Rar.exe มันทำงานแบบเงียบๆ ได้ออกมาหน้าตาแบบนี้
#!/bin/bash base_url="http://www.onemanga.com" manga_name=$1 chapter=$2 last_chapter=$3 if [[ "${chapter}" == "" ]]; then echo "getting latest chapter number..." latest_chapter=`curl -s ${base_url}/${manga_name}/ | grep -i "ch-subject" | grep -v -i "chapter name" | head -1 | awk -F\/ '{print $3}'` printf "the latest chapter of ${manga_name} is ${latest_chapter}. download it? ([y]/n): " read answer if [[ "${answer}" == "y" || "${answer}" == "" ]]; then chapter=$latest_chapter else exit fi fi if [[ "${last_chapter}" == "" ]]; then last_chapter=${chapter} fi while [[ ${chapter} -le ${last_chapter} ]] do next_page_chapter=$chapter page_location=`curl -s ${base_url}/${manga_name}/${chapter}/ | grep -i "begin reading" | awk -F\" '{print $2}'` while [[ $next_page_chapter -eq $chapter ]] do curl -s ${base_url}${page_location} > tmp_page image_location=`grep "class=\"manga-page\"" < tmp_page | awk -F\" '{print $4}'` if [[ "$image_location" != "" ]]; then echo "downloading ${image_location}..." wget -q $image_location fi page_location=`grep "value=\"next page\"" < tmp_page | awk -F\' '{print $2}'` next_page_chapter=`echo ${page_location} | cut -d\/ -f3` done echo "creating CBR file..." /cygdrive/c/Program\ Files/WinRAR/Rar.exe a -inul ${manga_name}_${chapter}.cbr *.jpg echo "cleaning up..." rm *.jpg chapter=$((chapter+1)) done rm tmp_page
วิธีใช้งาน ตอนนี้มี 3 แบบ
onemanga.sh <manga_name> <first_chapter> <last_chapter>โหลดทีละหลายๆ ตอนตามที่กำหนดonemanga.sh <manga_name> <chapter>โหลดแค่ตอนเดียวonemanga.sh <manga_name>โหลดตอนล่าสุด
ปล. ตอนแรกว่าจะใช้เป็นหัวข้อหัดเขียน Python แต่ใช้แบบนี้ไปก่อนละกัน ง่ายดี :P

3 comments
รบกวนช่วยนิดนึงครับผม Run แล้ว Error ดังนี้
$ ./onemanga.sh One_Piece ./onemanga.sh: line 2: $'\r': command not found ./onemanga.sh: line 7: $'\r': command not found ./onemanga.sh: line 25: syntax error in conditional expression ./onemanga.sh: line 25: syntax error near ']] ./onemanga.sh: line 25: 'while [[ $(chapter) -le $(last_chapter) ]] ขอบคุณมากครับ
น่าจะเกิดปัญหาตอน copy/paste นะครับ ลองใช้คำสั่งนี้ดูครับ
$ cat -v onemanga.sh
ถ้าผลลัพธ์ที่ได้ มีตัว ^M ที่ท้ายบรรทัดของทุกบรรทัด แสดงว่าไฟล์ onemanga.sh เป็น DOS format (ปิดบรรทัดด้วย \r\n) ไม่ใช่ Unix format (ปิดบรรทัดด้วย \n) ซึ่งจะทำให้รันไม่ได้
วิธีแก้คือ ใช้คำสั่งแบบนี้
$ tr -d '\r' < onemanga.sh > onemanga2.sh
แล้วลองรันไฟล์ onemanga2.sh ดูครับ
รันผ่านแล้วครับ ขอบคุณมากครับ