Skip to content

Conversation

@glensc
Copy link
Contributor

@glensc glensc commented Jan 12, 2022

This will make only one trakt.tv API request to create list of TVSeason with TVEpisode objects.

The properties are indexed in a dict by .number rather being a list. (moved to #185)

    show = TVShow('Game of Thrones')

    episodes = show.episodes
    assert len(episodes) == 9
    assert episodes[1].episodes[0].title == 'Winter Is Coming'

this will make only two requests:

2022-01-12 21:33:17,816 DEBUG[trakt.core]:RESPONSE [get] (https://api-v2launch.trakt.tv/shows/game-of-thrones?extended=full): request: GET https://api-v2launch.trakt.tv/shows/game-of-thrones?extended=full, response: 200 (1.21 KiB), created: 2022-01-12 19:03:22 EET, expires: N/A (fresh)
2022-01-12 21:33:17,827 DEBUG[trakt.core]:RESPONSE [get] (https://api-v2launch.trakt.tv/shows/game-of-thrones/seasons?extended=episodes): request: GET https://api-v2launch.trakt.tv/shows/game-of-thrones/seasons?extended=episodes, response: 200 (45.46 KiB), created: 2022-01-12 20:55:16 EET, expires: N/A (fresh)

This is a continued effort to replace internal implementation:

@glensc
Copy link
Contributor Author

glensc commented Jan 12, 2022

Perhaps instead of adding episodes property, replace the implementation with seasons property?

but then it would be a breaking change due list vs dict.

@glensc
Copy link
Contributor Author

glensc commented Jan 12, 2022

Note that the current data is all fetched and filled by TVShow only (no extra requests), not in TVSeason, TVEpisode individually, so the old code needs to remain for the TVSeason or TVEpisode direct creation to continue working.

@glensc

This comment has been minimized.

@glensc
Copy link
Contributor Author

glensc commented Jan 12, 2022

perhaps the list vs dict is not an issue since accessing season from list by index is unreliable anyway (season 0 aka extras may be present and may be missing). however the same does not apply for episodes, in list episode 1 is episodes[0] not episodes[1].

@glensc
Copy link
Contributor Author

glensc commented Jan 13, 2022

I've given this a thought, perhaps:

  1. change the types to be list
  2. replace the .episodes added here as .seasons
  3. in v3 change type to be dict

I've also started abstracting HTTP and API layer:

so, if someone wants to make raw queries without the abstraction of the object they can use just the API client class. reasons could be any of:

  • performance
  • memory
  • lack of higher level abstraction

@glensc
Copy link
Contributor Author

glensc commented Jan 15, 2022

Ok. I've removed changes making this incompatible for v3

@glensc glensc changed the title TVShow: Add .episodes property TVShow: Update seasons to fill episodes in single request Jan 15, 2022
@glensc
Copy link
Contributor Author

glensc commented Jan 15, 2022

Incompatible changes moved to separate PR for v4:

@glensc glensc marked this pull request as ready for review January 15, 2022 20:50
glensc added a commit to glensc/python-pytrakt that referenced this pull request Oct 23, 2022
@glensc
Copy link
Contributor Author

glensc commented Oct 23, 2022

Carried to my fork:

@glensc glensc mentioned this pull request Oct 23, 2022
@glensc glensc changed the title TVShow: Update seasons to fill episodes in single request [python-pytrakt] TVShow: Update seasons to fill episodes in single request Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant