def parseImageDataFromPhotoTableTag(page, thumbnailList, isPoster, maxImagesToParse): anchorElems = page.xpath('//table[@class="fotos" or @class="fotos fotos1" or @class="fotos fotos2"]/tr/td/a') currItemIndex = len(thumbnailList) for anchorElem in anchorElems: thumb = None try: thumb = parseImageDataFromAnchorElement(anchorElem, currItemIndex) currItemIndex += 1 except: common.logException('unable to parse image URLs') if thumb is None: Log.Debug('no URLs - skipping an image') continue else: common.scoreThumbnailResult(thumb, isPoster) if PREFS.imageChoice == common.IMAGE_CHOICE_BEST and \ thumb.score < common.IMAGE_SCORE_BEST_THRESHOLD: continue thumbnailList.append(thumb) Log.Debug('GOT URLs for an image: index=%d, thumb="%s", full="%s" (%sx%s)' % (thumb.index, str(thumb.thumbImgUrl), str(thumb.fullImgUrl), str(thumb.fullImgWidth), str(thumb.fullImgHeight))) maxImagesToParse = maxImagesToParse - 1 if not maxImagesToParse: break return maxImagesToParse
def parseAndScoreImageData(self, imageJson, itemIndex, isPortrait, preferredLang): try: url = S.TMDB_IMAGE_ORIGINAL_BASE_URL + imageJson['file_path'] thumbUrl = S.TMDB_IMAGE_THUMB_BASE_URL + imageJson['file_path'] lang = imageJson['iso_639_1'] imageData = common.Thumbnail( thumbUrl, url, imageJson['width'], imageJson['height'], itemIndex, 0, lang) common.scoreThumbnailResult(imageData, isPortrait, preferredLang) return imageData except: self.log.Warn('failed to parse image data') return None
def fetchAndParseStillsData(self, kinoPoiskId, maxStills): """ Fetches pages that contain fun art ("stills"), parses, scores, and orders fun art data. """ stillsData = self.fetchAndParsePostersPage(kinoPoiskId, maxStills, "stills") stills = stillsData["stills"] # Sort results according to their score and chop out extraneous images. Сортируем результаты. for still in stills: common.scoreThumbnailResult(still, False) stills = sorted(stills, key=lambda t: t.score, reverse=True)[0:maxStills] self.maybeLogImageResult(stills) return {"stills": stills}
def fetchAndParseStillsData(self, kinoPoiskId, maxStills): """ Fetches pages that contain fun art ("stills"), parses, scores, and orders fun art data. """ stillsData = self.fetchAndParsePostersPage(kinoPoiskId, maxStills, 'stills') stills = stillsData['stills'] # Sort results according to their score and chop out extraneous images. Сортируем результаты. for still in stills: common.scoreThumbnailResult(still, False) stills = sorted(stills, key=lambda t: t.score, reverse=True)[0:maxStills] self.maybeLogImageResult(stills) return {'stills': stills}
def parseAndScoreImageData(self, imageJson, itemIndex, isPortrait, preferredLang): try: url = S.TMDB_IMAGE_ORIGINAL_BASE_URL + imageJson['file_path'] thumbUrl = S.TMDB_IMAGE_THUMB_BASE_URL + imageJson['file_path'] lang = imageJson['iso_639_1'] imageData = common.Thumbnail(thumbUrl, url, imageJson['width'], imageJson['height'], itemIndex, 0, lang) common.scoreThumbnailResult(imageData, isPortrait, preferredLang) return imageData except: self.log.Warn('failed to parse image data') return None
def fetchAndParseStillsData(self, kinoPoiskId, maxStills, lang): """ Fetches pages that contain fun art ("backgrounds"), parses and scores them. """ backgrounds = self.fetchAndParseImagesPage( S.KINOPOISK_STILLS_URL % kinoPoiskId, maxStills) if len(backgrounds) == 0: backgrounds = self.fetchAndParseImagesPage( S.KINOPOISK_SCREENSHOTS_URL % kinoPoiskId, maxStills) if len(backgrounds) == 0: backgrounds = self.fetchAndParseImagesPage( S.KINOPOISK_WALL_URL % kinoPoiskId, maxStills) for background in backgrounds: common.scoreThumbnailResult(background, False, lang) return backgrounds
def fetchAndParsePostersData(self, kinoPoiskId, maxPosters, lang): """ Fetches various poster pages, parses, scores, and orders posters data. This will include parsing poster from the main title page and possibly from the posters (first) page. """ # Получение ярлыка (большого если есть или маленького с главной страницы). mainPoster = self.fetchAndParsePosterThumbnailData(kinoPoiskId) if maxPosters > 1: url = S.KINOPOISK_COVERS_URL % kinoPoiskId posters = self.fetchAndParseImagesPage(url, maxPosters) else: posters = [] if mainPoster: posters.append(mainPoster) for poster in posters: common.scoreThumbnailResult(poster, True, lang) return posters
def fetchAndParsePostersData(self, kinoPoiskId, maxPosters): """ Fetches various poster pages, parses, scores, and orders posters data. This will include parsing poster from the main title page and from the posters (first) page. This is the master poster parsing method. """ # Получение ярлыка (большого если есть или маленького с главной страницы). thumb = self.fetchAndParsePosterThumbnailData(kinoPoiskId) if maxPosters > 1: postersData = self.fetchAndParsePostersPage(kinoPoiskId, maxPosters, "posters") posters = postersData["posters"] posters.append(thumb) # Sort results according to their score and chop out extraneous images. Сортируем результаты. for poster in posters: common.scoreThumbnailResult(poster, True) posters = sorted(posters, key=lambda t: t.score, reverse=True)[0:maxPosters] self.maybeLogImageResult(posters) else: posters = [thumb] return {"posters": posters}
def fetchAndParsePostersData(self, kinoPoiskId, maxPosters): """ Fetches various poster pages, parses, scores, and orders posters data. This will include parsing poster from the main title page and from the posters (first) page. This is the master poster parsing method. """ # Получение ярлыка (большого если есть или маленького с главной страницы). thumb = self.fetchAndParsePosterThumbnailData(kinoPoiskId) if maxPosters > 1: postersData = self.fetchAndParsePostersPage( kinoPoiskId, maxPosters, 'posters') posters = postersData['posters'] posters.append(thumb) # Sort results according to their score and chop out extraneous images. Сортируем результаты. for poster in posters: common.scoreThumbnailResult(poster, True) posters = sorted(posters, key=lambda t: t.score, reverse=True)[0:maxPosters] self.maybeLogImageResult(posters) else: posters = [thumb] return {'posters': posters}