def testPixivImageParseManga(self): # print '\nTesting parse Manga Images' p = open('./test/test-image-parsemanga.htm', 'r') page = BeautifulSoup(p.read()) image = PixivImage() urls = image.ParseImages(page, mode='manga', _br=MockPixivBrowser(None)) # print urls self.assertEqual(len(urls), 3) self.assertEqual(len(urls), image.imageCount) imageId = urls[0].split('/')[-1].split('.')[0] # print 'imageId:',imageId self.assertEqual(imageId, '46279245_p0')
def testPixivImageParseMangaBig(self): # print '\nTesting parse Manga Images' # Issue #224 p = open('./test/test-image-big-manga.html', 'r') page = BeautifulSoup(p.read()) image = PixivImage(iid=62670665) image.ParseInfo(page) urls = image.ParseImages(page, mode=image.imageMode, _br=MockPixivBrowser(1)) self.assertEqual(len(urls), 1) print urls[0] imageId = urls[0].split('/')[-1].split('_')[0] # print 'imageId:',imageId self.assertEqual(int(imageId), 62670665)
def testPixivImageServerError2(self): # print('\nTesting image page') p = open('./test/test-image-generic-error.html', 'r') page = p.read() with self.assertRaises(PixivException) as ex: image = PixivImage(37882549, page) self.assertEqual(ex.exception.errorCode, PixivException.UNKNOWN_IMAGE_ERROR)
def testPixivImageParseInfo(self): p = open('./test/test-image-info.html', 'r') page = BeautifulSoup(p.read()) image2 = PixivImage(32039274, page) page.decompose() del page self.assertEqual(image2.imageId, 32039274) self.assertEqual(image2.imageTitle, u"新しいお姫様") self.assertTrue(len(image2.imageCaption) > 0) print u"\r\nCaption = {0}".format(image2.imageCaption) self.assertTrue(u'MAYU' in image2.imageTags) self.assertTrue(u'VOCALOID' in image2.imageTags) self.assertTrue(u'VOCALOID3' in image2.imageTags) self.assertTrue(u'なにこれかわいい' in image2.imageTags) self.assertTrue(u'やはり存在する斧' in image2.imageTags) self.assertEqual(image2.imageMode, "bigNew") self.assertEqual(image2.worksDate, '12/11/2012 00: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(image2.artist.artistToken, 'nardack')
def testPixivImageParseInfoPixivPremiumOffer(self): p = open('./test/test-image-parse-image-38826533-pixiv-premium.html', 'r') page = BeautifulSoup(p.read()) image2 = PixivImage(38826533, page) page.decompose() del page self.assertEqual(image2.imageId, 38826533) self.assertEqual(image2.imageTitle, u"てやり") self.assertEqual(image2.imageCaption, u'一応シーダ様です。') self.assertTrue(u'R-18' in image2.imageTags) self.assertTrue(u'FE' in image2.imageTags) self.assertTrue(u'ファイアーエムブレム' in image2.imageTags) self.assertTrue(u'シーダ' in image2.imageTags) self.assertEqual(image2.imageMode, "big") self.assertEqual(image2.worksDate, '9/30/2013 01:43') self.assertEqual(image2.worksResolution, '1000x2317') self.assertEqual(image2.worksTools, 'CLIP STUDIO PAINT') # self.assertEqual(image2.jd_rtv, 88190) # self.assertEqual(image2.jd_rtc, 6711) # self.assertEqual(image2.jd_rtt, 66470) self.assertEqual(image2.artist.artistToken, 'hvcv')
def testPixivImageServerError(self): # print('\nTesting image page') p = open('./test/test-server-error.html', 'r') page = p.read() with self.assertRaises(PixivException) as ex: image = PixivImage(9138317, page) self.assertEqual(ex.exception.errorCode, PixivException.SERVER_ERROR)
def getImagePage(self, image_id, parent=None, from_bookmark=False, bookmark_count=-1, image_response_count=-1): image = None response = None PixivHelper.GetLogger().debug("Getting image page: %s", image_id) # https://www.pixiv.net/en/artworks/76656661 url = "https://www.pixiv.net{1}/artworks/{0}".format(image_id, self._locale) response = self.getPixivPage(url, returnParsed=False) self.handleDebugMediumPage(response, image_id) # Issue #355 new ui handler image = None try: if response.find("meta-preload-data") > 0: PixivHelper.print_and_log('debug', 'New UI Mode') # Issue #420 _tzInfo = None if self._config.useLocalTimezone: _tzInfo = PixivHelper.LocalUTCOffsetTimezone() image = PixivImage(image_id, response, parent, from_bookmark, bookmark_count, image_response_count, dateFormat=self._config.dateFormat, tzInfo=_tzInfo) if image.imageMode == "ugoira_view": ugoira_meta_url = "https://www.pixiv.net/ajax/illust/{0}/ugoira_meta".format(image_id) meta_response = self.open_with_retry(ugoira_meta_url).read() image.ParseUgoira(meta_response) if parent is None: if from_bookmark: image.originalArtist.reference_image_id = image_id self.getMemberInfoWhitecube(image.originalArtist.artistId, image.originalArtist) else: image.artist.reference_image_id = image_id self.getMemberInfoWhitecube(image.artist.artistId, image.artist) except: PixivHelper.GetLogger().error("Respose data: \r\n %s", response) raise return (image, response)
def testPixivImageNoImageEng(self): # print '\nTesting image page - no image' p = open('./test/test-image-noimage-eng.htm', 'r') page = BeautifulSoup(p.read()) with self.assertRaises(PixivException): PixivImage(123, page) page.decompose() del page
def testPixivImageDeleted(self): # print('\nTesting image page - deleted image') p = open('./test/test-image-deleted.htm', 'r') page = BeautifulSoup(p.read()) with self.assertRaises(PixivException): PixivImage(123, page) page.decompose() del page
def testCreateMangaFilename(self): p = open('./test/test-image-manga.htm', 'r') page = BeautifulSoup(p.read()) imageInfo = PixivImage(28820443, page) imageInfo.imageCount = 100 page.decompose() del page # print(imageInfo.PrintInfo()) nameFormat = '%member_token% (%member_id%)\%urlFilename% %page_number% %works_date_only% %works_res% %works_tools% %title%' expected = unicode( u'ffei (554800)\\28865189_p0 001 7-23-2012 複数枚投稿 2P Photoshop C82おまけ本 「沙耶は俺の嫁」サンプル.jpg' ) result = PixivHelper.makeFilename( nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img26/img/ffei/28865189_p0.jpg') print(result) self.assertEqual(result, expected) expected = unicode( u'ffei (554800)\\28865189_p14 015 7-23-2012 複数枚投稿 2P Photoshop C82おまけ本 「沙耶は俺の嫁」サンプル.jpg' ) result = PixivHelper.makeFilename( nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img26/img/ffei/28865189_p14.jpg') print(result) self.assertEqual(result, expected) expected = unicode( u'ffei (554800)\\28865189_p921 922 7-23-2012 複数枚投稿 2P Photoshop C82おまけ本 「沙耶は俺の嫁」サンプル.jpg' ) result = PixivHelper.makeFilename( nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img26/img/ffei/28865189_p921.jpg') print(result) self.assertEqual(result, expected)
def testPixivImageNoLogin(self): # print '\nTesting not logged in' p = open('./test/test-image-nologin.htm', 'r') page = BeautifulSoup(p.read()) try: image = PixivImage(9138317, page) self.assertRaises(PixivException) except PixivException as ex: self.assertEqual(ex.errorCode, PixivException.NOT_LOGGED_IN)
def testPixivImageServerError2(self): # print '\nTesting image page' p = open('./test/test-image-generic-error.html', 'r') page = BeautifulSoup(p.read()) with self.assertRaises(PixivException) as ex: image = PixivImage(37882549, page) self.assertEqual(ex.exception.errorCode, PixivException.SERVER_ERROR) page.decompose() del page
def testPixivImageModeManga(self): # print('\nTesting image page - manga') p = open('./test/test-image-manga.htm', 'r') page = p.read() image = PixivImage(28820443, page) self.assertNotEqual(image, None) self.assertEqual(image.imageId, 28820443) self.assertEqual(image.imageMode, 'manga')
def testPixivImageNoLogin(self): # print('\nTesting not logged in') p = open('./test/test-image-nologin.htm', 'r') page = p.read() try: image = PixivImage(67089412, page) self.assertRaises(PixivException) except PixivException as ex: self.assertEqual(ex.errorCode, PixivException.NOT_LOGGED_IN)
def testPixivImageRateCount(self): p = open('./test/test-image-rate_count.htm', 'r') page = p.read() image = PixivImage(28865189, page) self.assertNotEqual(image, None) self.assertEqual(image.imageId, 28865189) self.assertEqual(image.imageMode, 'manga') self.assertTrue(image.jd_rtv > 0) self.assertTrue(image.jd_rtc > 0)
def testEroPageEng(self): try: br = Browser() path = 'file:///' + os.path.abspath('./test/test-image-ero-e.html').replace(os.sep,'/') p = br.open(path, 'r') page = BeautifulSoup(p.read()) image = PixivImage(31115956,page) self.assertRaises(PixivException) except PixivException as ex: self.assertEqual(ex.errorCode, 2005)
def testPixivImageParseNoTags(self): p = open('./test/test-image-no_tags.htm', 'r') page = p.read() image = PixivImage(9175987, page) self.assertNotEqual(image, None) self.assertEqual(image.imageId, 9175987) self.assertEqual(image.worksDate, '03/05/10 18:04') self.assertEqual(image.worksResolution, '1155x768') # self.assertEqual(image.worksTools, u'SAI') self.assertEqual(image.imageTags, [])
def testPixivImageUnicode(self): # print('\nTesting image page - big') p = open('./test/test-image-unicode.htm', 'r') page = p.read() image = PixivImage(2493913, page) self.assertNotEqual(image, None) self.assertEqual(image.imageId, 2493913) self.assertEqual(image.imageMode, 'big') self.assertEqual(image.worksDate, '12/23/08 12:01') self.assertEqual(image.worksResolution, '852x1200')
def testMyPickPage(self): try: br = Browser() path = 'file:///' + os.path.abspath('./test/test-image-my_pick.html').replace(os.sep,'/') p = br.open(path, 'r') page = BeautifulSoup(p.read()) image = PixivImage(12467674,page) self.assertRaises(PixivException) except PixivException as ex: self.assertEqual(ex.errorCode, 2002)
def testCreateFilenameUnicode(self): p = open('./test/test-image-unicode.htm', 'r') page = BeautifulSoup(p.read()) imageInfo = PixivImage(2493913, page) page.decompose() del page nameFormat = '%member_token% (%member_id%)\%urlFilename% %works_date_only% %works_res% %works_tools% %title%' expected = unicode(u'balzehn (267014)\\2493913 12-23-2008 852x1200 Photoshop SAI つけペン アラクネのいる日常2.jpg') result = PixivHelper.makeFilename(nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img16/img/balzehn/2493913.jpg') ##print result self.assertEqual(result, expected)
def testCreateMangaFilename(self): p = open('./test/test-image-manga.htm', 'r') page = BeautifulSoup(p.read()) imageInfo = PixivImage(28820443, page) imageInfo.imageCount = 100 page.decompose() del page print imageInfo.PrintInfo() nameFormat = '%member_token% (%member_id%)\%urlFilename% %page_number% %works_date_only% %works_res% %works_tools% %title% - %tags%' expected = unicode(u'ffei (554800)\\28865189_p0 001 07-23-2012 Manga 2P Photoshop C82\u304a\u307e\u3051\u672c \u300c\u6c99\u8036\u306f\u4ffa\u306e\u5ac1\u300d\u30b5\u30f3\u30d7\u30eb - C82 R-18 \u304a\u3063\u3071\u3044 \u3076\u3063\u304b\u3051 \u5b66\u5712\u9ed9\u793a\u9332 \u6f2b\u753b \u773c\u93e1 \u9ad8\u57ce\u6c99\u8036.jpg') result = PixivHelper.makeFilename(nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img26/img/ffei/28865189_p0.jpg') self.assertEqual(result, expected) expected = unicode(u'ffei (554800)\\28865189_p14 015 07-23-2012 Manga 2P Photoshop C82\u304a\u307e\u3051\u672c \u300c\u6c99\u8036\u306f\u4ffa\u306e\u5ac1\u300d\u30b5\u30f3\u30d7\u30eb - C82 R-18 \u304a\u3063\u3071\u3044 \u3076\u3063\u304b\u3051 \u5b66\u5712\u9ed9\u793a\u9332 \u6f2b\u753b \u773c\u93e1 \u9ad8\u57ce\u6c99\u8036.jpg') result = PixivHelper.makeFilename(nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img26/img/ffei/28865189_p14.jpg') self.assertEqual(result, expected) expected = unicode(u'ffei (554800)\\28865189_p921 922 07-23-2012 Manga 2P Photoshop C82\u304a\u307e\u3051\u672c \u300c\u6c99\u8036\u306f\u4ffa\u306e\u5ac1\u300d\u30b5\u30f3\u30d7\u30eb - C82 R-18 \u304a\u3063\u3071\u3044 \u3076\u3063\u304b\u3051 \u5b66\u5712\u9ed9\u793a\u9332 \u6f2b\u753b \u773c\u93e1 \u9ad8\u57ce\u6c99\u8036.jpg') result = PixivHelper.makeFilename(nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img26/img/ffei/28865189_p921.jpg') self.assertEqual(result, expected)
def testPixivImageParseTags(self): p = open('./test/test-image-parse-tags.htm', 'r') page = p.read() image = PixivImage(11164869, page) self.assertNotEqual(image, None) self.assertEqual(image.imageId, 11164869) self.assertEqual(image.worksDate, '06/08/10 17:33') self.assertEqual(image.worksResolution, '1009x683') # self.assertEqual(image.worksTools, u'SAI') # print(image.imageTags) joinedResult = " ".join(image.imageTags) self.assertEqual(joinedResult.find("VOCALOID") > -1, True)
def testPixivImageNoAvatar(self): # print('\nTesting artist page without avatar image') p = open('./test/test-image-noavatar.htm', 'r') page = p.read() image = PixivImage(20496355, page) # self.assertNotEqual(image, None) self.assertEqual(image.artist.artistToken, 'iymt') self.assertEqual(image.imageId, 20496355) # 07/22/2011 03:09|512×600|RETAS STUDIO # print(image.worksDate, image.worksResolution, image.worksTools) self.assertEqual(image.worksDate, '07/21/11 18:09') self.assertEqual(image.worksResolution, '512x600')
def testPixivImageModeManga(self): # print '\nTesting image page - manga' p = open('./test/test-image-manga.htm', 'r') page = BeautifulSoup(p.read()) try: image = PixivImage(28820443, page) # image.PrintInfo() except PixivException as ex: print ex page.decompose() del page self.assertNotEqual(image, None) self.assertEqual(image.imageId, 28820443) self.assertEqual(image.imageMode, 'manga')
def testPixivImageParseNoTags(self): p = open('./test/test-image-no_tags.htm', 'r') page = BeautifulSoup(p.read()) try: image = PixivImage(9175987, page) except PixivException as ex: print ex page.decompose() del page self.assertNotEqual(image, None) self.assertEqual(image.imageId, 9175987) self.assertEqual(image.worksDate, '3/6/2010 03:04') self.assertEqual(image.worksResolution, '1155x768') self.assertEqual(image.worksTools, u'SAI') self.assertEqual(image.imageTags, [])
def testPixivImageNoAvatar(self): # print '\nTesting artist page without avatar image' p = open('./test/test-image-noavatar.htm', 'r') page = BeautifulSoup(p.read()) image = PixivImage(20496355, page) page.decompose() del page # self.assertNotEqual(image, None) self.assertEqual(image.artist.artistToken, 'iymt') self.assertEqual(image.imageId, 20496355) # 07/22/2011 03:09|512×600|RETAS STUDIO # print image.worksDate, image.worksResolution, image.worksTools self.assertEqual(image.worksDate, '7/22/2011 03:09') self.assertEqual(image.worksResolution, '512x600') self.assertEqual(image.worksTools, 'RETAS STUDIO')
def testCreateMangaFilename(self): p = open('./test/test-image-manga.htm', 'r') page = BeautifulSoup(p.read()) imageInfo = PixivImage(28820443, page) imageInfo.imageCount = 100 page.decompose() del page ##print imageInfo.PrintInfo() nameFormat = '%member_token% (%member_id%)\%urlFilename% %page_number% %works_date_only% %works_res% %works_tools% %title% - %tags%' expected = unicode(u'ffei (554800)\\28865189_p0 001 7-23-2012 Manga 2P Photoshop C82おまけ本 「沙耶は俺の嫁」サンプル - C82 R-18 おっぱい ぶっかけ 学園黙示録 漫画 眼鏡 高城沙耶.jpg') result = PixivHelper.makeFilename(nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img26/img/ffei/28865189_p0.jpg') ##print result self.assertEqual(result, expected) expected = unicode(u'ffei (554800)\\28865189_p14 015 7-23-2012 Manga 2P Photoshop C82おまけ本 「沙耶は俺の嫁」サンプル - C82 R-18 おっぱい ぶっかけ 学園黙示録 漫画 眼鏡 高城沙耶.jpg') result = PixivHelper.makeFilename(nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img26/img/ffei/28865189_p14.jpg') ##print result self.assertEqual(result, expected) expected = unicode(u'ffei (554800)\\28865189_p921 922 7-23-2012 Manga 2P Photoshop C82おまけ本 「沙耶は俺の嫁」サンプル - C82 R-18 おっぱい ぶっかけ 学園黙示録 漫画 眼鏡 高城沙耶.jpg') result = PixivHelper.makeFilename(nameFormat, imageInfo, artistInfo=None, tagsSeparator=' ', fileUrl='http://i2.pixiv.net/img26/img/ffei/28865189_p921.jpg') ##print result self.assertEqual(result, expected)
def testPixivImageParseInfoSelf(self): # assuming being accessed via manage page for your own artwork. p = open('./test/test-image-selfimage.htm', 'r') page = p.read() image2 = PixivImage(65079382, page) self.assertEqual(image2.imageId, 65079382) self.assertEqual(image2.imageTitle, u"Test") self.assertTrue(len(image2.imageCaption) > 0) # print(u"\r\nCaption = {0}".format(image2.imageCaption)) self.assertTrue(u'None' in image2.imageTags) self.assertEqual(image2.imageMode, "big") self.assertEqual(image2.worksDate, '09/22/17 02:29') self.assertEqual(image2.worksResolution, '946x305')
def testPixivImageParseTags(self): p = open('./test/test-image-parse-tags.htm', 'r') page = BeautifulSoup(p.read()) try: image = PixivImage(11164869, page) except PixivException as ex: print ex page.decompose() del page self.assertNotEqual(image, None) self.assertEqual(image.imageId, 11164869) self.assertEqual(image.worksDate, '6/9/2010 02:33') self.assertEqual(image.worksResolution, '1009x683') self.assertEqual(image.worksTools, u'SAI') # print image.imageTags joinedResult = " ".join(image.imageTags) self.assertEqual(joinedResult.find("VOCALOID") > -1, True)
def testPixivImageRateCount(self): p = open('./test/test-image-rate_count.htm', 'r') page = BeautifulSoup(p.read()) try: image = PixivImage(28865189, page) #image.PrintInfo() except PixivException as ex: print ex page.decompose() del page self.assertNotEqual(image, None) self.assertEqual(image.imageId, 28865189) self.assertEqual(image.imageMode, 'manga') self.assertTrue(image.jd_rtv > 0) self.assertTrue(image.jd_rtc > 0) self.assertTrue(image.jd_rtt > 0) self.assertEqual(image.worksTools, "Photoshop")
def testPixivSImageParseInfoSelf(self): # assuming being accessed via manage page for your own artwork. p = open('./test/test-image-selfimage.htm', 'r') page = BeautifulSoup(p.read()) image2 = PixivImage(65079382, page) page.decompose() del page self.assertEqual(image2.imageId, 65079382) self.assertEqual(image2.imageTitle, u"Test") self.assertTrue(len(image2.imageCaption) > 0) print u"\r\nCaption = {0}".format(image2.imageCaption) self.assertTrue(u'None' in image2.imageTags) self.assertEqual(image2.imageMode, "bigNew") self.assertEqual(image2.worksDate, '9/22/2017 11:29') self.assertEqual(image2.worksResolution, '946x305')
def testPixivImageUnicode(self): # print '\nTesting image page - big' p = open('./test/test-image-unicode.htm', 'r') page = BeautifulSoup(p.read()) try: image = PixivImage(2493913, page) # image.PrintInfo() except PixivException as ex: print ex page.decompose() del page self.assertNotEqual(image, None) self.assertEqual(image.imageId, 2493913) self.assertEqual(image.imageMode, 'bigNew') self.assertEqual(image.worksDate, '12/23/2008 21:01') self.assertEqual(image.worksResolution, '852x1200') # print image.worksTools self.assertEqual(image.worksTools, u'Photoshop SAI つけペン')