november 21, 2023

Letterboxd Common Movies

letterboxd icon

I'm a big fan of using Letterboxd to track the movies I've watched and see what my friends have been watching. It's the best social media platform out there.
I wanted to find movie both my friends and I both had on our watchlists, so that we could narrow down the choices on movie night. I never got access to the elusive Letterboxd API, so I forked a CLI project that returned common movies from Letterboxd users watchlists and I updated it to be object-oriented. The main body of work request the watchlist of the user and looked for specific html tags:

def getUserMovies(self, username, page_num):
    print(f"Going through {username}'s watchlist...")
    lst = []
    for page in range(1, page_num + 1):
      watchlist = http.request('GET', f"https://letterboxd.com/{username}/watchlist/page/{page}/")
      watchlist_html = watchlist.data.decode("utf-8")
      while "\n" in watchlist_html:
        watchlist_html = watchlist_html.split("\n")
      for line in watchlist_html:
        if "film-poster" in line:
          film_start = line.find("alt=") + len("alt=")
          film_end = line.find("/>", film_start)
          try:
            lst.append(line[film_start:film_end])
          except:
            break
    return lst

I extended the project to give the user a random movie from the two watchlists, which was a fun exercise. This small project was written in Python and was a great way to refresh my skills in the language since studying it at university.

GitHub Link