神代綺凛

[Shell] nhentai一键批量下载
一个能一键分析批量下载nhentai本子的纯Shell脚本,下完还能自动打包成zip。
扫描右侧二维码阅读全文
28
2017/09

[Shell] nhentai一键批量下载

一个能一键分析批量下载nhentai本子的纯Shell脚本,下完还能自动打包成zip。
主要是给VPS用的,批量快速下完打包然后拉回来一气呵成(。

Head Pic: 「アストルフォきゅん」/「イチリ」

nhentai-one-key-downloader

但由于 shell 脚本仍存在很多问题,不建议使用,有兴趣可以看这个

演示视频

视频约1.7MB
演示内容顺序:

  1. 模式A 白名单
  2. 模式B + 断点续传
  3. 模式A 黑名单 + 查重

准备工作

首先你需要有Linux。。。VPS也可虚拟机也可。
然后用以下命令下载这个脚本:

wget -N --no-check-certificate  https://raw.githubusercontent.com/Tsuk1ko/nhentai-one-key-downloader/master/nhentai-batch.sh && chmod +x nhentai-batch.sh

然后用编辑器打开它,自己根据需要修改脚本开头的设置:

#setting  off:0  on:1
zad=1            #下载完一个本子后自动压缩成zip
dsaz=1          #压缩完之后删除源文件

dldir="comics"  #你想要把本子下载在哪个目录,相对/绝对路径均可

开始使用

这个脚本有两种下载模式。

模式A

从一个nhentai搜索页面,地址类似于https://nhentai.net/search/?q=xxxxxx,或者其他的什么Tags/Artists/...页面下载本子,反正就是像下面这样的有很多本子结果的页面。

哇!好多本子!

那就执行

./nhentai-batch.sh -a

然后就输入这个网址接着回车就可以了,然后脚本会自动分析页面内的所有本子并且罗列出来并标上序号。如果你输入的网址有误会提示你。
然后会提示你有3种模式来下载本子:

  1. 白名单模式:下载你指定的本子
  2. 黑名单模式:除了你指定的本子之外,都下载
  3. 想个屁模式:我全下了!(列表中有重复的本子也不要紧,由于“查重”功能,只会下载一个)

如果你选择了模式1或者模式2,你需要输入你指定的本子的序号并以空格隔开,最后回车。

模式B

从一个本子详情页,类似https://nhentai.net/g/xxxxxx/网址的页面下载本子,也就是下图所示的这种页面。

哇!本子!

那就执行

./nhentai-batch.sh -b

然后就会提示要你输入网址,按回车换行。你可以批量下载,即输入一个网址-换行-再输入一个网址-换行-……。当你输入一个空行的时候(即连续两次换行)即可结束输入,然后脚本会自动将所有你输入的网址里的本子下载下来。

其他功能

这个脚本带有查重功能和断点续传功能。
也就是说,如果你一个本子下到一半没下完就ctrl+c终止了脚本,那么你下次再下载同样的本子的时候会自动从上次断掉的地方开始下载(会自动检测并删除wget没有下载完全的文件并重新下载)。
已经下好了的图片会直接略过;如果文件夹内有和本子名称同名的压缩包(.zip),则也会判定为这个本子已经下过并跳过。

补充说明

如果在脚本完全运行完之前就ctrl+c结束了脚本,那么

  • 在总下载目录里会遗留形如.nhentai-temp-xxxxx的文件夹,删除即可
  • 在没下完的本子目录里会遗留.dl文件,这是用于记录本子下载进度的。如果你删除了,那么下次下载同一个本子的时候就无法识别 wget 是否完整下载了当时强制结束脚本时的那个图片。

TODO

开发网页程序(进行中)

搬瓦工VPS优惠套餐,建站稳如狗,支持支付宝,循环出账94折优惠码BWH3HYATVBJW
年付$47CN2线路,1核/1G内存/20G硬盘/1T@1Gbps【点击购买
季付$47CN2 GIA线路,1核/1G内存/20G硬盘/1T@2.5Gbps【点击购买
Last modification:April 24th, 2019 at 10:41 pm
If you think my article is useful to you, please feel free to appreciate

Comment here is closed

99 comments

  1. randolz  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 70.0.3538.77(Google Chrome 70.0.3538.77)
    小白跪求关闭盒子模式下,设置背景的方法,就像大佬你这样(☆ω☆)
    1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 70.0.3538.77(Google Chrome 70.0.3538.77)
      @randolz F12搜索#bg自行参考
  2. freedom  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 66.0.3359.139(Google Chrome 66.0.3359.139)
    大佬 问一下为什么会出现这几个?

    Page Count:
    mkdir: cannot create directory `': No such file or directory
    chmod: cannot access `': No such file or directory
    Download 1 Completed!
    chmod: cannot access `.zip': No such file or directory
    Zip 1 Completed!
    1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 68.0.3440.75(Google Chrome 68.0.3440.75)
      @freedom 估计是下载的本子名字里含有什么特殊字符的情况我还没考虑到的,因为这个问题无法一次性解决所以我也是自己遇到了才能自己找这种情况
  3. Neko  Windows 10 x64 Edition(Windows 10 x64 Edition) / Firefox 56.0(Firefox 56.0)
    为什么全是东方本啊喂(
    1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 67.0.3396.99(Google Chrome 67.0.3396.99)
      @Neko 因为搜的就是东方啊∠( ᐛ 」∠)_
  4. WeiYuan  Mac OS X(Mac OS X) / Safari 11.0(Safari 11.0)
    https://www.nicemoe.com/6212
    kirin酱,好像你的文章被盗了。连headpic链接都复制过去了。然而并没有headpic。想发个表情,pad上面就是点不开。泪
    主要是看见那个视频里浏览器的头像。哈哈哈٩(。・ω・。)و
    1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 67.0.3396.87(Google Chrome 67.0.3396.87)
      @WeiYuan 发现其实有写原文,只是字太小还显示不完整……
      1. WeiYuan  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 67.0.3396.99(Google Chrome 67.0.3396.99)
        @神代綺凜 你这么说我才发现有写链接
    2. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 67.0.3396.87(Google Chrome 67.0.3396.87)
      @WeiYuan 绝了,而且浏览量比我的还高
      1. WeiYuan  Android 8.0(Android 8.0) / QQbrowser(QQbrowser)
        @神代綺凜 抱抱。不哭。|´・ω・)ノ
        1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 67.0.3396.87(Google Chrome 67.0.3396.87)
          @WeiYuan 我差点就顺着链接过去怼他了,然后后来一问,发现这站长我认识
          1. WeiYuan  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 67.0.3396.99(Google Chrome 67.0.3396.99)
            @神代綺凜 怎么认识的厉害了,dalao你的后宫遍布世界。
            1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 67.0.3396.87(Google Chrome 67.0.3396.87)
              @WeiYuan 在我现在这个主题群里
  5. 球形中  Mac OS X 10.13.5(Mac OS X 10.13.5) / Safari 11.1.1(Safari 11.1.1)
    favorites页面的是不是不能用模式A下载
    1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 67.0.3396.79(Google Chrome 67.0.3396.79)
      @球形中 favorites必须是登录状态下才能查看,而单纯用curl并不能登录(
      除非在自己电脑上登录之后获取cookie写curl参数
  6. 君君不语  Mac OS X(Mac OS X) / Safari 10.0(Safari 10.0)
    求问大佬,程序显示在109行curl:未找到命令,无法生成漫画选择的菜单是什么情况
    1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 65.0.3325.162(Google Chrome 65.0.3325.162)
      @君君不语 没安装curl

      apt-get install -y curl
      # 或者
      yum install -y curl
      1. 君君不语  Mac OS X(Mac OS X) / Safari 10.0(Safari 10.0)
        @神代綺凜 成功解决了,谢谢大佬回复
  7. zhujiwiki  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 50.0.2661.102(Google Chrome 50.0.2661.102)
    有打码,感觉就是福利
    1. 神代綺凜  Mac OS X(Mac OS X) / Safari(Safari)
      @zhujiwiki 全是福利
  8. zephyru  Windows 7 x64 Edition(Windows 7 x64 Edition) / Google Chrome 64.0.3282.186(Google Chrome 64.0.3282.186)
    路过路过..我想问下..默认设置不是有压缩包的么..我这里没有自动打包是缺什么东西么..

    zip $zipcmd "${2}.zip" "$2" >/dev/null

    这个倒是看到了..
    但是不懂shell..
    还有我想问假如..我想让它作为后台进程爬它的,我把链接关掉它也不会断..需要的时候再来查看...应该去看哪方面的知识....

    1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 65.0.3325.162(Google Chrome 65.0.3325.162)
      @zephyru 可能是因为没有安装zip

      # Ubuntu / Debian
      apt-get install -y zip unzip
      # CentOS
      yum install -y zip unzip

      想后台爬而且随时看的话可以用screen

      # Ubuntu / Debian
      apt-get install -y screen
      # CentOS
      yum install -y screen

      screen的使用

      # 进入
      screen
      # 要退出 screen 返回前台 bash 的话
      按 ctrl+A 然后再按 D
      # 要回到 screen 的话
      screen -r
    2. zephyru  Windows 7 x64 Edition(Windows 7 x64 Edition) / Google Chrome 64.0.3282.186(Google Chrome 64.0.3282.186)
      @zephyru 啊呀..这回复居然不能修改..解决了..zip问题...就是单纯的没有装zip...
      yum install zip就好了
      下面也许可以考虑..用Node来运行试试..就是不知道会是什么效果..有空也许尝试尝试...
      1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 65.0.3325.162(Google Chrome 65.0.3325.162)
        @zephyru 我正在开发一个相关项目,利用nodejs解析和下载nhentai什么的……不过目前只开发完解析部分
        1. zephyru  Windows 7 x64 Edition(Windows 7 x64 Edition) / Google Chrome 64.0.3282.186(Google Chrome 64.0.3282.186)
          @神代綺凜 其实..个人感觉..解析和下载可以交给shell用weget进行..只用node控制什么的..毕竟..用node的模块比如..request一类的实现下载一来并发控制麻烦,二来想健壮的话得写很多东西..经常下着下着卡壳了呀诸如此类..用Node解析让我来做..就直接cheerio之后取链接...但是遇到一些网站可能有什么判断吧,图片地址request下下来直接403....必须得先打开页面再去下载才行..于是我就非常笨的..开了一个浏览器页面里面嵌个iframe一边链接一边下载..我都觉得很傻..不知道你有没有什么好的思路?附上一个直接下载会403的网站以供参考...http://thedoujin.com/index.php/categories/index
          1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 65.0.3325.162(Google Chrome 65.0.3325.162)
            @zephyru 直接下载会403的话,我看了下不是防盗链限制none referer,也和Cookie没有关系,应该是UA限制,伪装一下应该就行了……

            我自己目前打算是用nodejs做解析(因为可以用jq选择器,爬虫好爬),下载独立做出一个php程序,因为我也觉得nodejs在下载这块会很麻烦

            反正目前还处于做梦阶段(。
            周末还在愉快的肝实验

            1. zephyru  Windows 7 x64 Edition(Windows 7 x64 Edition) / Google Chrome 64.0.3282.186(Google Chrome 64.0.3282.186)
              @神代綺凜 关于我刚那个问题应该没那么简单..首先我试着伪造UA..没用..
              我举个例子..
              https://img1.thedoujin.com/images/ea/2d/ea2dc290fa6238e9bc4edde5816b8ac9.jpg
              这是图片地址,直接在浏览器里访问就是403...这可是在浏览器环境下..UA肯定没问题的...
              但是在浏览器里先访问这个..
              http://thedoujin.com/index.php/pages/27548
              再去直接浏览图片..就可以看到了..果然应该还是什么判断的原因吧..
              1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 65.0.3325.162(Google Chrome 65.0.3325.162)
                @zephyru 我直接用chrome隐私模式访问是可以访问的……

                如果按你这个说的最多就是cookie判断的问题,不过隐私模式下应该是隔离所有cookie的

                1. zephyru  Windows 7 x64 Edition(Windows 7 x64 Edition) / Google Chrome 64.0.3282.186(Google Chrome 64.0.3282.186)
                  @神代綺凜 直接截张图吧..它这个判断其实挺迷的..我试着直接wget下载..发现能取到图片..
                  于是试着用..Node,request('url').pipe(fs.createWriteStream('1.jpg'))也能取到..
                  但是..如图所示...

                  看不到的话..图片地址..https://s1.ax1x.com/2018/04/07/CPGjtH.png
                  其实到这里已经不影响写爬虫了..我只是单纯的好奇...
                  听你这么一说..我又试了下..把403的页面丢在那不管..没有去点原网页..一定时间后刷新会失去响应,再把链接取出来..再看就能在浏览器里显示图片了...挺迷的..
                  1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 65.0.3325.162(Google Chrome 65.0.3325.162)
                    @zephyru 很迷……
  9. hp  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 65.0.3325.181(Google Chrome 65.0.3325.181)
    谢谢茄子
    1. 神代綺凜  Windows 10 x64 Edition(Windows 10 x64 Edition) / Google Chrome 65.0.3325.162(Google Chrome 65.0.3325.162)
      @hp