Differences between version 2 and previous revision of KnowledgeBase/Scripts/e621.
Other diffs: Previous Major Revision, Previous Author
Newer page: | version 2 | Last edited on Sunday, 28 February 2010 21:59:22 | by CyberLeo | Revert |
Older page: | version 1 | Last edited on Sunday, 28 February 2010 21:12:47 | by CyberLeo | Revert |
@@ -1,13 +1,41 @@
<code brush="bash">
+# <post> : Emit the file download url for a given post
e621_post_to_link() {
post="${1}"
- wget -qO- "http://www.e621.net/post/show/${1
}" | sed -e '/class="original-file-unchanged"/!d; s/^.* href="//g; s/" class=".*$//g'
+ [ "${post}" ] || return 1
+
wget -qO- "http://www.e621.net/post/show/${post
}" | sed -e '/class="original-file-unchanged"/!d; s/^.* href="//g; s/" class=".*$//g'
}
+# <post> [filename] : Download the given post, optionally specifying a name
+# if the name lacks an extension, use that of the original url
e621_download_post() {
post="${1}"
+ [ "${post}" ] || return 1
url="$(e621_post_to_link "${post}")"
- file="${2:-
$(echo "${url}" | sed -e 's/\?.*$//; s/^.*\/\([^\/
]*\)$/\1/')}"
+ eval
$(echo "${url}" | sed -e 's/\?.*$//; s/^.*\///g; s/^\(.*\.
\([^.
]*\)
\)$/file="
\1" ext="\2"
/')
+ file="${2:-${file}}"
+ if echo "${file}" | grep -vq "\."
+ then
+ file="${file}.${ext
}"
+ fi
wget -O "${file}" "${url}"
+}
+
+# <pool> : Emit a list of posts in this pool
+e621_pool_posts() {
+ pool="${1}"
+ [ "${pool}" ] || return 1
+ wget -qO- "http://www.e621.net/pool/show/${pool}" | sed -e '/class="plid"/!d; s/^.*\#pl //g; s/<\/span.*$//g; s/^.*\/\([^\/]*\)$/\1/g'
+}
+
+# <pool> [start_count] : Download an entire pool, naming the files sequentially
+e621_download_pool() {
+ pool="${1}"
+ [ "${pool}" ] || return 1
+ count="${2:-0}"
+ e621_pool_posts "${pool}" | while read post
+ do
+ name="$(printf "%02u" "${count}")"
+ done
}
</code>
version 2
# <post> : Emit the file download url for a given post e621_post_to_link() { post="${1}" [ "${post}" ] || return 1 wget -qO- "http://www.e621.net/post/show/${post}" | sed -e '/class="original-file-unchanged"/!d; s/^.* href="//g; s/" class=".*$//g' } # <post> [filename] : Download the given post, optionally specifying a name # if the name lacks an extension, use that of the original url e621_download_post() { post="${1}" [ "${post}" ] || return 1 url="$(e621_post_to_link "${post}")" eval $(echo "${url}" | sed -e 's/\?.*$//; s/^.*\///g; s/^\(.*\.\([^.]*\)\)$/file="\1" ext="\2"/') file="${2:-${file}}" if echo "${file}" | grep -vq "\." then file="${file}.${ext}" fi wget -O "${file}" "${url}" } # <pool> : Emit a list of posts in this pool e621_pool_posts() { pool="${1}" [ "${pool}" ] || return 1 wget -qO- "http://www.e621.net/pool/show/${pool}" | sed -e '/class="plid"/!d; s/^.*\#pl //g; s/<\/span.*$//g; s/^.*\/\([^\/]*\)$/\1/g' } # <pool> [start_count] : Download an entire pool, naming the files sequentially e621_download_pool() { pool="${1}" [ "${pool}" ] || return 1 count="${2:-0}" e621_pool_posts "${pool}" | while read post do name="$(printf "%02u" "${count}")" done }