Пример #1
0
def test_watch():
    show1 = get_tv_maze_show(name="show 1")
    episode1 = get_tv_maze_episode(id=1, name="episode1", number=1)
    episode2 = get_tv_maze_episode(id=2, name="episode2", number=2)
    with get_memory_db() as database:
        with transaction(database) as transacted_db:
            show_id = database.add_show(show1)
            transacted_db.add_episode(show_id, episode1)
            transacted_db.add_episode(show_id, episode2)
        with transaction(database) as transacted_db:
            transacted_db.update_watched(1, True)
        episode1db = database.get_episode(1)
        with transaction(database) as transacted_db:
            transacted_db.update_watched(2, True)
        episode2db = database.get_episode(2)
    assert episode1db['watched'] != episode2db['watched']
Пример #2
0
def test_add():
    show = get_tv_maze_show()
    with get_memory_db() as database:
        with transaction(database) as transacted_db:
            add_id = transacted_db.add_show(show)

    assert add_id == 1
Пример #3
0
def test_get_shows():
    show = get_tv_maze_show()
    with get_memory_db() as database:
        with transaction(database) as transacted_db:
            transacted_db.add_show(show)
        shows = database.get_shows()

    assert len(shows) == 1
Пример #4
0
def test_get_active_shows():
    show1 = get_tv_maze_show(name="show 1")
    show2 = get_tv_maze_show(id=2,
                             name="show 2",
                             status=ShowStatus.ENDED.value)
    with get_memory_db() as database:
        with transaction(database) as transacted_db:
            transacted_db.add_show(show1)
            transacted_db.add_show(show2)
        active = database.get_active_shows()

    assert len(active) == 1
    assert active[0]['name'] == "show 1"
Пример #5
0
def test_last_seen():
    show1 = get_tv_maze_show(name="show 1")
    episode1 = get_tv_maze_episode(id=1, name="episode1", number=1)
    episode2 = get_tv_maze_episode(id=2, name="episode2", number=2)
    episode3 = get_tv_maze_episode(id=3, name="episode3", number=3)
    with get_memory_db() as database:
        with transaction(database) as transacted_db:
            show_id = database.add_show(show1)
            transacted_db.add_episode(show_id, episode1)
            transacted_db.add_episode(show_id, episode2)
            transacted_db.add_episode(show_id, episode3)
        database.last_seen(show_id, 1, 2)
        episodes = database.get_episodes(show_id)

    assert len(episodes) == 3
    assert episodes[0]['watched'] != ''
    assert episodes[1]['watched'] != ''
    assert episodes[2]['watched'] == ''  # last episode is not watched
Пример #6
0
 def sync(self,
          on_show_sync: Union[Callable[[Show], None], None] = None,
          on_episode_insert: Union[Callable[[TVMazeEpisode], None],
                                   None] = None,
          on_episode_update: Union[Callable[[TVMazeEpisode], None],
                                   None] = None):
     """Updates episode information for followed shows from tvmaze"""
     with transaction(self.database) as transacted_db:
         shows = transacted_db.get_active_shows()
         for show in shows:
             if on_show_sync:
                 on_show_sync(show)
             tv_maze_show = self.api.show_get(show['id'])
             if tv_maze_show:
                 transacted_db.update_show(ShowId(show['id']), tv_maze_show)
                 tv_maze_episodes = _get_episodes(self.api, show['id'])
                 transacted_db.sync_episodes(show['id'],
                                             tv_maze_episodes,
                                             on_insert=on_episode_insert,
                                             on_update=on_episode_update)
Пример #7
0
 def show_follow(
     self,
     show_id: ShowId,
     on_episode_insert: Union[Callable[[TVMazeEpisode], None], None] = None,
     on_episode_update: Union[Callable[[TVMazeEpisode], None], None] = None,
     on_show_added: Union[Callable[[TVMazeShow], None], None] = None
 ) -> Optional[TVMazeShow]:
     """Follows a show (downloads show information and episodes)"""
     # add show to db
     show = self.api.show_get(show_id)
     if show:
         with transaction(self.database) as transacted_db:
             _show_id = transacted_db.add_show(show)
             # add episodes to db
             episodes = _get_episodes(self.api, _show_id)
             transacted_db.sync_episodes(_show_id,
                                         episodes,
                                         on_insert=on_episode_insert,
                                         on_update=on_episode_update)
             if on_show_added:
                 on_show_added(show)
     return show
Пример #8
0
 def episodes_update_all_not_watched(self, show_id: ShowId):
     """Marks all show episodes as not watched"""
     with transaction(self.database) as transacted_db:
         return transacted_db.update_watched_show(show_id, False)
Пример #9
0
 def episodes_watched_to_last_seen(self, show_id: ShowId, season: int,
                                   episode: int) -> int:
     """Marks all episodes of a show until season/episode as watched"""
     with transaction(self.database) as transacted_db:
         return transacted_db.last_seen(show_id, season, episode)
Пример #10
0
 def episodes_update_season_not_watched(self, show_id: ShowId,
                                        season: int) -> None:
     """Marks all episodes from a season as non watched"""
     with transaction(self.database) as transacted_db:
         return transacted_db.update_watched_show_season(
             show_id, season, False)
Пример #11
0
 def episodes_update_season_watched(self, show_id: ShowId,
                                    season: int) -> None:
     """Marks all episodes from a season as watched"""
     with transaction(self.database) as transacted_db:
         return transacted_db.update_watched_show_season(
             ShowId(show_id), int(season), True)
Пример #12
0
 def episode_update_not_watched(self, episode_id: EpisodeId) -> None:
     """Marks episode as not watched"""
     with transaction(self.database) as transacted_db:
         return transacted_db.update_watched(episode_id, False)
Пример #13
0
 def episodes_patch_watchtime(self, file_name: str) -> None:
     """Patches episodes watch time from external file"""
     with transaction(self.database) as transacted_db:
         return transacted_db.update_watch_times(file_name)