Skip to content

Commit

Permalink
Implement #639
Browse files Browse the repository at this point in the history
  • Loading branch information
Nandaka committed Feb 26, 2020
1 parent b8e3b7d commit 55203f7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 6 deletions.
10 changes: 10 additions & 0 deletions PixivConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class PixivConfig():
useBlacklistMembers = False
maxFileSize = 0
minFileSize = 0
downloadResized = False

# filename related
filenameFormat = '%artist% (%member_id%)' + os.sep + '%urlFilename% - %title%'
Expand Down Expand Up @@ -621,6 +622,13 @@ def loadConfig(self, path=None):
self.autoAddMember = False
haveError = True

try:
self.downloadResized = config.getboolean('DownloadControl', 'downloadResized')
except ValueError:
print("downloadResized = False")
self.downloadResized = False
haveError = True

except BaseException:
print('Error at loadConfig():', sys.exc_info())
self.__logger.exception('Error at loadConfig()')
Expand Down Expand Up @@ -733,6 +741,7 @@ def writeConfig(self, error=False, path=None):
config.set('DownloadControl', 'dateDiff', self.dateDiff)
config.set('DownloadControl', 'enableInfiniteLoop', self.enableInfiniteLoop)
config.set('DownloadControl', 'useBlacklistMembers', self.useBlacklistMembers)
config.set('DownloadControl', 'downloadResized', self.downloadResized)

if path is not None:
configlocation = path
Expand Down Expand Up @@ -855,5 +864,6 @@ def printConfig(self):
print(' - dateDiff =', self.dateDiff)
print(' - enableInfiniteLoop =', self.enableInfiniteLoop)
print(' - useBlacklistMembers =', self.useBlacklistMembers)
print(' - downloadResized =', self.downloadResized)

print('')
16 changes: 15 additions & 1 deletion PixivImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PixivImage (object):
imageTags = []
imageMode = ""
imageUrls = []
imageResizedUrls = []
worksDate = ""
worksResolution = ""
worksTools = ""
Expand All @@ -55,6 +56,7 @@ def __init__(self, iid=0, page=None, parent=None, fromBookmark=False,
self.bookmark_count = bookmark_count
self.imageId = iid
self.imageUrls = []
self.imageResizedUrls = []
self.dateFormat = dateFormat
self.descriptionUrlList = []
self._tzInfo = tzInfo
Expand Down Expand Up @@ -112,11 +114,14 @@ def ParseInfo(self, page):
root = page["illust"][key]

self.imageUrls = list()
self.imageResizedUrls = list()

self.imageCount = int(root["pageCount"])
temp_url = root["urls"]["original"]
temp_resized_url = root["urls"]["regular"]
if self.imageCount == 1:
if temp_url.find("ugoira") > 0:
# ugoira mode
self.imageMode = "ugoira_view"
# https://i.pximg.net/img-zip-ugoira/img/2018/04/22/00/01/06/68339821_ugoira600x600.zip 1920x1080
# https://i.pximg.net/img-original/img/2018/04/22/00/01/06/68339821_ugoira0.jpg
Expand All @@ -126,15 +131,24 @@ def ParseInfo(self, page):
temp_url = temp_url.split("_ugoira0")[0]
temp_url = temp_url + "_ugoira1920x1080.zip"
self.imageUrls.append(temp_url)
# self.ParseUgoira(page)

temp_resized_url = temp_url.replace("/img-original/", "/img-zip-ugoira/")
temp_resized_url = temp_resized_url.split("_ugoira0")[0]
temp_resized_url = temp_resized_url + "_ugoira600x600.zip"
self.imageResizedUrls.append(temp_resized_url)
else:
# single page image
self.imageMode = "big"
self.imageUrls.append(temp_url)
self.imageResizedUrls.append(temp_resized_url)
elif self.imageCount > 1:
# multi-page images
self.imageMode = "manga"
for i in range(0, self.imageCount):
url = temp_url.replace("_p0", "_p{0}".format(i))
self.imageUrls.append(url)
resized_url = temp_resized_url.replace("_p0", "_p{0}".format(i))
self.imageResizedUrls.append(resized_url)

# title/caption
self.imageTitle = root["illustTitle"]
Expand Down
8 changes: 7 additions & 1 deletion PixivUtil2.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,13 @@ def process_image(artist=None, image_id=None, user_dir='', bookmark=False, searc
result = PixivConstant.PIXIVUTIL_OK
manga_files = dict()
page = 0
for img in image.imageUrls:

# Issue #639
source_urls = image.imageUrls
if __config__.downloadResized:
source_urls = image.imageResizedUrls

for img in source_urls:
print('Image URL :', img)
url = os.path.basename(img)
split_url = url.split('.')
Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
20200226-beta1
- Fix Issue #641: update API endpoints for Pixiv FANBOX.
- Implement #639: add option to download the resized image, rather than original size.
set `downloadResized = True` at `[DownloadControl]` section in config.ini to enable.

20200125 - Happy CNY 2020!
- Update #623: change default local to '', if exists then use the current locale.
Expand Down
11 changes: 7 additions & 4 deletions test_PixivModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ def testPixivImageParseInfo(self):
self.assertEqual(image2.imageMode, "big")
self.assertEqual(image2.worksDate, '12/10/12 15:23')
self.assertEqual(image2.worksResolution, '642x900')
# self.assertEqual(image2.worksTools, 'Photoshop SAI')
# self.assertEqual(image2.jd_rtv, 88190)
# self.assertEqual(image2.jd_rtc, 6711)
# self.assertEqual(image2.jd_rtt, 66470)
self.assertEqual(len(image2.imageUrls), 1)
self.assertEqual(len(image2.imageResizedUrls), 1)

self.assertEqual(image2.artist.artistToken, 'nardack')

# def testPixivImageParseInfo2(self):
Expand Down Expand Up @@ -306,6 +305,9 @@ def testPixivImageModeManga(self):
self.assertEqual(image.imageId, 28820443)
self.assertEqual(image.imageMode, 'manga')

self.assertEqual(len(image.imageUrls), 2)
self.assertEqual(len(image.imageResizedUrls), 2)

def testPixivImageParseMangaInfoMixed(self):
# print('\nTesting parse Manga Images')
# Issue #224
Expand Down Expand Up @@ -414,6 +416,7 @@ def testPixivImageUgoira(self):
image = PixivImage(46281014, page)
# print(image.imageUrls)
self.assertTrue(image.imageUrls[0].find(".zip") > -1)
self.assertTrue(image.imageResizedUrls[0].find(".zip") > -1)

def testPixivImageParseInfoSelf(self):
# assuming being accessed via manage page for your own artwork.
Expand Down

1 comment on commit 55203f7

@jonatanm27
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG"
Thank you so much for implementing my suggestion!
Also thank you in general for this beautiful program
I wish I could support you T-T

Please sign in to comment.