diff --git a/gui/slick/interfaces/default/home_popularShows.mako b/gui/slick/interfaces/default/home_popularShows.mako index 9519cf5fa7fcac89f10c9862157c1298f049fb27..6e9f94988a848225fddb784a522ca89b14c7948b 100644 --- a/gui/slick/interfaces/default/home_popularShows.mako +++ b/gui/slick/interfaces/default/home_popularShows.mako @@ -2,14 +2,20 @@ <%include file="/inc_top.mako"/> +<h2>Popular Shows</h2> +<br /> + % if not popular_shows: <h3>Fetching of IMDB Data failed. Are you online?</h3> + <strong>Exception:</strong> + <p>${imdb_exception}</p> + % else: % for cur_result in popular_shows: <div class="popularShow"> <div class="left"> - <img class="coverImage" src="${cur_result['image_url_large']}" /> + <img class="coverImage" src="${sbRoot}/cache/${cur_result['image_path']}" /> </div> <div class="right"> <h3>${cur_result['name']}</h3> @@ -20,7 +26,7 @@ <p>${cur_result['outline']}<span class="year"> - Released ${cur_result['year']}<span></p> <span class="imdb_url"><a href="${anon_url(cur_result['imdb_url'])}">View on IMDB</a></span> | - <span class="imdb_sickrage_search"><a href="/home/addShows/newShow/?search_string=${cur_result['name']}"> + <span class="imdb_sickrage_search"><a href="${sbRoot}/home/addShows/newShow/?search_string=${cur_result['name']}"> Add Show</a></span> </div> diff --git a/sickbeard/imdbPopular.py b/sickbeard/imdbPopular.py index 0b6396675c5f3f617662c8ecd685698e998fa9fe..44643242b246b932a0cab5f552c48fe7dc7269b9 100644 --- a/sickbeard/imdbPopular.py +++ b/sickbeard/imdbPopular.py @@ -1,17 +1,29 @@ +import re +import os import requests from bs4 import BeautifulSoup -import re from datetime import date -url = "http://www.imdb.com/search/title?at=0&sort=moviemeter&title_type=tv_series&year=%s,%s" % \ - (date.today().year - 1, date.today().year + 1) +import sickbeard +from sickbeard import helpers +from sickbeard import encodingKludge as ek + +class imdbPopular(): + def __init__(self): + + self.url = "http://www.imdb.com/search/title?at=0&sort=moviemeter&title_type=tv_series&year=%s,%s" % \ + (date.today().year - 1, date.today().year + 1) + + self.session = requests.Session() -def fetch_popular_shows(): - popular_shows = [] + def fetch_popular_shows(self): + popular_shows = [] - r = requests.get(url) - if r.status_code == 200: - soup = BeautifulSoup(r.text) + data = helpers.getURL(self.url, session=self.session) + if not data: + return None + + soup = BeautifulSoup(data, 'html.parser') results = soup.find("table", {"class": "results"}) rows = results.find_all("tr"); @@ -21,13 +33,14 @@ def fetch_popular_shows(): if image_td: image = image_td.find("img") - show['image_url'] = image['src'] - show['image_url_large'] = show['image_url'].replace( - "V1._SX54_CR0,0,54,74_.jpg","V1._SX108_CR0,0,108,148_.jpg") + show['image_url_large'] = self.change_size(image['src'],3) + show['image_path'] = os.path.join('images', 'imdb_popular', os.path.basename(show['image_url_large'])) + + self.cache_image(show['image_url_large']) td = row.find("td", {"class": "title"}) - if td: + if td: show['name'] = td.find("a").contents[0] show['imdb_url'] = "http://www.imdb.com" + td.find("a")["href"] show['year'] = td.find("span", {"class": "year_type"}).contents[0].split(" ")[0][1:] @@ -50,5 +63,34 @@ def fetch_popular_shows(): popular_shows.append(show) return popular_shows - else: - return None + + def change_size(self, image_url, factor=3): + match = re.search("^(.*)V1._(.{2})(.*?)_(.{2})(.*?),(.*?),(.*?),(.*?)_.jpg$", image_url) + + if match: + matches = match.groups() + os.path.basename(image_url) + matches = list(matches) + matches[2] = int(matches[2]) * 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]) + else: + return image_url + + def cache_image(self, image_url): + path = ek.ek(os.path.abspath, ek.ek(os.path.join, sickbeard.CACHE_DIR, 'images', 'imdb_popular')) + + if not os.path.exists(path): + os.makedirs(path) + + full_path = os.path.join(path, os.path.basename(image_url)) + + if not os.path.isfile(full_path): + helpers.download_file(image_url, full_path, session=self.session) + +imdb_popular = imdbPopular() diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index a48a0b812b4b2b82873f670ae18732cc9f905567..4e52d53c83121df7cf92fc7247429ac3a354b0a3 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -48,7 +48,7 @@ from sickbeard.scene_numbering import get_scene_numbering, set_scene_numbering, get_xem_numbering_for_show, get_scene_absolute_numbering_for_show, get_xem_absolute_numbering_for_show, \ get_scene_absolute_numbering -import imdbPopular +from imdbPopular import imdb_popular from dateutil import tz, parser as dateutil_parser from unrar2 import RarFile @@ -2573,13 +2573,14 @@ class HomeAddShows(Home): Fetches data from IMDB to show a list of popular shows. """ t = PageTemplate(rh=self, file="home_popularShows.mako") + e = None try: - popular_shows = imdbPopular.fetch_popular_shows() - except: + popular_shows = imdb_popular.fetch_popular_shows() + except Exception as e: popular_shows = None - return t.render(submenu = self.HomeMenu(), popular_shows=popular_shows) + return t.render(submenu = self.HomeMenu(), popular_shows=popular_shows, imdb_exception=e) def addShowToBlacklist(self, indexer_id):