Skip to content

Commit e00dddb

Browse files
author
thomas
committed
Fix imdb list plugin due to website changes #50
1 parent 8c406c5 commit e00dddb

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

plugins/imdb_list.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import bs4
22
import requests
3-
import csv
3+
import json
44
from utils.base_plugin import ListScraper
55

66
class IMDBList(ListScraper):
@@ -13,9 +13,26 @@ def get_list(list_id, config=None):
1313
list_name = soup.find('h1').text
1414
description = soup.find("div", {"class": "list-description"}).text
1515

16-
r = requests.get(f'https://www.imdb.com/list/{list_id}/export', headers={'Accept-Language': 'en-US', 'User-Agent': 'Mozilla/5.0'})
17-
reader = csv.DictReader(r.text.splitlines())
16+
ld_json = soup.find("script", {"type": "application/ld+json"}).text
17+
ld_json = json.loads(ld_json)
1818
movies = []
19-
for row in reader:
20-
movies.append({'title': row['Title'], 'release_year': row['Year'], "media_type": row['Title Type'], "imdb_id": row['Const']})
19+
for row in ld_json["itemListElement"]:
20+
url_parts = row["item"]["url"].split("/")
21+
url_parts = [p for p in url_parts if p!=""]
22+
23+
release_year = None
24+
if config.get("add_release_year", False):
25+
# Get release_date
26+
r = requests.get(row["item"]["url"], headers={'Accept-Language': 'en-US', 'User-Agent': 'Mozilla/5.0', 'Accept-Language': 'en-US'})
27+
soup = bs4.BeautifulSoup(r.text, 'html.parser')
28+
movie_json = soup.find("script", {"type": "application/ld+json"}).text
29+
release_year = json.loads(movie_json)["datePublished"].split("-")[0]
30+
31+
movies.append({
32+
"title": row["item"]["name"],
33+
"release_year": release_year,
34+
"media_type": row["item"]["@type"],
35+
"imdb_id": url_parts[-1]
36+
})
37+
2138
return {'name': list_name, 'items': movies, "description": description}

0 commit comments

Comments
 (0)