Skip to content

Commit f6cc84a

Browse files
authored
Merge pull request #53 from daniel-sanche/letterboxed_likes
Support Letterboxed likes list
2 parents cfe21db + 67df9ce commit f6cc84a

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

plugins/letterboxd.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,26 @@ def get_list(list_id, config=None):
1313
list_name = None
1414
description = None
1515
movies = []
16+
config = config or {}
1617

1718
while True:
1819
print("Page number: ", page_number)
1920
watchlist = list_id.endswith("/watchlist")
21+
likeslist = list_id.endswith("/likes/films")
2022

2123
if watchlist:
22-
r = requests.get(f"https://letterboxd.com/{list_id}/by/release-earliest/page/{page_number}/", headers={'User-Agent': 'Mozilla/5.0'})
23-
2424
list_name = list_id.split("/")[0] + " Watchlist"
2525
description = "Watchlist for " + list_id.split("/")[0]
26-
else:
27-
r = requests.get(f"https://letterboxd.com/{list_id}/detail/by/release-earliest/page/{page_number}/", headers={'User-Agent': 'Mozilla/5.0'})
26+
elif likeslist:
27+
list_name = list_id.split("/")[0] + " Likes"
28+
description = "Likes list for " + list_id.split("/")[0]
29+
30+
url_format = "https://letterboxd.com/{list_id}{maybe_detail}/by/release-earliest/page/{page_number}/"
31+
maybe_detail = "" if watchlist or likeslist else "/detail"
32+
r = requests.get(
33+
url_format.format(list_id=list_id, maybe_detail=maybe_detail, page_number=page_number),
34+
headers={'User-Agent': 'Mozilla/5.0'},
35+
)
2836

2937
soup = bs4.BeautifulSoup(r.text, 'html.parser')
3038

@@ -38,13 +46,13 @@ def get_list(list_id, config=None):
3846
else:
3947
description = ""
4048

41-
if watchlist:
49+
if watchlist or likeslist:
4250
page = soup.find_all('li', {'class': 'poster-container'})
4351
else:
4452
page = soup.find_all('div', {'class': 'film-detail-content'})
4553

4654
for movie_soup in page:
47-
if watchlist:
55+
if watchlist or likeslist:
4856
movie = {"title": movie_soup.find('img').attrs['alt'], "media_type": "movie"}
4957
link = movie_soup.find('div', {'class': 'film-poster'})['data-target-link']
5058
else:

0 commit comments

Comments
 (0)