Made by @choshicure Download pixiv's Ugoira There is a program called. It's very easy to use, but the gif is compressed quite a bit, and I can't move it cleanly. https://aviutl.info/gif-puraguinn/ The features of gif are described in detail here, so if you want to know, please have a look. I looked at PIL, but it seems that the degree of compression cannot be changed. So I decided to use openCV to make mp4 instead of gif. I also thought about ffmpeg, but I stopped it because it seems to be difficult to pass through the path.
pixivpy is probably a library made by Chinese volunteers and is not official. Therefore, it is recommended to use a method such as throwing away the user id and password at the time of login so that they can be leaked. Abuse is strictly prohibited. There is an implicit rule of scraping that you can only requery once per second. Without this, it would be a dos attack and legally out. Please comment out sleep at your own risk. If you have any problems, please do so at your own risk.
This program runs under windows10 environment. I don't know if it works under Linux or Mac environment. Works with the latest version of anaconda as of December 30, 2020
pip install opencv-python
pip install pixivpy
Up to the point of downloading the image Made by @choshicure [Download pixiv's mover] (https://qiita.com/choshicure/items/8795bf929e34af6622fc) Is the same as. Please read this article for explanations of variables.
The part to be converted to mp4 in the latter half Make a video from serial number images using Python3 + OpenCV I referred to.
ugoira_mp4_downloader.py
from pixivpy3 import *
from time import sleep
from PIL import Image
import os, glob
import sys
import cv2
#Login process
aapi = AppPixivAPI()
ID = 'YOUR_ID'
PASS = 'YOUR_PASS'
aapi.login(ID, PASS)
#Waiting for illustration ID input
illust_id = int(input('>>'))
illust = aapi.illust_detail(illust_id)
ugoira_url = illust.illust.meta_single_page.original_image_url.rsplit('0', 1)
ugoira = aapi.ugoira_metadata(illust_id)
ugoira_frames = len(ugoira.ugoira_metadata.frames)
ugoira_delay = ugoira.ugoira_metadata.frames[0].delay
dir_name = str(illust_id)+'_ugoira'
#Create a folder to save the movement
if not os.path.isdir(dir_name):
os.mkdir(dir_name)
#Download all images used in Ugoira
for frame in range(ugoira_frames):
print(frame)
frame_url = ugoira_url[0] + str(frame) + ugoira_url[1]
aapi.download(frame_url, path=dir_name)
sleep(2) #Wait 2 seconds after downloading
#Creating a video
frames = glob.glob(f'{dir_name}/*_ugoira*')
frames.sort(key=os.path.getmtime, reverse=False)
#parameter
fps = 1000 / ugoira_delay
height = illust.illust.height
width = illust.illust.width
# encoder(for mp4)
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
# output file name, encoder, fps, size(fit to image size)
video = cv2.VideoWriter(f'{dir_name}/{illust_id}.mp4',fourcc, fps, (width, height))
for frame in frames:
img = cv2.imread(frame)
video.write(img)
video.release()
print('written')
The file size is smaller than gif, and you can now download beautiful mp4. However, mp4 cannot loop.
Download all works of a specific user from pixiv at once using pixivpy of python (including moving) I also want to support mp4
[Download pixiv's Ugoira] (https://qiita.com/choshicure/items/8795bf929e34af6622fc) Make a video from serial number images using Python3 + OpenCV OpenCV video codec Make graph animation with Python (output mp4 file with OpenCV) cv::VideoWriter Class Reference Animate multiple still images with Python
Recommended Posts