Skip to content

Commit

Permalink
Make sure imdb parser doesn't get false positives on rating ineligibi…
Browse files Browse the repository at this point in the history
…lity check. fix Flexget#2223
  • Loading branch information
gazpachoking committed Oct 6, 2013
1 parent a3079db commit 7a40bdb
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions flexget/utils/imdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,29 +282,33 @@ def parse(self, imdb_id):
# if title is already in original language, it doesn't have the tag
log.debug('Unable to get original title for %s - it probably does not exists' % url)

# detect if movie is eligible for ratings
rating_ineligible = soup.find('div', attrs={'class': 'rating-ineligible'})
if rating_ineligible:
log.debug('movie is not eligible for ratings')
else:
# get votes
tag_votes = soup.find(itemprop='ratingCount')
if tag_votes:
self.votes = str_to_int(tag_votes.string) or 0
log.debug('Detected votes: %s' % self.votes)
else:
log.warning('Unable to get votes for %s - plugin needs update?' % url)

# get score - find the ratingValue item that contains a numerical value
span_score = soup.find(itemprop='ratingValue', text=re.compile('[\d\.]+'))
if span_score:
try:
self.score = float(span_score.string)
except (ValueError, TypeError):
log.debug('tag_score %r is not valid float' % span_score.string)
log.debug('Detected score: %s' % self.score)
star_box = soup.find('div', attrs={'class': 'star-box giga-star'})
if star_box:
# detect if movie is eligible for ratings
rating_ineligible = star_box.find('div', attrs={'class': 'rating-ineligible'})
if rating_ineligible:
log.debug('movie is not eligible for ratings')
else:
log.warning('Unable to get score for %s - plugin needs update?' % url)
# get votes
tag_votes = star_box.find(itemprop='ratingCount')
if tag_votes:
self.votes = str_to_int(tag_votes.string) or 0
log.debug('Detected votes: %s' % self.votes)
else:
log.warning('Unable to get votes for %s - plugin needs update?' % url)

# get score - find the ratingValue item that contains a numerical value
span_score = star_box.find(itemprop='ratingValue', text=re.compile('[\d\.]+'))
if span_score:
try:
self.score = float(span_score.string)
except (ValueError, TypeError):
log.debug('tag_score %r is not valid float' % span_score.string)
log.debug('Detected score: %s' % self.score)
else:
log.warning('Unable to get score for %s - plugin needs update?' % url)
else:
log.warning('Unable to find score/vote section for %s - plugin needs update?' % url)

# get genres
genres = soup.find('div', itemprop='genre')
Expand Down

0 comments on commit 7a40bdb

Please sign in to comment.