Python Library: tmdbapis | fetching movie data

Python wrapper for the TMDB API - themoviedb.org - with support for API v4

20 Jul 2022 starting note *note date indicates latest update.

Library resources
PyPI https://pypi.org/project/tmdbapis/
Github https://github.com/meisnate12/tmdbapis
Documentation https://tmdbapis.metamanager.wiki/en/latest/index.html
Has been updated 4 days ago, so valid library.

Continuing from Nic Note: Library: tmdbv3api | fetching movie data as I need API v4 support to get large lists.

Install with:

pip3 install tmdbapis

Successful 2-step authentication with:

from tmdbapis import TMDbAPIs

tmdb_api_key = os.getenv("TMDB_API_KEY")
print(f"{tmdb_api_key=}") # print to check that proper key is passed in the payload later
tmdb_v4_token = os.getenv("TMDB_V4_TOKEN")
print(f"{tmdb_v4_token=}\n")

tmdb = TMDbAPIs(tmdb_api_key, v4_access_token=tmdb_v4_token)

print(tmdb.v4_authenticate())
input("Navigate to the URL and then hit enter when Authenticated")
tmdb.v4_approved()
with open("tmdb_access_token.txt", "w") as text_file:
    print(tmdb.v4_access_token, file=text_file)

To load the authenticated token saved in a .txt file (note to self: rework logic to save in .env?):

CAREFUL: remove \n at end of line in tmdb_access_token.txt if error. Not sure how to avoid this at write stage.

from tmdbapis import TMDbAPIs

tmdb_api_key = os.getenv("TMDB_API_KEY")

v4_access_token = None
with open("tmdb_access_token.txt") as text_file:
    v4_access_token = text_file.readline()

tmdb = TMDbAPIs(tmdb_api_key, v4_access_token=v4_access_token)

Fetching my lists

Works with following code, but still only returns 20:

# my_top_1000_list_id = int(my_list_id)
my_1000 = tmdb.list(my_top_1000_list_id)
for m in my_1000:
    print(m.id)
    print(m.title)
    print(f"https://image.tmdb.org/t/p/original/{m.poster_path}")
    print() 

Pagination:

my_1000 = tmdb.list(my_top_1000_list_id)
print(f"{my_1000.page=}")
print(f"{my_1000.total_pages=}")
print(f"{my_1000.total_results=}\n")

Can't figure out how to get data from page 2 onwards though.

Call me weak, but after losing 2 hours of my life trying to make pagination work with both tmdbapis and tmdbv3api, I reverted back to just using Python's requests and it worked in 5mns!

See Nic Note: Fetching data from TMDB

links

social