5 Commits

Author SHA1 Message Date
lamp 79c5a7abe5 Merge branch 'master' of gitea.moe:lamp/pixiv-popular-downloader 2021-09-21 13:12:43 -07:00
lamp edb1af72eb eliminate the need to edit hosts file 2021-09-21 13:10:56 -07:00
lamp 9440fcf740 Update 'README.md' 2021-09-21 06:09:21 -05:00
lamp f5eb46e8a8 refactored on python 2021-09-21 04:04:51 -07:00
lamp f815b730f0 resurrect python script 2021-09-21 03:38:29 -07:00
9 changed files with 79 additions and 12 deletions
+1 -2
View File
@@ -1,3 +1,2 @@
node_modules PHPSESSID.txt
download download
chromium_data
+8 -9
View File
@@ -1,12 +1,11 @@
This is a python script for downloading original pixiv images from popular search results via a premium account.
### example usage # Instructions
```sh
node pixiv-downloader.js "初音ミク" -p 3
```
Chromium window will appear where you'll need to sign in to your pixiv premium account if you haven't already. 1. Download this repo to your computer of course, and open the terminal in it. Run `pip install -r requirements.txt` if necessary.
### args 2. In your browser, on Pixiv logged in to a premium account, in dev tools Application tab, copy the **value** of the `PHPSESSID` cookie, and paste it into a new file named `PHPSESSID.txt` in this folder.
- `-p <num>` for number of pages (default 1)
- `-s <num>` for page number to start on (default 1) 3. Run `python pixiv-popular-downloader.py -h` for usage information. Example usage to download 10 pages of 初音ミク tag, including r18: `python pixiv-popular-downloader.py -r -p 10 "初音ミク"`
- `-r` to include R18
4. Check the download folder. If you're getting newest results instead of popular results, then your PHPSESSID failed to work.
+3
View File
@@ -0,0 +1,3 @@
node_modules
download
chromium_data
+12
View File
@@ -0,0 +1,12 @@
### example usage
```sh
node pixiv-downloader.js "初音ミク" -p 3
```
Chromium window will appear where you'll need to sign in to your pixiv premium account if you haven't already.
### args
- `-p <num>` for number of pages (default 1)
- `-s <num>` for page number to start on (default 1)
- `-r` to include R18
View File
View File
+51
View File
@@ -0,0 +1,51 @@
import argparse
import requests
from requests_toolbelt.adapters import host_header_ssl
from urllib.parse import quote as encodeURI
import os
ap = argparse.ArgumentParser()
ap.add_argument("tag", help="Pixiv tag(s) to search")
ap.add_argument("-p", dest="numpages", type=int, default=1, help="number of pages to download (default 1)")
ap.add_argument("-s", dest="startpagenum", type=int, default=1, help="page number to start at")
ap.add_argument("-r", action='store_true', help="include r18 posts")
args = ap.parse_args()
PHPSESSID = None
with open("PHPSESSID.txt", 'r') as f:
PHPSESSID = f.read()
rqs = requests.Session()
rqs.mount('https://', host_header_ssl.HostHeaderSSLAdapter())
download_count = 1
for i in range(args.startpagenum, args.numpages+1):
page_url = f"https://210.140.131.219/ajax/search/artworks/{encodeURI(args.tag, safe='')}?order=popular_d&mode={'all' if args.r else 'safe'}&p={i}"
print("get", page_url)
page_data = rqs.get(page_url, cookies={"PHPSESSID": PHPSESSID}, headers={"host":"www.pixiv.net"}).json()
if (page_data['error']):
print(page_data['message'])
exit(1)
for illust in page_data['body']['illustManga']['data']:
illust_r18 = bool(illust['xRestrict'])
illust_url = f"https://210.140.131.219/ajax/illust/{illust['id']}/pages"
print("get", illust_url)
illust_data = rqs.get(illust_url, headers={"host":"www.pixiv.net"}).json()
if (illust_data['error']):
print(illust_data['message'])
else:
for image in illust_data['body']:
image_url = image['urls']['original']
download_dir = f"download/{args.tag}/"
os.makedirs(download_dir, exist_ok=True)
download_filename = str(download_count) + '_' + ('x_' if illust_r18 else '') + image_url.split('/').pop()
download_path = download_dir + download_filename
if os.path.exists(download_path):
print(download_path, "already exists")
continue
print("get", image_url)
res = rqs.get(image_url, headers={'referer':'https://www.pixiv.net'})
with open(download_path, "wb") as f:
f.write(res.content)
print("saved", download_filename)
download_count = download_count + 1
+3
View File
@@ -0,0 +1,3 @@
requests==2.26.0
requests-toolbelt==0.9.1
urllib3==1.26.6