forked from Nandaka/PixivUtil2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_PixivModel_fanbox.py
247 lines (199 loc) · 10.5 KB
/
test_PixivModel_fanbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/c/Python27/python.exe
# -*- coding: UTF-8 -*-
from __future__ import print_function
import sys
import os
import unittest
import re
from PixivModelFanbox import Fanbox, FanboxArtist, FanboxPost
import PixivHelper
temp = PixivHelper.__re_manga_index
class TestPixivModel_Fanbox(unittest.TestCase):
currPath = unicode(os.path.abspath('.'))
PixivHelper.GetLogger()
def testFanboxSupportedArtist(self):
p = open('./test/Fanbox_supported_artist.json', 'r').read()
result = Fanbox(p)
self.assertIsNotNone(result)
self.assertEqual(len(result.supportedArtist), 3)
self.assertTrue(190026 in result.supportedArtist)
self.assertTrue(685000 in result.supportedArtist)
self.assertTrue(15521131 in result.supportedArtist)
def testFanboxArtistPosts(self):
p = open('./test/Fanbox_artist_posts.json', 'r').read()
result = FanboxArtist(15521131, p)
self.assertIsNotNone(result)
self.assertEqual(result.artistId, 15521131)
self.assertTrue(result.hasNextPage)
self.assertTrue(len(result.nextUrl) > 0)
self.assertTrue(len(result.posts) > 0)
for post in result.posts:
self.assertFalse(post.is_restricted)
# post-136761 image
self.assertEqual(result.posts[0].imageId, 136761)
self.assertTrue(len(result.posts[0].imageTitle) > 0)
self.assertTrue(len(result.posts[0].coverImageUrl) > 0)
self.assertEqual(result.posts[0].type, "image")
self.assertEqual(len(result.posts[0].images), 5)
# post-132919 text
self.assertEqual(result.posts[2].imageId, 132919)
self.assertTrue(len(result.posts[2].imageTitle) > 0)
self.assertIsNone(result.posts[2].coverImageUrl)
self.assertEqual(result.posts[2].type, "text")
self.assertEqual(len(result.posts[2].images), 0)
# post-79695 image
self.assertEqual(result.posts[3].imageId, 79695)
self.assertTrue(len(result.posts[3].imageTitle) > 0)
self.assertIsNone(result.posts[3].coverImageUrl)
self.assertEqual(result.posts[3].type, "image")
self.assertEqual(len(result.posts[3].images), 4)
def testFanboxArtistArticle(self):
p = open('./test/Fanbox_artist_posts_article.json', 'r').read()
result = FanboxArtist(190026, p)
self.assertIsNotNone(result)
self.assertEqual(result.artistId, 190026)
self.assertTrue(result.hasNextPage)
self.assertTrue(len(result.nextUrl) > 0)
self.assertTrue(len(result.posts) > 0)
# post-201946 article
self.assertEqual(result.posts[0].imageId, 201946)
self.assertTrue(len(result.posts[0].imageTitle) > 0)
self.assertIsNone(result.posts[0].coverImageUrl)
self.assertEqual(result.posts[0].type, "article")
self.assertEqual(len(result.posts[0].images), 5)
self.assertEqual(len(result.posts[0].body_text), 1292)
# result.posts[0].WriteInfo("./201946.txt")
def testFanboxArtistArticleFileMap(self):
p = open('./test/creator_with_filemap.json', 'r').read()
result = FanboxArtist(190026, p)
self.assertIsNotNone(result)
self.assertEqual(result.artistId, 190026)
self.assertTrue(result.hasNextPage)
self.assertTrue(len(result.nextUrl) > 0)
self.assertTrue(len(result.posts) > 0)
# post-201946 article
self.assertEqual(result.posts[0].imageId, 210980)
self.assertTrue(len(result.posts[0].imageTitle) > 0)
self.assertIsNone(result.posts[0].coverImageUrl)
self.assertEqual(result.posts[0].type, "article")
self.assertEqual(len(result.posts[0].images), 15)
self.assertEqual(len(result.posts[0].body_text), 3006)
# result.posts[0].WriteInfo("./210980.txt")
def testFanboxArtistVideo(self):
p = open('./test/creator_posts_with_video.json', 'r').read()
result = FanboxArtist(711048, p)
self.assertIsNotNone(result)
self.assertEqual(result.artistId, 711048)
self.assertTrue(result.hasNextPage)
self.assertTrue(len(result.nextUrl) > 0)
self.assertTrue(len(result.posts) > 0)
# post-201946 article
self.assertEqual(result.posts[4].imageId, 330905)
self.assertTrue(len(result.posts[4].imageTitle) > 0)
self.assertEqual(result.posts[4].coverImageUrl, u'https://pixiv.pximg.net/c/1200x630_90_a2_g5/fanbox/public/images/post/330905/cover/3A2zPUg4s6iz17MM0Z45eWBj.jpeg')
self.assertEqual(result.posts[4].type, "video")
self.assertEqual(len(result.posts[4].images), 0)
self.assertEqual(len(result.posts[4].body_text), 99)
# result.posts[0].WriteInfo("./210980.txt")
def testFanboxArtistArticleEmbedTwitter(self):
p = open('./test/creator_embedMap.json', 'r').read()
result = FanboxArtist(68813, p)
self.assertIsNotNone(result)
self.assertEqual(result.artistId, 68813)
self.assertFalse(result.hasNextPage)
self.assertTrue(len(result.posts) > 0)
# post-201946 article
self.assertEqual(result.posts[0].imageId, 285502)
self.assertTrue(len(result.posts[0].imageTitle) > 0)
self.assertEqual(result.posts[0].coverImageUrl, u'https://pixiv.pximg.net/c/1200x630_90_a2_g5/fanbox/public/images/post/285502/cover/orx9TCsiPFi5sgDdbvg4zwkX.jpeg')
self.assertEqual(result.posts[0].type, "article")
self.assertEqual(len(result.posts[0].images), 7)
self.assertEqual(len(result.posts[0].body_text), 3095)
# result.posts[0].WriteInfo("./285502.txt")
def testFanboxArtistPostsNextPage(self):
p2 = open('./test/Fanbox_artist_posts_nextpage.json', 'r').read()
result = FanboxArtist(15521131, p2)
self.assertIsNotNone(result)
self.assertEqual(result.artistId, 15521131)
self.assertFalse(result.hasNextPage)
self.assertTrue(result.nextUrl is None)
self.assertEqual(len(result.posts), 1)
def testFanboxArtistPostsRestricted(self):
p = open('./test/Fanbox_artist_posts_restricted.json', 'r').read()
result = FanboxArtist(15521131, p)
self.assertIsNotNone(result)
self.assertEqual(result.artistId, 15521131)
self.assertTrue(result.hasNextPage)
self.assertTrue(len(result.nextUrl) > 0)
self.assertEqual(len(result.posts), 10)
for post in result.posts:
self.assertTrue(post.is_restricted)
def testFanboxArtistPostsRestrictedNextPage(self):
p = open('./test/Fanbox_artist_posts_next_page_restricted.json', 'r').read()
result = FanboxArtist(15521131, p)
self.assertIsNotNone(result)
self.assertEqual(result.artistId, 15521131)
self.assertFalse(result.hasNextPage)
self.assertTrue(result.nextUrl is None)
self.assertEqual(len(result.posts), 6)
self.assertTrue(result.posts[0].is_restricted)
self.assertFalse(result.posts[1].is_restricted)
def testFanboxFilename(self):
p = open('./test/Fanbox_artist_posts.json', 'r').read()
result = FanboxArtist(15521131, p)
self.assertIsNotNone(result)
root_dir = os.path.abspath(os.path.curdir)
post = result.posts[0]
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))
re_page = temp.findall(fake_image_url)
self.assertIsNotNone(re_page)
self.assertEqual(re_page[0], u"0")
def simple_from_images():
filename_format = '%title%_%urlFilename%'
filename = PixivHelper.makeFilename(filename_format,
post,
artistInfo=result,
tagsSeparator=" ",
tagsLimit=0,
fileUrl=fake_image_url,
bookmark=None,
searchTags='')
filename = PixivHelper.sanitizeFilename(filename, root_dir)
self.assertEqual(filename, root_dir + os.sep + u"アスナさん02_136761_p0_hcXl48iORoJykmrR3zPZEoUu.jpeg")
simple_from_images()
def more_format():
# from images
filename_format = '%member_id%' + os.sep + '%image_id%_p%page_index%_%title%_%urlFilename%_%works_date%'
filename = PixivHelper.makeFilename(filename_format,
post,
artistInfo=result,
tagsSeparator=" ",
tagsLimit=0,
fileUrl=fake_image_url,
bookmark=None,
searchTags='')
filename = PixivHelper.sanitizeFilename(filename, root_dir)
self.assertEqual(filename, root_dir + os.sep + u"15521131" + os.sep + u"136761_p0_アスナさん02_136761_p0_hcXl48iORoJykmrR3zPZEoUu_2018-08-26 20_28_16.jpeg")
more_format()
def cover_more_format():
# https://pixiv.pximg.net/c/1200x630_90_a2_g5/fanbox/public/images/post/96862/cover/6SRpcQwIUuJdeZbhn5q85l9x.jpeg
fake_image_url = post.coverImageUrl.replace("{0}/cover/".format(post.imageId), "{0}_".format(post.imageId))
print(fake_image_url)
filename_format = '%member_id%' + os.sep + '%image_id%_%title%_%urlFilename%_%works_date%'
filename = PixivHelper.makeFilename(filename_format,
post,
artistInfo=result,
tagsSeparator=" ",
tagsLimit=0,
fileUrl=fake_image_url,
bookmark=None,
searchTags='')
filename = PixivHelper.sanitizeFilename(filename, root_dir)
self.assertEqual(filename, root_dir + os.sep + u"15521131" + os.sep + u"136761_アスナさん02_136761_OqhhcslOfbzZpHyTfJNtnIWm_2018-08-26 20_28_16.jpeg")
cover_more_format()
if __name__ == '__main__':
# unittest.main()
suite = unittest.TestLoader().loadTestsFromTestCase(TestPixivModel_Fanbox)
unittest.TextTestRunner(verbosity=5).run(suite)