Example #1
0
    def _build(self, data):
        """Build the calendar"""
        self._calendar = []

        for item in data:
            show_data = item.pop('show')
            episode_data = {
                **item.pop('episode'), 'airs_at':
                airs_date(item.get('first_aired'))
            }

            show = TVShow(
                show_data.pop('title'),
                slug="sodiafagiaugaiugh",
                **{
                    **show_data,
                    #                    'seasons': []
                })
            episode = TVEpisode(show.title,
                                episode_data.pop('season'),
                                episode_data.pop('number'),
                                slug=show.slug,
                                **episode_data)
            for season in show.seasons:
                if season.season != episode.season:
                    continue
                season._episodes = [episode]
                show._seasons = [season]
                self._calendar.append(show)
                break
        self._calendar = sorted(self._calendar,
                                key=lambda x: x.seasons[0].episodes[0].airs_at)
Example #2
0
 def show_collection(self):
     """All :class:`TVShow`'s in this :class:`User`'s library collection.
     Collection items might include blu-rays, dvds, and digital downloads.
     Protected users won't return any data unless you are friends.
     """
     if self._show_collection is None:
         ext = 'users/{username}/collection/shows?extended=metadata'
         data = yield ext.format(username=self.username)
         self._show_collection = []
         for show in data:
             s = show.pop('show')
             extract_ids(s)
             sh = TVShow(**s)
             sh._seasons = [TVSeason(show=sh.title, **sea)
                            for sea in show.pop('seasons')]
             self._show_collection.append(sh)
     yield self._show_collection
 def show_collection(self):
     """All :class:`TVShow`'s in this :class:`User`'s library collection.
     Collection items might include blu-rays, dvds, and digital downloads.
     Protected users won't return any data unless you are friends.
     """
     if self._show_collection is None:
         ext = 'users/{username}/collection/shows?extended=metadata'
         data = yield ext.format(username=self.username)
         self._show_collection = []
         for show in data:
             s = show.pop('show')
             extract_ids(s)
             sh = TVShow(**s)
             sh._seasons = [TVSeason(show=sh.title, **sea)
                            for sea in show.pop('seasons')]
             self._show_collection.append(sh)
     yield self._show_collection
Example #4
0
    def get_items(self):
        """A list of the list items using class instances
        instance types: movie, show, season, episode, person

        """

        data = yield 'users/{user}/lists/{id}/items'.format(user=self.creator,
                                                            id=self.slug)

        for item in data:
            # match list item type
            if 'type' not in item:
                continue
            item_type = item['type']
            item_data = item.pop(item_type)
            extract_ids(item_data)
            if item_type == 'movie':
                movie = Movie(item_data.pop('title'), item_data.pop('year'),
                              item_data.pop('slug'), **item_data)
                self._items.append(movie)
            elif item_type == 'show':
                show = TVShow(item_data.pop('title'),
                              slug=item_data.pop('slug'),
                              **item_data)
                seasons = show.seasons
                show._seasons = []
                for season in seasons:
                    season._episodes = []
                    show._seasons.append(season)
                self._items.append(show)
            elif item_type == 'season':
                show_data = item.pop('show')
                extract_ids(show_data)
                show = TVShow(show_data.pop('title'),
                              slug=show_data.pop('slug'),
                              **show_data)
                _season = TVSeason(show=show.title,
                                   season=item_data.pop('number'),
                                   slug=show.slug,
                                   **item_data)
                for season in show.seasons:
                    if season.trakt != _season.trakt:
                        continue
                    season._episodes = []
                    show._seasons = [season]
                    self._items.append(show)
                    break
                # season._episodes = []
                # show._seasons = [season]
                # self._items.append(show)

                # extract_ids(show_data)
                # show=TVShow(show_data['title'], show_data['slug'])
                # season = TVSeason(
                #     show=show.title,
                #     season=item_data['number'],
                #     slug=show.slug,
                #     **item_data
                # )
                # self._items.append(self.__class__.ListTVSeason(show=show, season=season))
            elif item_type == 'episode':
                show_data = item.pop('show')
                extract_ids(show_data)
                show = TVShow(show_data.pop('title'),
                              slug=show_data.pop('slug'),
                              **show_data)
                episode = TVEpisode(show=show.title,
                                    season=item_data.pop('season'),
                                    slug=show.slug,
                                    **item_data)
                for season in show.seasons:
                    if season.season != episode.season:
                        continue
                    season._episodes = [episode]
                    show._seasons = [season]
                    self._items.append(show)
                    break

                # show=TVShow(show_data['title'], show_data['slug'])
                # show._seasons = None
                # for season in show.seasons:
                #     if season.season != item_data['number']:
                #         continue
                #     episode = TVEpisode(show.title, season.season, item_data['number'], show.slug)
                #     self._items.append(self.__class__.ListTVEpisode(show=show, season=season, episode=episode))
                #     break
            elif item_type == 'person':
                self._items.append(Person(item_data['name'],
                                          item_data['slug']))

        yield self._items