Skip to content

Commit

Permalink
Fix regex, add doc and pep
Browse files Browse the repository at this point in the history
  • Loading branch information
medariox authored and fernandog committed Jul 29, 2016
1 parent 2f9878d commit dafd827
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions sickbeard/imdbPopular.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
from sickrage.helper.encoding import ek


class imdbPopular(object):
class ImdbPopular(object):
"""This class contains everything for the IMDB popular page."""

def __init__(self):
"""Get a list of most popular TV series from imdb."""
# Use akas.imdb.com, just like the imdb lib.
Expand Down Expand Up @@ -47,7 +49,7 @@ def fetch_popular_shows(self):
image_div = row.find('div', class_='lister-item-image float-left')
if image_div:
image = image_div.find('img')
show['image_url_large'] = image['loadlate'].replace('67_CR0,0,67,98', '186_CR0,0,186,273')
show['image_url_large'] = self.change_size(image['loadlate'], 3)
show['image_path'] = ek(posixpath.join, 'images', 'imdb_popular', ek(os.path.basename,
show['image_url_large']))
self.cache_image(show['image_url_large'])
Expand Down Expand Up @@ -78,28 +80,32 @@ def fetch_popular_shows(self):

@staticmethod
def change_size(image_url, factor=3):
match = re.search("^(.*)V1._(.{2})(.*?)_(.{2})(.*?),(.*?),(.*?),(.*?)_.jpg$", image_url)
"""
Change the size of the image we get from IMDB.
:param: image_url: Image source URL
:param: factor: Multiplier for the image size
"""
match = re.search('(.+[X|Y])(\d+)(_CR\d+,\d+,)(\d+),(\d+)', image_url)

if match:
matches = match.groups()
ek(os.path.basename, image_url)
matches = list(matches)
matches[2] = int(matches[2]) * factor
matches[1] = int(matches[1]) * factor
matches[3] = int(matches[3]) * factor
matches[4] = int(matches[4]) * factor
matches[5] = int(matches[5]) * factor
matches[6] = int(matches[6]) * factor
matches[7] = int(matches[7]) * factor

return "%sV1._%s%s_%s%s,%s,%s,%s_.jpg" % (matches[0], matches[1], matches[2], matches[3], matches[4],
matches[5], matches[6], matches[7])
return '{0}{1}{2}{3},{4}_AL_.jpg'.format(matches[0], matches[1], matches[2],
matches[3], matches[4])
else:
return image_url

def cache_image(self, image_url):
"""
Store cache of image in cache dir.
:param image_url: Source URL
:param image_url: Image source URL
"""
path = ek(os.path.abspath, ek(os.path.join, sickbeard.CACHE_DIR, 'images', 'imdb_popular'))

Expand All @@ -111,4 +117,5 @@ def cache_image(self, image_url):
if not ek(os.path.isfile, full_path):
helpers.download_file(image_url, full_path, session=self.session)

imdb_popular = imdbPopular()

imdb_popular = ImdbPopular()

0 comments on commit dafd827

Please sign in to comment.