thdaemon / pixiv-novel-saver

Pixiv Novel Saver. A tool for batch downloading your loved novels from bookmarks, series id or author id with lazy mode supported.
GNU General Public License v3.0
11 stars 0 forks source link

[Bug] inline images does not save on other novels #7

Closed dundundunnn closed 1 year ago

dundundunnn commented 3 years ago

inline images from other novels are failed to recognize by the parser, i will email you an example

thdaemon commented 3 years ago

Copy from sent email:

Hi,

I created a dirty workaround. If you are in a hurry, you can apply the following patch.

This solution solves the problem, but is a low performance hack.

In the future I will use a better approach.

diff --git a/novel.sh b/novel.sh
index a3a74af..59a5032 100755
--- a/novel.sh
+++ b/novel.sh
@@ -512,15 +512,17 @@ pixiv_get_novel() {
 #    id - the id of the illust
 #    __url - a pointer to recv url string
 pixiv_get_illust_url_original() {
-       local id="$1"
+       local id=(${1//-/ })
+       local index=${id[1]:-1}
+       index=$(( $index - 1 ))
        declare -n  __url="$2"

        local tmp

-       tmp=`invoke_rest_api pixiv "ajax/illust/${id}/pages"`
+       tmp=`invoke_rest_api pixiv "ajax/illust/${id[0]}/pages"`
        __pixiv_parsehdr "$tmp" pixiv_error || return 1

-       json_get_string "$tmp" body[0].urls.original __url
+       json_get_string "$tmp" body[${index}].urls.original __url
        return 0
 }

@@ -667,7 +669,7 @@ download_inline_images() {
        local url=''
        local stat='done'

-       for i in `grep -o -E '\[pixivimage:[0-9]+\]' <<< "$1"`; do
+       for i in `grep -o -E '\[pixivimage:[0-9-]+\]' <<< "$1"`; do
                illust=`echo "$i" | cut -d : -f 2 | cut -d ] -f 1`
                pixiv_get_illust_url_original "$illust" url || echo "[warning] pixiv_get_illust_url_original: $pixiv_error"
                if [ -z "$url" ]; then