Skip to content

Commit

Permalink
Merge 93a6beb into 2bef241
Browse files Browse the repository at this point in the history
  • Loading branch information
omaralvarez committed Dec 18, 2016
2 parents 2bef241 + 93a6beb commit 1776023
Show file tree
Hide file tree
Showing 3 changed files with 244 additions and 20 deletions.
45 changes: 29 additions & 16 deletions trakt/interfaces/shows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,49 @@
class ShowsInterface(Interface):
path = 'shows'

def get(self, id, **kwargs):
def get(self, id, extended=None, **kwargs):
response = self.http.get(
str(id)
)
str(id), query={
'extended': extended
})

return SummaryMapper.show(
self.client,
self.get_data(response, **kwargs)
)

def trending(self, **kwargs):
def trending(self, extended=None, **kwargs):
response = self.http.get(
'trending'
)
'trending',
query={
'extended': extended
})

return SummaryMapper.shows(
self.client,
self.get_data(response, **kwargs)
)

def next_episode(self, id, **kwargs):
def next_episode(self, id, extended=None, **kwargs):
response = self.http.get(
str(id), 'next_episode'
)
str(id), [
'next_episode'
], query={
'extended': extended
})

return SummaryMapper.episode(
self.client,
self.get_data(response, **kwargs)
)

def last_episode(self, id, **kwargs):
def last_episode(self, id, extended=None, **kwargs):
response = self.http.get(
str(id), 'last_episode'
)
str(id), [
'last_episode'
], query={
'extended': extended
})

return SummaryMapper.episode(
self.client,
Expand All @@ -57,21 +66,25 @@ def seasons(self, id, extended=None, **kwargs):
self.get_data(response, **kwargs)
)

def season(self, id, season, **kwargs):
def season(self, id, season, extended=None, **kwargs):
response = self.http.get(str(id), [
'seasons', str(season)
])
], query={
'extended': extended
})

return SummaryMapper.episodes(
self.client,
self.get_data(response, **kwargs)
)

def episode(self, id, season, episode, **kwargs):
def episode(self, id, season, episode, extended=None, **kwargs):
response = self.http.get(str(id), [
'seasons', str(season),
'episodes', str(episode)
])
], query={
'extended': extended
})

return SummaryMapper.episode(
self.client,
Expand Down
50 changes: 48 additions & 2 deletions trakt/objects/episode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from trakt.core.helpers import to_iso8601, deprecated
from trakt.core.helpers import from_iso8601, to_iso8601, deprecated
from trakt.objects.core.helpers import update_attributes
from trakt.objects.video import Video

Expand Down Expand Up @@ -28,6 +28,34 @@ def __init__(self, client, keys=None, index=None):
Episode title
"""

self.overview = None
"""
:type: :class:`~python:str`
Episode overview
"""

self.first_aired = None
"""
:type: :class:`~python:datetime.datetime`
Air date
"""

self.updated_at = None
"""
:type: :class:`~python:datetime.datetime`
Updated date
"""

self.available_translations = None
"""
:type: :class:`~python:list`
Available translations
"""

def to_identifier(self):
"""Returns the episode identifier which is compatible with requests that require
episode definitions.
Expand Down Expand Up @@ -79,12 +107,30 @@ def to_dict(self):
result['rating'] = self.rating.value
result['rated_at'] = to_iso8601(self.rating.timestamp)

if self.first_aired:
result['first_aired'] = to_iso8601(self.first_aired)

if self.updated_at:
result['updated_at'] = to_iso8601(self.updated_at)

if self.overview:
result['overview'] = self.overview

if self.available_translations:
result['available_translations'] = self.available_translations

return result

def _update(self, info=None, **kwargs):
super(Episode, self)._update(info, **kwargs)

update_attributes(self, info, ['title'])
update_attributes(self, info, ['title', 'overview', 'available_translations'])

if 'first_aired' in info:
self.first_aired = from_iso8601(info.get('first_aired'))

if 'updated_at' in info:
self.updated_at = from_iso8601(info.get('updated_at'))

@classmethod
def _construct(cls, client, keys, info=None, index=None, **kwargs):
Expand Down
169 changes: 167 additions & 2 deletions trakt/objects/show.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from trakt.core.helpers import to_iso8601, deprecated
from trakt.core.helpers import from_iso8601, to_iso8601, deprecated
from trakt.objects.core.helpers import update_attributes
from trakt.objects.media import Media

Expand Down Expand Up @@ -40,6 +40,106 @@ def __init__(self, client, keys, index=None):
and :code:`Trakt['shows'].trending()` methods)
"""

self.overview = None
"""
:type: :class:`~python:str`
Episode overview
"""

self.first_aired = None
"""
:type: :class:`~python:datetime.datetime`
Air date
"""

self.airs = None
"""
:type: :class:`~python:dict`
Dictionary with day, time and timezone in which the show airs
"""

self.runtime = None
"""
:type: :class:`~python:int`
Duration of the show in minutes
"""

self.certification = None
"""
:type: :class:`~python:str`
Show certification (e.g TV-MA)
"""

self.network = None
"""
:type: :class:`~python:str`
Network in which the show is aired
"""

self.country = None
"""
:type: :class:`~python:str`
Country in which the show is aired
"""

self.updated_at = None
"""
:type: :class:`~python:datetime.datetime`
Updated date
"""

self.status = None
"""
:type: :class:`~python:str`
Value of :code:`returning series` (airing right now),
:code:`in production` (airing soon), :code:`planned` (in development),
:code:`canceled`, or :code:`ended`
"""

self.homepage = None
"""
:type: :class:`~python:str`
Show homepage url
"""

self.language = None
"""
:type: :class:`~python:str`
Show language
"""

self.available_translations = None
"""
:type: :class:`~python:list`
Available translations
"""

self.genres = None
"""
:type: :class:`~python:list`
Show genres
"""

self.aired_episodes = None
"""
:type: :class:`~python:int`
Aired episodes
"""

def episodes(self):
"""Returns a flat episode iterator
Expand Down Expand Up @@ -91,6 +191,48 @@ def to_dict(self):

result['in_watchlist'] = self.in_watchlist if self.in_watchlist is not None else 0

if self.first_aired:
result['first_aired'] = to_iso8601(self.first_aired)

if self.updated_at:
result['updated_at'] = to_iso8601(self.updated_at)

if self.overview:
result['overview'] = self.overview

if self.available_translations:
result['available_translations'] = self.available_translations

if self.airs:
result['airs'] = self.airs

if self.runtime:
result['runtime'] = self.runtime

if self.certification:
result['certification'] = self.certification

if self.network:
result['network'] = self.network

if self.country:
result['country'] = self.country

if self.homepage:
result['homepage'] = self.homepage

if self.status:
result['status'] = self.status

if self.language:
result['language'] = self.language

if self.genres:
result['genres'] = self.genres

if self.aired_episodes:
result['aired_episodes'] = self.aired_episodes

return result

def _update(self, info=None, **kwargs):
Expand All @@ -99,12 +241,35 @@ def _update(self, info=None, **kwargs):
update_attributes(self, info, [
'title',

'watchers' # trending
'watchers', # trending

'overview', # extended info
'airs',
'certification',
'network',
'country',
'homepage',
'status',
'language',
'available_translations',
'genres'
])

if info.get('year'):
self.year = int(info['year'])

if info.get('runtime'):
self.runtime = int(info['runtime'])

if info.get('aired_episodes'):
self.aired_episodes = int(info['aired_episodes'])

if 'first_aired' in info:
self.first_aired = from_iso8601(info.get('first_aired'))

if 'updated_at' in info:
self.updated_at = from_iso8601(info.get('updated_at'))

@classmethod
def _construct(cls, client, keys, info=None, index=None, **kwargs):
show = cls(client, keys, index=index)
Expand Down

0 comments on commit 1776023

Please sign in to comment.