Skip to content

Commit

Permalink
update #930, replace resized cover with full size instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Nandaka committed Apr 29, 2021
1 parent 47ac339 commit 4423bb6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
2 changes: 1 addition & 1 deletion PixivFanboxHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def process_fanbox_artist_by_id(caller, config, artist_id, end_page, title_prefi
artist.artistToken = result[7]
PixivHelper.print_and_log("info", f"Using saved artist name and token from db: {artist.artistName}, {artist.artistToken}")
else:
PixivHelper.print_and_log("warn", f"Artist name or token found in FANBOX filename formats, but not in db.")
PixivHelper.print_and_log("warn", "Artist name or token found in FANBOX filename formats, but not in db.")
if name_flag:
artist.artistName = input(f"Please input %artist% for {artist_id}: ").strip()
if token_flag:
Expand Down
7 changes: 4 additions & 3 deletions PixivModelFanbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ def parsePost(self, jsPost):
if self.coverImageUrl is not None:
original_url = jsPost["coverImageUrl"]
self.fullCoverSizeUrl = _re_fanbox_cover.sub("fanbox", original_url)
self.try_add(self.fullCoverSizeUrl, self.images)
self.try_add(self.fullCoverSizeUrl, self.embeddedFiles)
self.coverImageUrl = self.fullCoverSizeUrl
# self.try_add(self.fullCoverSizeUrl, self.images)
# self.try_add(self.fullCoverSizeUrl, self.embeddedFiles)

self.worksDate = jsPost["publishedDatetime"]
self.worksDateDateTime = datetime_z.parse_datetime(self.worksDate)
Expand Down Expand Up @@ -435,7 +436,7 @@ def WriteHtml(self, html_template, useAbsolutePaths, filename):
if self.coverImageUrl:
# Issue #930
if self.fullCoverSizeUrl:
cover_image = f'<div class="cover"><a href="{self.fullCoverSizeUrl}" target="_blank"><img src="{self.coverImageUrl}"/></a></div>'
cover_image = f'<div class="cover"><a href="{self.fullCoverSizeUrl}" target="_blank"><img style="max-width: 1200px; height:auto;" src="{self.coverImageUrl}"/></a></div>'
else:
cover_image = f'<div class="cover"><img src="{self.coverImageUrl}"/></div>'
page = html_template.replace("%coverImage%", cover_image)
Expand Down
35 changes: 12 additions & 23 deletions test_PixivModel_fanbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def testFanboxArtistPosts(self):
self.assertTrue(len(result[0].imageTitle) > 0)
self.assertTrue(len(result[0].coverImageUrl) > 0)
self.assertEqual(result[0].type, "image")
self.assertEqual(len(result[0].images), 6)
self.assertEqual(len(result[0].images), 5)

# post-132919 text
self.assertEqual(result[2].imageId, 132919)
Expand Down Expand Up @@ -136,9 +136,9 @@ def testFanboxArtistVideo(self):
# post-201946 article
self.assertEqual(result[4].imageId, 330905)
self.assertTrue(len(result[4].imageTitle) > 0)
self.assertEqual(result[4].coverImageUrl, u'https://pixiv.pximg.net/c/1200x630_90_a2_g5/fanbox/public/images/post/330905/cover/3A2zPUg4s6iz17MM0Z45eWBj.jpeg')
self.assertEqual(result[4].coverImageUrl, u'https://pixiv.pximg.net/fanbox/public/images/post/330905/cover/3A2zPUg4s6iz17MM0Z45eWBj.jpeg')
self.assertEqual(result[4].type, "video")
self.assertEqual(len(result[4].images), 1)
self.assertEqual(len(result[4].images), 0)
self.assertEqual(len(result[4].body_text), 109)
print(result[4].body_text)

Expand All @@ -161,9 +161,9 @@ def testFanboxArtistArticleEmbedTwitter(self):
# post-201946 article
self.assertEqual(result[0].imageId, 285502)
self.assertTrue(len(result[0].imageTitle) > 0)
self.assertEqual(result[0].coverImageUrl, u'https://pixiv.pximg.net/c/1200x630_90_a2_g5/fanbox/public/images/post/285502/cover/orx9TCsiPFi5sgDdbvg4zwkX.jpeg')
self.assertEqual(result[0].coverImageUrl, u'https://pixiv.pximg.net/fanbox/public/images/post/285502/cover/orx9TCsiPFi5sgDdbvg4zwkX.jpeg')
self.assertEqual(result[0].type, "article")
self.assertEqual(len(result[0].images), 8)
self.assertEqual(len(result[0].images), 7)
self.assertEqual(len(result[0].body_text), 3414)

# result.posts[0].WriteInfo("./285502.txt")
Expand Down Expand Up @@ -260,8 +260,8 @@ def testFanboxNewApi2_MultiImages(self):
self.assertIsNotNone(result)

self.assertEqual(result.imageId, 855025)
self.assertEqual(len(result.images), 3)
self.assertEqual(len(result.embeddedFiles), 3)
self.assertEqual(len(result.images), 2)
self.assertEqual(len(result.embeddedFiles), 2)
self.assertIsNotNone(result.coverImageUrl)
self.assertFalse(result.coverImageUrl in result.images)

Expand All @@ -274,8 +274,8 @@ def testFanboxNewApi2_Files(self):
self.assertIsNotNone(result)

self.assertEqual(result.imageId, 685832)
self.assertEqual(len(result.images), 2)
self.assertEqual(len(result.embeddedFiles), 2)
self.assertEqual(len(result.images), 1)
self.assertEqual(len(result.embeddedFiles), 1)
self.assertIsNotNone(result.coverImageUrl)
self.assertFalse(result.coverImageUrl in result.images)

Expand All @@ -290,10 +290,10 @@ def testFanboxFilename(self):
root_dir = os.path.abspath(os.path.curdir)
post = result[0]

# 'https://pixiv.pximg.net/fanbox/public/images/post/136761/cover/OqhhcslOfbzZpHyTfJNtnIWm.jpeg'
big_cover_url = post.images[0]
# # 'https://pixiv.pximg.net/fanbox/public/images/post/136761/cover/OqhhcslOfbzZpHyTfJNtnIWm.jpeg'
# big_cover_url = post.images[0]
# 'https://fanbox.pixiv.net/images/post/136761/hcXl48iORoJykmrR3zPZEoUu.jpeg'
image_url = post.images[1]
image_url = post.images[0]
# current_page = 0
# fake_image_url = image_url.replace("{0}/".format(post.imageId), "{0}_p{1}_".format(post.imageId, current_page))

Expand All @@ -319,17 +319,6 @@ def simple_from_images():
filename = PixivHelper.sanitize_filename(filename, root_dir)

self.assertEqual(filename, root_dir + os.sep + "アスナさん02_hcXl48iORoJykmrR3zPZEoUu.jpeg")
filename2 = PixivHelper.make_filename(filename_format,
post,
artistInfo=artist,
tagsSeparator=" ",
tagsLimit=0,
fileUrl=big_cover_url,
bookmark=None,
searchTags='')
filename = PixivHelper.sanitize_filename(filename2, root_dir)

self.assertEqual(filename, root_dir + os.sep + "アスナさん02_OqhhcslOfbzZpHyTfJNtnIWm.jpeg")
simple_from_images()

def more_format():
Expand Down

0 comments on commit 4423bb6

Please sign in to comment.