Fix getting XEM absolute numbers for show.

Fix IMDb info load for redirected ids.
Fix flags on displayShow (under Linux).
This commit is contained in:
Prinz23 2018-09-05 15:15:08 +01:00 committed by JackDandy
parent 0b2b3f35df
commit 41a0cea90a
4 changed files with 35 additions and 13 deletions

View file

@ -233,7 +233,7 @@
<span class="space-right">#echo ($startyear, 'Unknown')[None is $startyear]#</span>
#if $flags
#for $country in $show.imdb_info['country_codes'].split('|')
<img class="flag space-right" src="$sbRoot/images/flags/${$country}.png" width="16" height="11" />
<img class="flag space-right" src="$sbRoot/images/flags/${$country.lower()}.png" width="16" height="11" />
#end for
#end if
</span>

View file

@ -65,6 +65,7 @@
style="padding:0; text-align:center; max-width:60px">
</td>
#elif $scene_anime
## todo: $xem_absolute_numbering[$ep['absolute_number']] is tuple key: $xem_absolute_numbering[($ep['season'], $ep['episode'])]
#set $dfltAbsolute = 0 if $ep['absolute_number'] not in $xem_absolute_numbering else $xem_absolute_numbering[$ep['absolute_number']]
<td align="center">
<input type="text" placeholder="$dfltAbsolute" size="6" maxlength="8"

View file

@ -83,7 +83,7 @@ def find_scene_numbering(indexer_id, indexer, season, episode):
return int(rows[0]['scene_season']), int(rows[0]['scene_episode'])
def get_scene_absolute_numbering(indexer_id, indexer, absolute_number, fallback_to_xem=True):
def get_scene_absolute_numbering(indexer_id, indexer, absolute_number, season, episode, fallback_to_xem=True):
"""
Returns a tuple, (season, episode), with the scene numbering (if there is one),
otherwise returns the xem numbering (if fallback_to_xem is set), otherwise
@ -110,7 +110,7 @@ def get_scene_absolute_numbering(indexer_id, indexer, absolute_number, fallback_
return result
else:
if fallback_to_xem:
xem_result = find_xem_absolute_numbering(indexer_id, indexer, absolute_number)
xem_result = find_xem_absolute_numbering(indexer_id, indexer, absolute_number, season, episode)
if xem_result:
return xem_result
return absolute_number
@ -247,7 +247,7 @@ def find_xem_numbering(indexer_id, indexer, season, episode):
return int(rows[0]['scene_season']), int(rows[0]['scene_episode'])
def find_xem_absolute_numbering(indexer_id, indexer, absolute_number):
def find_xem_absolute_numbering(indexer_id, indexer, absolute_number, season, episode):
"""
Returns the scene numbering, as retrieved from xem.
Refreshes/Loads as needed.
@ -266,8 +266,8 @@ def find_xem_absolute_numbering(indexer_id, indexer, absolute_number):
my_db = db.DBConnection()
rows = my_db.select(
'SELECT scene_absolute_number FROM tv_episodes WHERE indexer = ? and showid = ? and absolute_number = ? and scene_absolute_number != 0',
[indexer, indexer_id, absolute_number])
'SELECT scene_absolute_number FROM tv_episodes WHERE indexer = ? and showid = ? and season = ? and episode = ? and scene_absolute_number != 0',
[indexer, indexer_id, season, episode])
if rows:
return int(rows[0]['scene_absolute_number'])
@ -437,14 +437,15 @@ def get_xem_absolute_numbering_for_show(indexer_id, indexer):
result = {}
my_db = db.DBConnection()
rows = my_db.select(
'SELECT absolute_number, scene_absolute_number FROM tv_episodes WHERE indexer = ? and showid = ? and scene_absolute_number != 0 ORDER BY absolute_number',
'SELECT season, episode, scene_absolute_number FROM tv_episodes WHERE indexer = ? and showid = ? and scene_absolute_number != 0 ORDER BY season, episode',
[indexer, indexer_id])
for row in rows:
absolute_number = int(row['absolute_number'])
season = int(row['season'])
episode = int(row['episode'])
scene_absolute_number = int(row['scene_absolute_number'])
result[absolute_number] = scene_absolute_number
result[(season, episode)] = scene_absolute_number
return result
@ -752,7 +753,7 @@ def set_scene_numbering_helper(indexerid, indexer, forSeason=None, forEpisode=No
if scene_numbering:
(result['sceneSeason'], result['sceneEpisode']) = scene_numbering
else:
scene_numbering = get_scene_absolute_numbering(indexerid, indexer, for_absolute)
scene_numbering = get_scene_absolute_numbering(indexerid, indexer, for_absolute, for_season, for_episode)
if scene_numbering:
result['sceneAbsolute'] = scene_numbering

View file

@ -25,6 +25,7 @@ import re
import glob
import stat
import traceback
import requests
import shutil
import sickbeard
@ -1077,6 +1078,17 @@ class TVShow(object):
logger.log('Error loading IMDb info: %s' % ex(e), logger.ERROR)
logger.log('%s' % traceback.format_exc(), logger.ERROR)
def check_imdb_redirect(self, imdb_id):
page_url = 'https://www.imdb.com/title/{0}/'.format(imdb_id)
try:
response = requests.head(page_url, allow_redirects=True)
if response.history and any(h for h in response.history if h.status_code == 301):
return re.search(r'(tt\d{7})', response.url, flags=re.I).group(1)
else:
return None
except (StandardError, Exception):
return None
def _get_imdb_info(self):
if not self.imdbid and self.ids.get(indexermapper.INDEXER_IMDB, {'id': 0}).get('id', 0) <= 0:
@ -1099,6 +1111,11 @@ class TVShow(object):
imdb_certificates = None
try:
imdb_id = str(self.imdbid or 'tt%07d' % self.ids[indexermapper.INDEXER_IMDB]['id'])
redirect_check = self.check_imdb_redirect(imdb_id)
if redirect_check:
self._imdbid = redirect_check
imdb_id = redirect_check
imdb_info['imdb_id'] = self.imdbid
i = imdbpie.Imdb(exclude_episodes=True)
if not re.search(r'tt\d{7}', imdb_id, flags=re.I):
logger.log('Not a valid imdbid: %s for show: %s' % (imdb_id, self.name), logger.WARNING)
@ -1914,7 +1931,8 @@ class TVEpisode(object):
self.scene_absolute_number = sickbeard.scene_numbering.get_scene_absolute_numbering(
self.show.indexerid,
self.show.indexer,
self.absolute_number
absolute_number=self.absolute_number,
season=self.season, episode=episode
)
if self.scene_season == 0 or self.scene_episode == 0:
@ -2008,7 +2026,8 @@ class TVEpisode(object):
self.scene_absolute_number = sickbeard.scene_numbering.get_scene_absolute_numbering(
self.show.indexerid,
self.show.indexer,
self.absolute_number
absolute_number=self.absolute_number,
season=self.season, episode=self.episode
)
self.scene_season, self.scene_episode = sickbeard.scene_numbering.get_scene_numbering(
@ -2175,7 +2194,8 @@ class TVEpisode(object):
self.scene_absolute_number = sickbeard.scene_numbering.get_scene_absolute_numbering(
self.show.indexerid,
self.show.indexer,
self.absolute_number
absolute_number=self.absolute_number,
season=self.season, episode=self.episode
)
self.scene_season, self.scene_episode = sickbeard.scene_numbering.get_scene_numbering(