One Manga Downloader (Shell Script)

Posted by kong

อยากอ่านการ์ตูนย้อนหลังใน One Manga แต่ขี้เกียจคลิกทีละหน้า เลยเขียน shell scipt บน Cygwin ให้โหลดมาทีละ chapter แล้วเซฟเป็นไฟล์ .cbr จะได้เลือกอ่านได้ง่ายๆ

สคริปต์ที่ใช้ก็ประมาณนี้

#!/bin/bash
 
base_url="http://www.onemanga.com"
manga_name=$1
chapter=$2
last_chapter=$3
 
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
            wget $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
 
    /cygdrive/c/Program\ Files/WinRAR/Rar.exe a ${manga_name}_${chapter}.cbr *.jpg
    rm *.jpg
 
    chapter=$((chapter+1))
done
 
rm tmp_page

สร้าง directory ใหม่ซักอันนึง แล้วเซฟ shell script ข้างบนเป็นไฟล์ชื่ออะไรก็ได้ เช่น onemanga.sh แล้วสั่ง chmod +x onemanga.sh เพื่อให้สามารถ execute ได้

วิธีใช้ก็เรียกสคริปต์ ตามด้วยชื่อเรื่อง (หาจาก URL ใน One Manga), chapter เริ่มต้น และ chapter สุดท้าย เช่น

./onemanga.sh Hajime_no_Ippo 800 824

หรือถ้าต้องการแค่ chapter เดียว ก็ไม่ต้องใส่ chapter สุดท้าย

./onemanga.sh One_Piece 516

ปล. ถ้ารันบน Cygwin ต้องลง cURL กับ wget ด้วย (เลือกจากใน setup.exe) ถ้ารันบนลินุกซ์ หรือไม่ได้ใช้ WinRAR ก็ต้องแก้บรรทัดที่เรียก Rar.exe เป็นอย่างอื่นแทน :P

Comments

karn's picture

แสรด.. ทำไมไม่เอาข้อความใน

แสรด.. ทำไมไม่เอาข้อความใน "ปล." ไปบอกตั้งแต่แรก

Posted by karn (not verified) | Oct 3rd, 2008 at 10:28 am | Reply
oholit's picture

ความพยายาม ในทางที่แตกต่าง

โห...เก่งหว่ะพี่
ผมก็อ่านการ์ตูนย้อนหลังนะครับ ขี้เกียจ load เหมือนกันด้วย
แต่วิธีผมมันใช้สมองน้อยกว่านั้นเยอะเลยอ่ะ
เช่น
ผมอยากอ่าน Dragonball แต่ขี้เกียจ load ทีละหน้า
ก็ google โดยใช้ keywork ว่า "download dragonball"
เพียงแค่นี้ ก็จะเจอ web ที่เค้าให้ load ทั้ง set ได้แล้วอ่ะครับ

แต่นับถือว่าพี่เก่งจริงๆ ครับ

Posted by oholit (not verified) | Oct 4th, 2008 at 12:24 pm | Reply
Anonymous's picture

Works but I had to modify the

Works but I had to modify the sript for personal reasons now the scrip includes
mkdir ${chapter}
cp *.jpg ${chapter}
rm *.jpg
at the end.

Posted by Anonymous (not verified) | Oct 15th, 2008 at 9:45 am | Reply

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options