Add AniDb Random and Hot to Add Show page.

This commit is contained in:
JackDandy 2015-11-12 00:18:19 +00:00
parent 56c6b996ee
commit e37c9ba6d7
5 changed files with 112 additions and 8 deletions

View file

@ -69,6 +69,7 @@
* Change Trakt view drop down "Show" to reveal Brand-new Shows, Season Premieres, Recommendations and Trending views
* Change increase number of displayed Trakt shows to 100
* Add genres and rating to all Trakt shows
* Add AniDb Random and Hot to Add Show page
[develop changelog]
Enable Alpha Ratio again now that the secure login page over https is fixed

View file

@ -43,6 +43,21 @@
</div>
</a>
#if $sickbeard.USE_ANIDB
<a class="btn btn-large" href="$sbRoot/home/addShows/randomhot_anidb/" style="float:right">
<div class="button"><div class="icon-addtrendingshow"></div></div>
<div class="buttontext">
<h3>Add from AniDB</h3>
<p>Browse what's hot and recommnended.</p>
</div>
</a>
#else
<div class="buttontext" style="padding:10px 5px 10px 30px">
<h3>Add Random/Hot AniDB</h3>
<p>To use, enable AniDB in Config/Anime.</p>
</div>
#end if
<div style="clear:both;font-size:2px">&nbsp;</div>
</div>

View file

@ -101,7 +101,7 @@
<label for="anime">
<span class="component-title">Show is anime</span>
<span class="component-desc">
<input type="checkbox" name="anime" id="anime" #if $sickbeard.ANIME_DEFAULT then "checked=\"checked\"" else ""# />
<input type="checkbox" name="anime" id="anime" #if $sickbeard.ANIME_DEFAULT or $kwargs.get('is_anime') then "checked=\"checked\"" else ""# />
<p>enable if this show is anime and episode releases are named ... <em class="grey-text">Show.265</em> instead of <em class="grey-text">Show.S02E03</em></p>
</span>
</label>

View file

@ -1162,19 +1162,19 @@ def getURL(url, post_data=None, params=None, headers=None, timeout=30, session=N
return
except requests.exceptions.HTTPError as e:
logger.log(u"HTTP error " + str(e.errno) + " while loading URL " + url, logger.WARNING)
logger.log(u'HTTP error %s while loading URL %s' % (e.errno, url), logger.WARNING)
return
except requests.exceptions.ConnectionError as e:
logger.log(u"Connection error " + str(e.message) + " while loading URL " + url, logger.WARNING)
logger.log(u'Connection error msg:%s while loading URL %s' % (str(e.message), url), logger.WARNING)
return
except requests.exceptions.ReadTimeout as e:
logger.log(u'Read timed out ' + str(e.message) + ' while loading URL ' + url, logger.WARNING)
logger.log(u'Read timed out msg:%s while loading URL %s' % (str(e.message), url), logger.WARNING)
return
except requests.exceptions.Timeout as e:
logger.log(u"Connection timed out " + str(e.message) + " while loading URL " + url, logger.WARNING)
except (requests.exceptions.Timeout, socket.timeout) as e:
logger.log(u'Connection timed out msg:%s while loading URL %s' % (str(e.message), url), logger.WARNING)
return
except Exception:
logger.log(u"Unknown exception while loading URL " + url + ": " + traceback.format_exc(), logger.WARNING)
logger.log(u'Exception caught while loading URL %s Detail... %s' % (url, traceback.format_exc()), logger.WARNING)
return
if json:

View file

@ -2234,7 +2234,7 @@ class NewHomeAddShows(Home):
return t.respond()
def newShow(self, show_to_add=None, other_shows=None, use_show_name=None):
def newShow(self, show_to_add=None, other_shows=None, use_show_name=None, **kwargs):
"""
Display the new show page which collects a tvdb id, folder, and extra options and
posts them to addNewShow
@ -2247,6 +2247,7 @@ class NewHomeAddShows(Home):
t.submenu = self.HomeMenu()
t.enable_anime_options = True
t.enable_default_wanted = True
t.kwargs = kwargs
indexer, show_dir, indexer_id, show_name = self.split_extra_show(show_to_add)
@ -2284,6 +2285,93 @@ class NewHomeAddShows(Home):
return t.respond()
def randomhot_anidb(self, *args, **kwargs):
try:
import xml.etree.cElementTree as etree
except ImportError:
import elementtree.ElementTree as etree
browse_type = 'AniDB'
filtered = []
xref_src = 'https://raw.githubusercontent.com/ScudLee/anime-lists/master/anime-list.xml'
xml_data = helpers.getURL(xref_src)
xref_root = xml_data and etree.fromstring(xml_data) or None
url = 'http://api.anidb.net:9001/httpapi?client=sickgear&clientver=1&protover=1&request=main'
response = helpers.getURL(url)
if response and xref_root:
oldest, newest = None, None
try:
anime_root = etree.fromstring(response)
hot_anime, random_rec = [anime_root.find(node) for node in ['hotanime', 'randomrecommendation']]
random_rec = [item.find('./anime') for item in random_rec]
oldest_dt, newest_dt = 9999999, 0
for list_type, items in [('hot', hot_anime.getchildren()), ('recommended', random_rec)]:
for anime in items:
ids = dict(anidb=config.to_int(anime.get('id'), None))
xref_node = xref_root.find('./anime[@anidbid="%s"]' % ids['anidb'])
if not xref_node:
continue
tvdbid = config.to_int(xref_node.get('tvdbid'), None)
if None is tvdbid:
continue
ids.update(dict(tvdb=tvdbid))
first_aired, title, image = [None is not y and y.text or y for y in [
anime.find(node) for node in ['startdate', 'title', 'picture']]]
dt = dateutil.parser.parse(first_aired)
dt_ordinal = dt.toordinal()
dt_string = sbdatetime.sbdatetime.sbfdate(dt)
if dt_ordinal < oldest_dt:
oldest_dt = dt_ordinal
oldest = dt_string
if dt_ordinal > newest_dt:
newest_dt = dt_ordinal
newest = dt_string
img_uri = 'http://img7.anidb.net/pics/anime/%s' % image
path = ek.ek(os.path.abspath, ek.ek(os.path.join, sickbeard.CACHE_DIR, 'images', 'anidb'))
helpers.make_dirs(path)
file_name = ek.ek(os.path.basename, img_uri)
cached_name = ek.ek(os.path.join, path, file_name)
if not ek.ek(os.path.isfile, cached_name):
helpers.download_file(img_uri, cached_name)
images = dict(poster=dict(thumb='cache/images/anidb/%s' % file_name))
votes = rating = 0
counts = anime.find('./ratings/permanent')
if isinstance(counts, object):
votes = counts.get('count')
rated = float(counts.text)
rating = 100 < rated and rated / 10 or 10 > rated and 10 * rated or rated
filtered.append(dict(
type=list_type,
ids=ids,
premiered=dt_ordinal,
premiered_str=dt_string,
title=title.strip(),
images=images,
url_src_db='http://anidb.net/perl-bin/animedb.pl?show=anime&aid=%s' % ids['anidb'],
url_tvdb='%s%s' % (sickbeard.indexerApi(INDEXER_TVDB).config['show_url'], ids['tvdb']),
votes=votes, rating=rating,
genres='', overview=''
))
except:
pass
kwargs.update(dict(oldest=oldest, newest=newest))
return self.browse_shows(browse_type, 'Random and Hot at AniDB', filtered, **kwargs)
def addAniDBShow(self, indexer_id, showName):
if helpers.findCertainShow(sickbeard.showList, config.to_int(indexer_id, '')):
return
return self.newShow('|'.join(['', '', '', indexer_id or showName]), use_show_name=True, is_anime=True)
def traktTrending(self, *args, **kwargs):
return self.browse_trakt('shows/trending?limit=%s&' % 100, 'Trending at Trakt', mode='trending')