Skip to content

Commit

Permalink
Fixes issue #1
Browse files Browse the repository at this point in the history
Fixes issue #1 by
- Adding a user agent header in the request
- Fixed the parsing of IMDb for the IDs as it has changed. Should be more reliable now
- Bump to version 1.1
  • Loading branch information
primetime43 committed Jun 30, 2024
1 parent 9f32201 commit 52a8a65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
34 changes: 18 additions & 16 deletions PlexPlaylistMakerController.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ def fetch_item_details(self, queue, ia, imdb_id, retry_count=3, delay=1):
print(f"Failed to fetch details for {imdb_id} after {retry_count} attempts.")

def fetch_imdb_list_data(self, imdb_list_url):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
}

try:
response = requests.get(imdb_list_url, timeout=10)
response.raise_for_status()
response = requests.get(imdb_list_url, headers=headers, timeout=10)
response.raise_for_status()
except requests.exceptions.HTTPError:
return [], "HTTP error occurred. Please check the URL."
except requests.exceptions.ConnectionError:
Expand All @@ -105,20 +109,18 @@ def fetch_imdb_list_data(self, imdb_list_url):
return [], "An error occurred. Please try again."

soup = BeautifulSoup(response.text, 'html.parser')
json_str_match = re.search(r'<script type="application/ld\+json">(.+?)</script>', soup.prettify(), re.DOTALL)
if json_str_match:
json_str = json_str_match.group(1)
try:
data = json.loads(json_str)
except json.JSONDecodeError:
return [], "Failed to decode JSON from the webpage."

itemListElements = data.get("about", {}).get("itemListElement", [])
imdb_ids = [item.get("url", "").split("/title/")[1].rstrip("/") for item in itemListElements if "/title/tt" in item.get("url", "")]
if imdb_ids:
return imdb_ids, "Data fetched successfully."
else:
return [], "No IMDb IDs found in the provided URL."

imdb_ids = []
for a_tag in soup.find_all('a', href=True):
href = a_tag['href']
imdb_id_match = re.search(r'/title/(tt\d+)/', href)
if imdb_id_match:
imdb_ids.append(imdb_id_match.group(1))

if imdb_ids:
return imdb_ids, "Data fetched successfully."
else:
return [], "No IMDb IDs found in the provided URL."

return [], "Failed to fetch data. Please check the URL format and try again."

Expand Down
2 changes: 1 addition & 1 deletion PlexPlaylistMakerGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from PIL import Image
from PlexPlaylistMakerController import PlexIMDbApp, PlexLetterboxdApp, check_updates

VERSION = 1.0
VERSION = 1.1

class PlexPlaylistMakerGUI(ctk.CTk):
def __init__(self):
Expand Down

0 comments on commit 52a8a65

Please sign in to comment.