Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for banner and background images to tvmaze #10234

Merged
merged 4 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

#### New Features
- Add support for banner and background images to indexer tvmaze ([10234](https://github.com/pymedusa/Medusa/pull/10234))
- Add option for using ffprobe to validate postprocessed media ([10132](https://github.com/pymedusa/Medusa/pull/10132))

#### Improvements
Expand Down
1 change: 1 addition & 0 deletions lib/pytvmaze/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
show_seasons = 'http://api.tvmaze.com/shows/{0}/seasons'
season_by_id = 'http://api.tvmaze.com/seasons/{0}'
episode_by_id = 'http://api.tvmaze.com/episodes/{0}'
show_images = 'http://api.tvmaze.com/shows/{0}/images'

# TVMaze Premium endpoints
followed_shows = 'http://api.tvmaze.com/v1/user/follows/shows{0}'
Expand Down
3 changes: 3 additions & 0 deletions lib/pytvmaze/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class SeasonNotFound(BaseError):
pass


class ImagesNotFound(BaseError):
pass

class IllegalAirDate(BaseError):
pass

Expand Down
23 changes: 23 additions & 0 deletions lib/pytvmaze/tvmaze.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,21 @@ def __repr__(self):
))


class Image(object):
def __init__(self, data):
self.id = data.get('id')
self.type = data.get('type')
self.main = data.get('main')
self.resolutions = data.get('resolutions')

def __repr__(self):
return '<Image(maze_id={id},type={type},main={main})>'.format(
id=self.id,
type=self.type,
main=self.main
)


class Updates(object):
def __init__(self, data):
self.updates = dict()
Expand Down Expand Up @@ -1199,6 +1214,14 @@ def show_seasons(self, maze_id):
else:
raise SeasonNotFound('Couldn\'t find Season\'s for TVMaze ID {0}'.format(maze_id))

def show_images(self, maze_id):
url = endpoints.show_images.format(maze_id)
q = self._endpoint_standard_get(url)
if q:
return [Image(image) for image in q]
else:
raise ImagesNotFound('Couldn\'t find Images\'s for TVMaze ID {0}'.format(maze_id))

def season_by_id(self, season_id):
url = endpoints.season_by_id.format(season_id)
q = self._endpoint_standard_get(url)
Expand Down
54 changes: 45 additions & 9 deletions medusa/indexers/tvmaze/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,56 @@ def _parse_images(self, tvmaze_id):
log.debug('Getting show banners for {0}', tvmaze_id)

try:
image_medium = self.shows[tvmaze_id]['image_medium']
images = self.tvmaze_api.show_images(tvmaze_id)
# image_medium = self.shows[tvmaze_id]['image_medium']
except Exception:
log.debug('Could not parse Poster for showid: {0}', tvmaze_id)
return False

# Set the poster (using the original uploaded poster for now, as the medium formated is 210x195
_images = {u'poster': {u'1014x1500': {u'1': {u'rating': 1,
u'language': u'en',
u'ratingcount': 1,
u'bannerpath': image_medium.split('/')[-1],
u'bannertype': u'poster',
u'bannertype2': u'210x195',
u'_bannerpath': image_medium,
u'id': u'1035106'}}}}
_images = {}
for image in images:
if image.type not in _images:
_images[image.type] = {}

if not image.resolutions:
continue

if image.type == 'poster' and not image.main:
continue

# For banner, poster and fanart use the origin size.
_images[image.type] = {
f"{image.resolutions['original']['width']}x{image.resolutions['original']['height']}": {
image.id: {
'rating': 1,
'language': u'en',
'ratingcount': 1,
'bannerpath': image.resolutions['original']['url'].split('/')[-1],
'bannertype': image.type,
'bannertype2': f"{image.resolutions['original']['width']}x{image.resolutions['original']['height']}",
'_bannerpath': image.resolutions['original']['url'],
'id': image.id
}
}
}

if image.type == 'poster':
# Save the main poster as a poster thumb.
_images['poster_thumb'] = {
f"{image.resolutions['medium']['width']}x{image.resolutions['medium']['height']}": {
image.id: {
'rating': 1,
'language': u'en',
'ratingcount': 1,
'bannerpath': image.resolutions['medium']['url'].split('/')[-1],
'bannertype': 'poster_thumb',
'bannertype2': f"{image.resolutions['medium']['width']}x{image.resolutions['medium']['height']}",
'_bannerpath': image.resolutions['medium']['url'],
'id': image.id
}
}
}

season_images = self._parse_season_images(tvmaze_id)
if season_images:
Expand Down